[Python-checkins] r42412 - python/trunk/Objects/abstract.c python/trunk/Objects/enumobject.c python/trunk/Objects/iterobject.c python/trunk/Objects/listobject.c python/trunk/Objects/methodobject.c python/trunk/Objects/stringobject.c python/trunk/Objects/structseq.c python/trunk/Objects/tupleobject.c python/trunk/Objects/typeobject.c python/trunk/Objects/unicodeobject.c

martin.v.loewis python-checkins at python.org
Thu Feb 16 15:32:29 CET 2006


Author: martin.v.loewis
Date: Thu Feb 16 15:32:27 2006
New Revision: 42412

Modified:
   python/trunk/Objects/abstract.c
   python/trunk/Objects/enumobject.c
   python/trunk/Objects/iterobject.c
   python/trunk/Objects/listobject.c
   python/trunk/Objects/methodobject.c
   python/trunk/Objects/stringobject.c
   python/trunk/Objects/structseq.c
   python/trunk/Objects/tupleobject.c
   python/trunk/Objects/typeobject.c
   python/trunk/Objects/unicodeobject.c
Log:
Use Py_ssize_t for counts and sizes.
Convert Py_ssize_t using PyInt_FromSsize_t

Modified: python/trunk/Objects/abstract.c
==============================================================================
--- python/trunk/Objects/abstract.c	(original)
+++ python/trunk/Objects/abstract.c	Thu Feb 16 15:32:27 2006
@@ -1170,7 +1170,7 @@
 	   to nb_multiply if o appears to be a sequence. */
 	if (PySequence_Check(o)) {
 		PyObject *n, *result;
-		n = PyInt_FromLong(count);
+		n = PyInt_FromSsize_t(count);
 		if (n == NULL)
 			return NULL;
 		result = binary_op1(o, n, NB_SLOT(nb_multiply));
@@ -1222,7 +1222,7 @@
 
 	if (PySequence_Check(o)) {
 		PyObject *n, *result;
-		n = PyInt_FromLong(count);
+		n = PyInt_FromSsize_t(count);
 		if (n == NULL)
 			return NULL;
 		result = binary_iop1(o, n, NB_SLOT(nb_inplace_multiply),

Modified: python/trunk/Objects/enumobject.c
==============================================================================
--- python/trunk/Objects/enumobject.c	(original)
+++ python/trunk/Objects/enumobject.c	Thu Feb 16 15:32:27 2006
@@ -159,14 +159,14 @@
 
 typedef struct {
 	PyObject_HEAD
-	long      index;
+	Py_ssize_t      index;
 	PyObject* seq;
 } reversedobject;
 
 static PyObject *
 reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-	long n;
+	Py_ssize_t n;
 	PyObject *seq;
 	reversedobject *ro;
 
@@ -249,7 +249,7 @@
 	if (seqsize == -1)
 		return NULL;
 	position = ro->index + 1;
-	return PyInt_FromLong((seqsize < position)  ?  0  :  position);
+	return PyInt_FromSsize_t((seqsize < position)  ?  0  :  position);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");

Modified: python/trunk/Objects/iterobject.c
==============================================================================
--- python/trunk/Objects/iterobject.c	(original)
+++ python/trunk/Objects/iterobject.c	Thu Feb 16 15:32:27 2006
@@ -82,7 +82,7 @@
 			return NULL;
 		len = seqsize - it->it_index;
 		if (len >= 0)
-			return PyInt_FromLong(len);
+			return PyInt_FromSsize_t(len);
 	}
 	return PyInt_FromLong(0);
 }

Modified: python/trunk/Objects/listobject.c
==============================================================================
--- python/trunk/Objects/listobject.c	(original)
+++ python/trunk/Objects/listobject.c	Thu Feb 16 15:32:27 2006
@@ -2504,13 +2504,13 @@
 list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
 {
 	if (PyInt_Check(item)) {
-		long i = PyInt_AS_LONG(item);
+		Py_ssize_t i = PyInt_AS_LONG(item);
 		if (i < 0)
 			i += PyList_GET_SIZE(self);
 		return list_ass_item(self, i, value);
 	}
 	else if (PyLong_Check(item)) {
-		long i = PyLong_AsLong(item);
+		Py_ssize_t i = PyInt_AsSsize_t(item);
 		if (i == -1 && PyErr_Occurred())
 			return -1;
 		if (i < 0)
@@ -2818,7 +2818,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	long it_index;
+	Py_ssize_t it_index;
 	PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
 } listreviterobject;
 
@@ -2860,7 +2860,7 @@
 listreviter_next(listreviterobject *it)
 {
 	PyObject *item;
-	long index = it->it_index;
+	Py_ssize_t index = it->it_index;
 	PyListObject *seq = it->it_seq;
 
 	if (index>=0 && index < PyList_GET_SIZE(seq)) {

Modified: python/trunk/Objects/methodobject.c
==============================================================================
--- python/trunk/Objects/methodobject.c	(original)
+++ python/trunk/Objects/methodobject.c	Thu Feb 16 15:32:27 2006
@@ -65,7 +65,7 @@
 	PyCFunctionObject* f = (PyCFunctionObject*)func;
 	PyCFunction meth = PyCFunction_GET_FUNCTION(func);
 	PyObject *self = PyCFunction_GET_SELF(func);
-	long size;
+	Py_ssize_t size;
 
 	switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
 	case METH_VARARGS:
@@ -81,7 +81,7 @@
 			if (size == 0)
 				return (*meth)(self, NULL);
 			PyErr_Format(PyExc_TypeError,
-			    "%.200s() takes no arguments (%ld given)",
+			    "%.200s() takes no arguments (%zd given)",
 			    f->m_ml->ml_name, size);
 			return NULL;
 		}
@@ -92,7 +92,7 @@
 			if (size == 1)
 				return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
 			PyErr_Format(PyExc_TypeError,
-			    "%.200s() takes exactly one argument (%ld given)",
+			    "%.200s() takes exactly one argument (%zd given)",
 			    f->m_ml->ml_name, size);
 			return NULL;
 		}

Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c	(original)
+++ python/trunk/Objects/stringobject.c	Thu Feb 16 15:32:27 2006
@@ -1030,7 +1030,7 @@
 	const char *sub = PyString_AS_STRING(el);
 	char *last;
 	Py_ssize_t len_sub = PyString_GET_SIZE(el);
-	int shortsub;
+	Py_ssize_t shortsub;
 	char firstchar, lastchar;
 
 	if (!PyString_CheckExact(el)) {
@@ -2942,11 +2942,11 @@
 static PyObject *
 string_zfill(PyStringObject *self, PyObject *args)
 {
-    long fill;
+    Py_ssize_t fill;
     PyObject *s;
     char *p;
 
-    int width;
+    long width;
     if (!PyArg_ParseTuple(args, "l:zfill", &width))
         return NULL;
 
@@ -3886,7 +3886,7 @@
 PyString_Format(PyObject *format, PyObject *args)
 {
 	char *fmt, *res;
-	int arglen, argidx;
+	Py_ssize_t arglen, argidx;
 	Py_ssize_t reslen, rescnt, fmtcnt;
 	int args_owned = 0;
 	PyObject *result, *orig_args;
@@ -4294,7 +4294,7 @@
 	/* Fiddle args right (remove the first argidx arguments) */
 	if (PyTuple_Check(orig_args) && argidx > 0) {
 		PyObject *v;
-		int n = PyTuple_GET_SIZE(orig_args) - argidx;
+		Py_ssize_t n = PyTuple_GET_SIZE(orig_args) - argidx;
 		v = PyTuple_New(n);
 		if (v == NULL)
 			goto error;

Modified: python/trunk/Objects/structseq.c
==============================================================================
--- python/trunk/Objects/structseq.c	(original)
+++ python/trunk/Objects/structseq.c	Thu Feb 16 15:32:27 2006
@@ -247,7 +247,7 @@
 	PyObject* tup;
 	PyObject* dict;
 	PyObject* result;
-	long n_fields, n_visible_fields, n_unnamed_fields;
+	Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields;
 	int i;
 	
 	n_fields = REAL_SIZE(self);

Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c	(original)
+++ python/trunk/Objects/tupleobject.c	Thu Feb 16 15:32:27 2006
@@ -278,7 +278,8 @@
 		if (y == -1)
 			return -1;
 		x = (x ^ y) * mult;
-		mult += 82520L + len + len;
+		/* the cast might truncate len; that doesn't change hash stability */
+		mult += (long)(82520L + len + len);
 	}
 	x += 97531L;
 	if (x == -1)
@@ -850,10 +851,10 @@
 static PyObject *
 tupleiter_len(tupleiterobject *it)
 {
-	long len = 0;
+	Py_ssize_t len = 0;
 	if (it->it_seq)
 		len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
-	return PyInt_FromLong(len);
+	return PyInt_FromSsize_t(len);
 }
 
 PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(it)).");

Modified: python/trunk/Objects/typeobject.c
==============================================================================
--- python/trunk/Objects/typeobject.c	(original)
+++ python/trunk/Objects/typeobject.c	Thu Feb 16 15:32:27 2006
@@ -1561,11 +1561,11 @@
 /* Replace Unicode objects in slots.  */
 
 static PyObject *
-_unicode_to_string(PyObject *slots, int nslots)
+_unicode_to_string(PyObject *slots, Py_ssize_t nslots)
 {
 	PyObject *tmp = slots;
 	PyObject *o, *o1;
-	int i;
+	Py_ssize_t i;
 	ssizessizeargfunc copy = slots->ob_type->tp_as_sequence->sq_slice;
 	for (i = 0; i < nslots; i++) {
 		if (PyUnicode_Check(o = PyTuple_GET_ITEM(tmp, i))) {
@@ -2428,7 +2428,7 @@
 same_slots_added(PyTypeObject *a, PyTypeObject *b)
 {
 	PyTypeObject *base = a->tp_base;
-	int size;
+	Py_ssize_t size;
 
 	if (base != b->tp_base)
 		return 0;
@@ -2904,7 +2904,7 @@
 static void
 inherit_special(PyTypeObject *type, PyTypeObject *base)
 {
-	int oldsize, newsize;
+	Py_ssize_t oldsize, newsize;
 
 	/* Special flag magic */
 	if (!type->tp_as_buffer && base->tp_as_buffer) {
@@ -3316,7 +3316,8 @@
 static int
 add_subclass(PyTypeObject *base, PyTypeObject *type)
 {
-	int i;
+	Py_ssize_t i;
+	int result;
 	PyObject *list, *ref, *new;
 
 	list = base->tp_subclasses;
@@ -3334,9 +3335,9 @@
 		if (PyWeakref_GET_OBJECT(ref) == Py_None)
 			return PyList_SetItem(list, i, new);
 	}
-	i = PyList_Append(list, new);
+	result = PyList_Append(list, new);
 	Py_DECREF(new);
-	return i;
+	return result;
 }
 
 static void
@@ -4160,7 +4161,7 @@
 				return NULL;
 			}
 		}
-		ival = PyInt_FromLong(i);
+		ival = PyInt_FromSsize_t(i);
 		if (ival != NULL) {
 			args = PyTuple_New(1);
 			if (args != NULL) {

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Thu Feb 16 15:32:27 2006
@@ -6541,7 +6541,7 @@
     return 1;
 }
 
-static int
+static Py_ssize_t
 unicode_buffer_getcharbuf(PyUnicodeObject *self,
 			  Py_ssize_t index,
 			  const void **ptr)


More information about the Python-checkins mailing list