-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
attached is a patch against 1.1.6 that makes Imaging work a little
better with python2.5 -  values returned from Py*_Length are trimmed to
INT_MAX and object methods now have correct signatures with Py_ssize_t.

I am not very sure about the value trimming. It's possible that it is
not necessary, at least in _imaging.c, although it certainly can't make
any harm.
(feel free to remove it anyway)

regards,
jan matejek
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFGDATzjBrWA+AvBr8RAteKAJkBgVA4MfLivcvxKRzaUhiA6A7NKQCdEuer
+XH05NkxLByTQkR8FbeGgYo=
=o1u1
-----END PGP SIGNATURE-----
--- _imaging.c
+++ _imaging.c
@@ -316,6 +316,7 @@
 getlist(PyObject* arg, int* length, const char* wrong_length, int type)
 {
     int i, n;
+    Py_ssize_t s;
     void* list;
 
     if (!PySequence_Check(arg)) {
@@ -323,7 +324,8 @@
 	return NULL;
     }
 
-    n = PyObject_Length(arg);
+    s = PyObject_Length(arg);
+    n = (s > INT_MAX) ? INT_MAX : s;
     if (length && wrong_length && n != *length) {
 	PyErr_SetString(PyExc_ValueError, wrong_length);
 	return NULL;
@@ -1125,6 +1127,7 @@
 {
     Imaging image;
     int n, i, x, y;
+    Py_ssize_t s;
 
     PyObject* data;
     double scale = 1.0;
@@ -1139,7 +1142,8 @@
 
     image = self->image;
 
-    n = PyObject_Length(data);
+    s = PyObject_Length(data);
+    n = (s > INT_MAX) ? INT_MAX : s;
     if (n > (int) (image->xsize * image->ysize)) {
 	PyErr_SetString(PyExc_TypeError, "too many data entries");
 	return NULL;
@@ -2880,7 +2884,7 @@
 
 /* basic sequence semantics */
 
-static int
+static Py_ssize_t
 image_length(ImagingObject *self)
 {
     Imaging im = self->image;
@@ -2889,7 +2893,7 @@
 }
 
 static PyObject *
-image_item(ImagingObject *self, int i)
+image_item(ImagingObject *self, Py_ssize_t i)
 {
     int x, y;
     Imaging im = self->image;
@@ -2904,7 +2908,7 @@
 }
 
 static PySequenceMethods image_as_sequence = {
-    (inquiry)image_length, /*sq_length*/
+    (lenfunc)image_length, /*sq_length*/
     (binaryfunc)0, /*sq_concat*/
     (ssizeargfunc)0, /*sq_repeat*/
     (ssizeargfunc)image_item, /*sq_item*/
--- path.c
+++ path.c
@@ -111,6 +111,7 @@
 PyPath_Flatten(PyObject* data, double **pxy)
 {
     int i, j, n;
+    Py_ssize_t s;
     double *xy;
     PyBufferProcs *buffer;
 
@@ -147,7 +148,8 @@
     }
 
     j = 0;
-    n = PyObject_Length(data);
+    s = PyObject_Length(data);
+    n = (s > INT_MAX) ? INT_MAX : s;
     /* Just in case __len__ breaks (or doesn't exist) */
     if (PyErr_Occurred())
         return -1;
@@ -357,7 +359,7 @@
 }
 
 static PyObject*
-path_getitem(PyPathObject* self, int i)
+path_getitem(PyPathObject* self, Py_ssize_t i)
 {
     if (i < 0 || i >= self->count) {
 	PyErr_SetString(PyExc_IndexError, "path index out of range");
@@ -368,7 +370,7 @@
 }
 
 static PyObject*
-path_getslice(PyPathObject* self, int ilow, int ihigh)
+path_getslice(PyPathObject* self, Py_ssize_t ilow, Py_ssize_t ihigh)
 {
     /* adjust arguments */
     if (ilow < 0)
@@ -385,7 +387,7 @@
     return (PyObject*) path_new(ihigh - ilow, self->xy + ilow * 2, 1);
 }
 
-static int
+static Py_ssize_t
 path_len(PyPathObject* self)
 {
     return self->count;
@@ -423,7 +425,7 @@
 }
 
 static int
-path_setitem(PyPathObject* self, int i, PyObject* op)
+path_setitem(PyPathObject* self, Py_ssize_t i, PyObject* op)
 {
     double* xy;
 
@@ -556,7 +558,7 @@
 }
 
 static PySequenceMethods path_as_sequence = {
-	(inquiry)path_len, /*sq_length*/
+	(lenfunc)path_len, /*sq_length*/
 	(binaryfunc)0, /*sq_concat*/
 	(ssizeargfunc)0, /*sq_repeat*/
 	(ssizeargfunc)path_getitem, /*sq_item*/
_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to