[Python-checkins] r42411 - python/trunk/Modules/_bisectmodule.c python/trunk/Modules/_heapqmodule.c python/trunk/Modules/arraymodule.c python/trunk/Modules/cStringIO.c python/trunk/Modules/collectionsmodule.c python/trunk/Modules/itertoolsmodule.c python/trunk/Modules/mmapmodule.c python/trunk/Modules/operator.c python/trunk/Modules/parsermodule.c python/trunk/Modules/stropmodule.c python/trunk/Modules/structmodule.c python/trunk/Modules/zipimport.c

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


Author: martin.v.loewis
Date: Thu Feb 16 15:30:23 2006
New Revision: 42411

Modified:
   python/trunk/Modules/_bisectmodule.c
   python/trunk/Modules/_heapqmodule.c
   python/trunk/Modules/arraymodule.c
   python/trunk/Modules/cStringIO.c
   python/trunk/Modules/collectionsmodule.c
   python/trunk/Modules/itertoolsmodule.c
   python/trunk/Modules/mmapmodule.c
   python/trunk/Modules/operator.c
   python/trunk/Modules/parsermodule.c
   python/trunk/Modules/stropmodule.c
   python/trunk/Modules/structmodule.c
   python/trunk/Modules/zipimport.c
Log:
Use Py_ssize_t for counts and sizes.

Modified: python/trunk/Modules/_bisectmodule.c
==============================================================================
--- python/trunk/Modules/_bisectmodule.c	(original)
+++ python/trunk/Modules/_bisectmodule.c	Thu Feb 16 15:30:23 2006
@@ -6,10 +6,10 @@
 #include "Python.h"
 
 static int
-internal_bisect_right(PyObject *list, PyObject *item, int lo, int hi)
+internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t hi)
 {
 	PyObject *litem;
-	int mid, res;
+	Py_ssize_t mid, res;
 
 	if (hi == -1) {
 		hi = PySequence_Size(list);

Modified: python/trunk/Modules/_heapqmodule.c
==============================================================================
--- python/trunk/Modules/_heapqmodule.c	(original)
+++ python/trunk/Modules/_heapqmodule.c	Thu Feb 16 15:30:23 2006
@@ -9,10 +9,11 @@
 #include "Python.h"
 
 static int
-_siftdown(PyListObject *heap, int startpos, int pos)
+_siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
 {
 	PyObject *newitem, *parent;
-	int cmp, parentpos;
+	int cmp;
+	Py_ssize_t parentpos;
 
 	assert(PyList_Check(heap));
 	if (pos >= PyList_GET_SIZE(heap)) {
@@ -45,9 +46,9 @@
 }
 
 static int
-_siftup(PyListObject *heap, int pos)
+_siftup(PyListObject *heap, Py_ssize_t pos)
 {
-	int startpos, endpos, childpos, rightpos;
+	Py_ssize_t startpos, endpos, childpos, rightpos;
 	int cmp;
 	PyObject *newitem, *tmp;
 
@@ -123,7 +124,7 @@
 heappop(PyObject *self, PyObject *heap)
 {
 	PyObject *lastelt, *returnitem;
-	int n;
+	Py_ssize_t n;
 
 	if (!PyList_Check(heap)) {
 		PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
@@ -197,7 +198,7 @@
 static PyObject *
 heapify(PyObject *self, PyObject *heap)
 {
-	int i, n;
+	Py_ssize_t i, n;
 
 	if (!PyList_Check(heap)) {
 		PyErr_SetString(PyExc_TypeError, "heap argument must be a list");
@@ -300,10 +301,11 @@
 Equivalent to:  sorted(iterable, reverse=True)[:n]\n");
 
 static int
-_siftdownmax(PyListObject *heap, int startpos, int pos)
+_siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
 {
 	PyObject *newitem, *parent;
-	int cmp, parentpos;
+	int cmp;
+	Py_ssize_t parentpos;
 
 	assert(PyList_Check(heap));
 	if (pos >= PyList_GET_SIZE(heap)) {
@@ -336,9 +338,9 @@
 }
 
 static int
-_siftupmax(PyListObject *heap, int pos)
+_siftupmax(PyListObject *heap, Py_ssize_t pos)
 {
-	int startpos, endpos, childpos, rightpos;
+	Py_ssize_t startpos, endpos, childpos, rightpos;
 	int cmp;
 	PyObject *newitem, *tmp;
 
@@ -389,7 +391,7 @@
 nsmallest(PyObject *self, PyObject *args)
 {
 	PyObject *heap=NULL, *elem, *iterable, *los, *it, *oldelem;
-	int i, n;
+	Py_ssize_t i, n;
 
 	if (!PyArg_ParseTuple(args, "iO:nsmallest", &n, &iterable))
 		return NULL;

Modified: python/trunk/Modules/arraymodule.c
==============================================================================
--- python/trunk/Modules/arraymodule.c	(original)
+++ python/trunk/Modules/arraymodule.c	Thu Feb 16 15:30:23 2006
@@ -688,11 +688,11 @@
 }
 
 static int
-array_ass_slice(arrayobject *a, int ilow, int ihigh, PyObject *v)
+array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
 {
 	char *item;
-	int n; /* Size of replacement array */
-	int d; /* Change in size */
+	Py_ssize_t n; /* Size of replacement array */
+	Py_ssize_t d; /* Change in size */
 #define b ((arrayobject *)v)
 	if (v == NULL)
 		n = 0;
@@ -907,10 +907,7 @@
 		else if (cmp < 0)
 			return NULL;
 	}
-	if (i < LONG_MAX)
-	     return PyInt_FromLong((long)count);
-	else
-	     return PyLong_FromLong(count);
+	return PyInt_FromSsize_t(count);
 }
 
 PyDoc_STRVAR(count_doc,
@@ -987,9 +984,9 @@
 static PyObject *
 array_pop(arrayobject *self, PyObject *args)
 {
-	int i = -1;
+	Py_ssize_t i = -1;
 	PyObject *v;
-	if (!PyArg_ParseTuple(args, "|i:pop", &i))
+	if (!PyArg_ParseTuple(args, "|n:pop", &i))
 		return NULL;
 	if (self->ob_size == 0) {
 		/* Special-case most common failure cause */
@@ -1196,7 +1193,7 @@
 array_fromfile(arrayobject *self, PyObject *args)
 {
 	PyObject *f;
-	int n;
+	Py_ssize_t n;
 	FILE *fp;
         if (!PyArg_ParseTuple(args, "Oi:fromfile", &f, &n))
 		return NULL;
@@ -1207,9 +1204,9 @@
 	}
 	if (n > 0) {
 		char *item = self->ob_item;
-		int itemsize = self->ob_descr->itemsize;
+		Py_ssize_t itemsize = self->ob_descr->itemsize;
 		size_t nread;
-		int newlength;
+		Py_ssize_t newlength;
 		size_t newbytes;
 		/* Be careful here about overflow */
 		if ((newlength = self->ob_size + n) <= 0 ||
@@ -1577,13 +1574,13 @@
 array_subscr(arrayobject* self, PyObject* item)
 {
 	if (PyInt_Check(item)) {
-		long i = PyInt_AS_LONG(item);
+		Py_ssize_t i = PyInt_AS_LONG(item);
 		if (i < 0)
 			i += self->ob_size;
 		return array_item(self, i);
 	}
 	else if (PyLong_Check(item)) {
-		long i = PyLong_AsLong(item);
+		Py_ssize_t i = PyInt_AsSsize_t(item);
 		if (i == -1 && PyErr_Occurred())
 			return NULL;
 		if (i < 0)
@@ -1631,13 +1628,13 @@
 array_ass_subscr(arrayobject* 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 += self->ob_size;
 		return array_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)

Modified: python/trunk/Modules/cStringIO.c
==============================================================================
--- python/trunk/Modules/cStringIO.c	(original)
+++ python/trunk/Modules/cStringIO.c	Thu Feb 16 15:30:23 2006
@@ -129,7 +129,7 @@
 static PyObject *
 IO_getval(IOobject *self, PyObject *args) {
         PyObject *use_pos=Py_None;
-        int s;
+        Py_ssize_t s;
 
         UNLESS (IO__opencheck(self)) return NULL;
         UNLESS (PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL;
@@ -156,7 +156,7 @@
 
 static int
 IO_cread(PyObject *self, char **output, Py_ssize_t  n) {
-        int l;
+        Py_ssize_t l;
 
         UNLESS (IO__opencheck(IOOOBJECT(self))) return -1;
         l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos;  
@@ -279,7 +279,7 @@
 
         UNLESS (IO__opencheck(self)) return NULL;
 
-        return PyInt_FromLong(self->pos);
+        return PyInt_FromSsize_t(self->pos);
 }
 
 PyDoc_STRVAR(IO_truncate__doc__,

Modified: python/trunk/Modules/collectionsmodule.c
==============================================================================
--- python/trunk/Modules/collectionsmodule.c	(original)
+++ python/trunk/Modules/collectionsmodule.c	Thu Feb 16 15:30:23 2006
@@ -489,7 +489,7 @@
 {
 	PyObject *old_value;
 	block *b;
-	int n, len=deque->len, halflen=(len+1)>>1, index=i;
+	Py_ssize_t n, len=deque->len, halflen=(len+1)>>1, index=i;
 
 	if (i < 0 || i >= len) {
 		PyErr_SetString(PyExc_IndexError,

Modified: python/trunk/Modules/itertoolsmodule.c
==============================================================================
--- python/trunk/Modules/itertoolsmodule.c	(original)
+++ python/trunk/Modules/itertoolsmodule.c	Thu Feb 16 15:30:23 2006
@@ -1054,7 +1054,7 @@
 	PyObject *seq;
 	long start=0, stop=-1, step=1;
 	PyObject *it, *a1=NULL, *a2=NULL, *a3=NULL;
-	int numargs;
+	Py_ssize_t numargs;
 	isliceobject *lz;
 
 	if (!_PyArg_NoKeywords("islice()", kwds))
@@ -1378,7 +1378,7 @@
 {
 	PyObject *it, *iters, *func;
 	imapobject *lz;
-	int numargs, i;
+	Py_ssize_t numargs, i;
 
 	if (!_PyArg_NoKeywords("imap()", kwds))
 		return NULL;
@@ -1466,7 +1466,7 @@
 	PyObject *val;
 	PyObject *argtuple;
 	PyObject *result;
-	int numargs, i;
+	Py_ssize_t numargs, i;
 
 	numargs = PyTuple_Size(lz->iters);
 	argtuple = PyTuple_New(numargs);
@@ -1547,7 +1547,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	long	tuplesize;
+	Py_ssize_t	tuplesize;
 	long	iternum;		/* which iterator is active */
 	PyObject *ittuple;		/* tuple of iterators */
 } chainobject;
@@ -1558,7 +1558,7 @@
 chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
 	chainobject *lz;
-	int tuplesize = PySequence_Length(args);
+	Py_ssize_t tuplesize = PySequence_Length(args);
 	int i;
 	PyObject *ittuple;
 
@@ -2074,7 +2074,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	long	tuplesize;
+	Py_ssize_t	tuplesize;
 	PyObject *ittuple;		/* tuple of iterators */
 	PyObject *result;
 } izipobject;
@@ -2088,7 +2088,7 @@
 	int i;
 	PyObject *ittuple;  /* tuple of iterators */
 	PyObject *result;
-	int tuplesize = PySequence_Length(args);
+	Py_ssize_t tuplesize = PySequence_Length(args);
 
 	if (!_PyArg_NoKeywords("izip()", kwds))
 		return NULL;
@@ -2160,7 +2160,7 @@
 izip_next(izipobject *lz)
 {
 	int i;
-	long tuplesize = lz->tuplesize;
+	Py_ssize_t tuplesize = lz->tuplesize;
 	PyObject *result = lz->result;
 	PyObject *it;
 	PyObject *item;

Modified: python/trunk/Modules/mmapmodule.c
==============================================================================
--- python/trunk/Modules/mmapmodule.c	(original)
+++ python/trunk/Modules/mmapmodule.c	Thu Feb 16 15:30:23 2006
@@ -220,11 +220,11 @@
 mmap_read_method(mmap_object *self,
 		 PyObject *args)
 {
-	long num_bytes;
+	Py_ssize_t num_bytes;
 	PyObject *result;
 
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple(args, "l:read", &num_bytes))
+	if (!PyArg_ParseTuple(args, "n:read", &num_bytes))
 		return(NULL);
 
 	/* silently 'adjust' out-of-range requests */
@@ -240,7 +240,7 @@
 mmap_find_method(mmap_object *self,
 		 PyObject *args)
 {
-	long start = self->pos;
+	Py_ssize_t start = self->pos;
 	char *needle;
 	int len;
 
@@ -468,10 +468,10 @@
 static PyObject *
 mmap_flush_method(mmap_object *self, PyObject *args)
 {
-	unsigned long offset = 0;
-	unsigned long size = self->size;
+	Py_ssize_t offset = 0;
+	Py_ssize_t size = self->size;
 	CHECK_VALID(NULL);
-	if (!PyArg_ParseTuple (args, "|kk:flush", &offset, &size)) {
+	if (!PyArg_ParseTuple (args, "|nn:flush", &offset, &size)) {
 		return NULL;
 	} else if ((offset + size) > self->size) {
 		PyErr_SetString (PyExc_ValueError,
@@ -1092,8 +1092,8 @@
 	m_obj->map_handle = CreateFileMapping (m_obj->file_handle,
 					       NULL,
 					       flProtect,
-					       0,
-					       m_obj->size,
+					       (DWORD)(m_obj->size >> 32),
+					       (DWORD)(m_obj->size & 0xFFFFFFFF),
 					       m_obj->tagname);
 	if (m_obj->map_handle != NULL) {
 		m_obj->data = (char *) MapViewOfFile (m_obj->map_handle,

Modified: python/trunk/Modules/operator.c
==============================================================================
--- python/trunk/Modules/operator.c	(original)
+++ python/trunk/Modules/operator.c	Thu Feb 16 15:30:23 2006
@@ -296,7 +296,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	int nitems;
+	Py_ssize_t nitems;
 	PyObject *item;
 } itemgetterobject;
 
@@ -307,7 +307,7 @@
 {
 	itemgetterobject *ig;
 	PyObject *item;
-	int nitems;
+	Py_ssize_t nitems;
 
 	if (!_PyArg_NoKeywords("itemgetter()", kwds))
 		return NULL;
@@ -352,7 +352,7 @@
 itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
 {
 	PyObject *obj, *result;
-	int i, nitems=ig->nitems;
+	Py_ssize_t i, nitems=ig->nitems;
 
 	if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj))
 		return NULL;
@@ -435,7 +435,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	int nattrs;
+	Py_ssize_t nattrs;
 	PyObject *attr;
 } attrgetterobject;
 
@@ -446,7 +446,7 @@
 {
 	attrgetterobject *ag;
 	PyObject *attr;
-	int nattrs;
+	Py_ssize_t nattrs;
 
 	if (!_PyArg_NoKeywords("attrgetter()", kwds))
 		return NULL;
@@ -491,7 +491,7 @@
 attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
 {
 	PyObject *obj, *result;
-	int i, nattrs=ag->nattrs;
+	Py_ssize_t i, nattrs=ag->nattrs;
 
 	if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj))
 		return NULL;

Modified: python/trunk/Modules/parsermodule.c
==============================================================================
--- python/trunk/Modules/parsermodule.c	(original)
+++ python/trunk/Modules/parsermodule.c	Thu Feb 16 15:30:23 2006
@@ -782,7 +782,7 @@
                 res = NULL;
             }
             if (res && encoding) {
-                int len;
+                Py_ssize_t len;
                 len = PyString_GET_SIZE(encoding) + 1;
                 res->n_str = (char *)PyMem_MALLOC(len);
                 if (res->n_str != NULL)

Modified: python/trunk/Modules/stropmodule.c
==============================================================================
--- python/trunk/Modules/stropmodule.c	(original)
+++ python/trunk/Modules/stropmodule.c	Thu Feb 16 15:30:23 2006
@@ -166,8 +166,8 @@
 {
 	PyObject *seq;
 	char *sep = NULL;
-	int seqlen, seplen = 0;
-	int i, reslen = 0, slen = 0, sz = 100;
+	Py_ssize_t seqlen, seplen = 0;
+	Py_ssize_t i, reslen = 0, slen = 0, sz = 100;
 	PyObject *res = NULL;
 	char* p = NULL;
 	ssizeargfunc getitemfunc;
@@ -921,10 +921,11 @@
 strop_translate(PyObject *self, PyObject *args)
 {
 	register char *input, *table, *output;
-	register int i, c, changed = 0;
+	Py_ssize_t i; 
+	int c, changed = 0;
 	PyObject *input_obj;
 	char *table1, *output_start, *del_table=NULL;
-	int inlen, tablen, dellen = 0;
+	Py_ssize_t inlen, tablen, dellen = 0;
 	PyObject *result;
 	int trans_table[256];
 

Modified: python/trunk/Modules/structmodule.c
==============================================================================
--- python/trunk/Modules/structmodule.c	(original)
+++ python/trunk/Modules/structmodule.c	Thu Feb 16 15:30:23 2006
@@ -1031,7 +1031,7 @@
 	PyObject *format, *result, *v;
 	char *fmt;
 	int size, num;
-	int i, n;
+	Py_ssize_t i, n;
 	char *s, *res, *restart, *nres;
 	char c;
 
@@ -1097,7 +1097,7 @@
 				goto fail;
 			if (c == 's') {
 				/* num is string size, not repeat count */
-				int n;
+				Py_ssize_t n;
 				if (!PyString_Check(v)) {
 					PyErr_SetString(StructError,
 					  "argument for 's' must be a string");
@@ -1116,7 +1116,7 @@
 			else if (c == 'p') {
 				/* num is string size + 1,
 				   to fit in the count byte */
-				int n;
+				Py_ssize_t n;
 				num--; /* now num is max string size */
 				if (!PyString_Check(v)) {
 					PyErr_SetString(StructError,
@@ -1133,7 +1133,8 @@
 					memset(res+1+n, '\0', num-n);
 				if (n > 255)
 					n = 255;
-				*res++ = n; /* store the length byte */
+				/* store the length byte */
+				*res++ = Py_SAFE_DOWNCAST(n, Py_ssize_t, char);
 				res += num;
 				break;
 			}

Modified: python/trunk/Modules/zipimport.c
==============================================================================
--- python/trunk/Modules/zipimport.c	(original)
+++ python/trunk/Modules/zipimport.c	Thu Feb 16 15:30:23 2006
@@ -408,7 +408,7 @@
 	char *p, buf[MAXPATHLEN + 1];
 #endif
 	PyObject *toc_entry;
-	int len;
+	Py_ssize_t len;
 
 	if (!PyArg_ParseTuple(args, "s:zipimporter.get_data", &path))
 		return NULL;
@@ -910,7 +910,7 @@
 {
 	PyObject *code;
 	char *buf = PyString_AsString(data);
-	int size = PyString_Size(data);
+	Py_ssize_t size = PyString_Size(data);
 
 	if (size <= 9) {
 		PyErr_SetString(ZipImportError,


More information about the Python-checkins mailing list