pygame 1.7.1 fails with Python 2.5, due to the introduction of Py_ssize_t. (it 
compiles, but calling pygame.event.Event() with keyword arguments fails to 
actually add anything to the dict used by the event object

Following is an initial patch to fix this. I didn't audit the code for 
correctness, I just set CFLAGS="-Wall -Wextra" and fixed the places where gcc 
complained. It does fix the problem I was having with pygame.event.Event 
though.

diff -Nurp pygame-1.7.1release/src/event.c 
pygame-1.7.1release-fixed/src/event.c
--- pygame-1.7.1release/src/event.c     2005-08-15 04:11:40.000000000 -0700
+++ pygame-1.7.1release-fixed/src/event.c       2007-05-10 22:25:49.000000000 
-0700
@@ -534,7 +534,7 @@ static PyObject* Event(PyObject* self, P
        if(keywords)
        {
                PyObject *key, *value;
-               int pos  = 0;
+               Py_ssize_t pos  = 0;
                while(PyDict_Next(keywords, &pos, &key, &value))
                        PyDict_SetItem(dict, key, value);
        }
diff -Nurp pygame-1.7.1release/src/image.c 
pygame-1.7.1release-fixed/src/image.c
--- pygame-1.7.1release/src/image.c     2005-03-12 17:12:35.000000000 -0800
+++ pygame-1.7.1release-fixed/src/image.c       2007-05-10 22:30:45.000000000 
-0700
@@ -291,7 +291,8 @@ PyObject* image_tostring(PyObject* self,
        PyObject *surfobj, *string=NULL;
        char *format, *data, *pixels;
        SDL_Surface *surf, *temp=NULL;
-       int w, h, color, len, flipped=0;
+       Py_ssize_t len;
+       int w, h, color, flipped=0;
        int Rmask, Gmask, Bmask, Amask, Rshift, Gshift, Bshift, Ashift, Rloss, 
Gloss, Bloss, Aloss;
        int hascolorkey, colorkey;
 
@@ -605,7 +606,8 @@ PyObject* image_fromstring(PyObject* sel
        PyObject *string;
        char *format, *data;
        SDL_Surface *surf = NULL;
-       int w, h, len, flipped=0;
+       Py_ssize_t len;
+       int w, h, flipped=0;
        int loopw, looph;
 
        if(!PyArg_ParseTuple(arg, "O!(ii)s|i", &PyString_Type, &string, &w, &h, 
&format, &flipped))
@@ -729,7 +731,8 @@ PyObject* image_frombuffer(PyObject* sel
        PyObject *buffer;
        char *format, *data;
        SDL_Surface *surf = NULL;
-       int w, h, len;
+       Py_ssize_t len;
+       int w, h;
         PyObject *surfobj;
 
        if(!PyArg_ParseTuple(arg, "O(ii)s|i", &buffer, &w, &h, &format))
diff -Nurp pygame-1.7.1release/src/pygame.h 
pygame-1.7.1release-fixed/src/pygame.h
--- pygame-1.7.1release/src/pygame.h    2005-04-17 22:46:24.000000000 -0700
+++ pygame-1.7.1release-fixed/src/pygame.h      2007-05-12 21:32:15.000000000 
-0700
@@ -56,6 +56,13 @@
         **/
 #include <Python.h>
 
+/* support changes for Python 2.5 on earlier versions of Python */
+#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
 #ifdef MS_WIN32 /*Python gives us MS_WIN32, SDL needs just WIN32*/
 #define WIN32
 #endif
Files pygame-1.7.1release/src/.pygame.h.swp and 
pygame-1.7.1release-fixed/src/.pygame.h.swp differ
diff -Nurp pygame-1.7.1release/src/rect.c pygame-1.7.1release-fixed/src/rect.c
--- pygame-1.7.1release/src/rect.c      2004-07-18 18:39:49.000000000 -0700
+++ pygame-1.7.1release-fixed/src/rect.c        2007-05-10 23:01:14.000000000 
-0700
@@ -589,7 +589,7 @@ static PyObject* rect_collidedict(PyObje
 {
        PyRectObject* self = (PyRectObject*)oself;
        GAME_Rect *argrect, temp;
-       int loop=0;
+       Py_ssize_t loop=0;
        PyObject* dict, *key, *val;
        PyObject* ret = NULL;
 
@@ -640,7 +640,7 @@ static PyObject* rect_collidedictall(PyO
 {
        PyRectObject* self = (PyRectObject*)oself;
        GAME_Rect *argrect, temp;
-       int loop=0;
+       Py_ssize_t loop=0;
        PyObject* dict, *key, *val;
        PyObject* ret = NULL;
 
@@ -937,13 +937,15 @@ static struct PyMethodDef rect_methods[]
 
 /* sequence functions */
 
-static int rect_length(PyRectObject *self)
+static Py_ssize_t rect_length(PyObject *_self)
 {
        return 4;
 }
 
-static PyObject* rect_item(PyRectObject *self, int i)
+static PyObject* rect_item(PyObject *_self, Py_ssize_t i)
 {
+       PyRectObject *self = (PyRectObject*) _self;
+
        int* data = (int*)&self->r;
        if(i<0 || i>3)
                return RAISE(PyExc_IndexError, "Invalid rect Index");
@@ -951,8 +953,10 @@ static PyObject* rect_item(PyRectObject 
        return PyInt_FromLong(data[i]);
 }
 
-static int rect_ass_item(PyRectObject *self, int i, PyObject *v)
+static int rect_ass_item(PyObject *_self, Py_ssize_t i, PyObject *v)
 {
+       PyRectObject *self = (PyRectObject*) _self;
+
        int val;
        int* data = (int*)&self->r;
        if(i<0 || i>3)
@@ -970,8 +974,10 @@ static int rect_ass_item(PyRectObject *s
 }
 
 
-static PyObject* rect_slice(PyRectObject *self, int ilow, int ihigh)
+static PyObject* rect_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t 
ihigh)
 {
+       PyRectObject *self = (PyRectObject*) _self;
+
        PyObject *list;
        int* data = (int*)&self->r;
        int numitems, loop, l = 4;
@@ -994,8 +1000,10 @@ static PyObject* rect_slice(PyRectObject
 
 
 
-static int rect_ass_slice(PyRectObject *self, int ilow, int ihigh, PyObject 
*v)
+static int rect_ass_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh, 
PyObject *v)
 {
+       PyRectObject *self = (PyRectObject*) _self;
+
        int* data = (int*)&self->r;
        int numitems, loop, l = 4;
        int val;
@@ -1031,13 +1039,13 @@ static int rect_ass_slice(PyRectObject *
 }
 
 static PySequenceMethods rect_as_sequence = {
-       (inquiry)rect_length,                           /*length*/
-       (binaryfunc)NULL,                                       /*concat*/
-       (intargfunc)NULL,                                       /*repeat*/
-       (intargfunc)rect_item,                          /*item*/
-       (intintargfunc)rect_slice,                      /*slice*/
-       (intobjargproc)rect_ass_item,           /*ass_item*/
-       (intintobjargproc)rect_ass_slice,       /*ass_slice*/
+       rect_length,    /*length*/
+       NULL,                   /*concat*/
+       NULL,                   /*repeat*/
+       rect_item,              /*item*/
+       rect_slice,             /*slice*/
+       rect_ass_item,  /*ass_item*/
+       rect_ass_slice, /*ass_slice*/
 };
 
 
diff -Nurp pygame-1.7.1release/src/surface.c 
pygame-1.7.1release-fixed/src/surface.c
--- pygame-1.7.1release/src/surface.c   2005-02-05 16:03:07.000000000 -0800
+++ pygame-1.7.1release-fixed/src/surface.c     2007-05-10 
22:33:56.000000000 -0700
@@ -1353,7 +1353,7 @@ static PyObject* surf_get_rect(PyObject*
        if(rect && kw)
        {
                PyObject *key, *value;
-               int pos=0;
+               Py_ssize_t pos=0;
                while(PyDict_Next(kw, &pos, &key, &value))
                {
                        if((PyObject_SetAttr(rect, key, value) == -1))

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to