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.0 -0700
+++ pygame-1.7.1release-fixed/src/event.c 2007-05-10 22:25:49.0
-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.0 -0800
+++ pygame-1.7.1release-fixed/src/image.c 2007-05-10 22:30:45.0
-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.h2005-04-17 22:46:24.0 -0700
+++ pygame-1.7.1release-fixed/src/pygame.h 2007-05-12 21:32:15.0
-0700
@@ -56,6 +56,13 @@
**/
#include Python.h
+/* support changes for Python 2.5 on earlier versions of Python */
+#if PY_VERSION_HEX 0x0205 !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.0 -0700
+++ pygame-1.7.1release-fixed/src/rect.c2007-05-10 23:01:14.0
-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(i0 || i3)
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(i0 || i3)
@@ -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;
+