[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Patch for win-amd64



Hello,

please consider the attached patch. It fixes some array interface related crashes and test failures on the win-amd64 platform.

Christoph
Index: src/color.c
===================================================================
--- src/color.c	(revision 3195)
+++ src/color.c	(working copy)
@@ -1353,6 +1353,7 @@
     typedef struct {
         PyArrayInterface inter;
         Py_intptr_t shape[1];
+        Py_intptr_t strides[1];
     } _color_view_t;
     _color_view_t *view = PyMem_New(_color_view_t, 1);
     PyObject *cobj;
@@ -1360,7 +1361,7 @@
     if (!view) {
         return PyErr_NoMemory();
     }
-    view->shape[0] = color->len;
+    view->shape[0] = (Py_intptr_t)color->len;
     view->inter.two = 2;
     view->inter.nd = 1;
     view->inter.typekind = 'u';
@@ -1368,7 +1369,8 @@
     view->inter.flags = (PAI_CONTIGUOUS | PAI_FORTRAN |
                          PAI_ALIGNED | PAI_NOTSWAPPED);
     view->inter.shape = view->shape;
-    view->inter.strides = &(view->inter.itemsize);
+    view->strides[0] = (Py_intptr_t)view->inter.itemsize;
+    view->inter.strides = view->strides;
     view->inter.data = color->data;
     
 #if PY3
Index: src/surface.c
===================================================================
--- src/surface.c	(revision 3195)
+++ src/surface.c	(working copy)
@@ -2186,10 +2186,10 @@
     inter->descr = 0;
     shape = inter->shape;
     strides = inter->strides;
-    shape[0] = surface->w;
-    shape[1] = surface->h;
-    strides[0] = pixelsize;
-    strides[1] = surface->pitch;
+    shape[0] = (Py_intptr_t)surface->w;
+    shape[1] = (Py_intptr_t)surface->h;
+    strides[0] = (Py_intptr_t)pixelsize;
+    strides[1] = (Py_intptr_t)surface->pitch;
     switch (view_kind) {
 
     case VIEWKIND_2D:
Index: src/pixelcopy.c
===================================================================
--- src/pixelcopy.c	(revision 3195)
+++ src/pixelcopy.c	(working copy)
@@ -158,13 +158,13 @@
     char *dst = (char *)inter->data;
     int w = surf->w;
     int h = surf->h;
-    unsigned dx_src = surf->format->BytesPerPixel;
-    unsigned dy_src = surf->pitch;
-    unsigned dz_src = 1;
-    unsigned dx_dst = inter->strides[0];
-    unsigned dy_dst = inter->strides[1];
-    int dz_dst = 1;
-    int x, y, z;
+    Py_intptr_t dx_src = surf->format->BytesPerPixel;
+    Py_intptr_t dy_src = surf->pitch;
+    Py_intptr_t dz_src = 1;
+    Py_intptr_t dx_dst = inter->strides[0];
+    Py_intptr_t dy_dst = inter->strides[1];
+    Py_intptr_t dz_dst = 1;
+    Py_intptr_t x, y, z;
 
     if (inter->shape[0] != w || inter->shape[1] != h) {
         PyErr_Format(PyExc_ValueError,
@@ -220,13 +220,13 @@
     char *dst = (char *)inter->data;
     int w = surf->w;
     int h = surf->h;
-    unsigned dx_src = surf->format->BytesPerPixel;
-    unsigned dy_src = surf->pitch;
-    unsigned dx_dst = inter->strides[0];
-    unsigned dy_dst = inter->strides[1];
-    int dz_dst = 1;
-    unsigned dz_pix;
-    int x, y, z;
+    Py_intptr_t dx_src = surf->format->BytesPerPixel;
+    Py_intptr_t dy_src = surf->pitch;
+    Py_intptr_t dx_dst = inter->strides[0];
+    Py_intptr_t dy_dst = inter->strides[1];
+    Py_intptr_t dz_dst = 1;
+    Py_intptr_t dz_pix;
+    Py_intptr_t x, y, z;
     Uint8 r, g, b, a;
     Uint8 *element;
     _pc_pixel_t pixel = { 0 };
@@ -332,14 +332,14 @@
     char *dst = (char *)inter->data;
     int w = surf->w;
     int h = surf->h;
-    unsigned dx_src = surf->format->BytesPerPixel;
-    unsigned dy_src = surf->pitch;
-    unsigned dx_dst = inter->strides[0];
-    unsigned dy_dst = inter->strides[1];
-    unsigned dp_dst = inter->strides[2];
-    int dz_dst = 1;
-    unsigned dz_pix;
-    int x, y, z;
+    Py_intptr_t dx_src = surf->format->BytesPerPixel;
+    Py_intptr_t dy_src = surf->pitch;
+    Py_intptr_t dx_dst = inter->strides[0];
+    Py_intptr_t dy_dst = inter->strides[1];
+    Py_intptr_t dp_dst = inter->strides[2];
+    Py_intptr_t dz_dst = 1;
+    Py_intptr_t dz_pix;
+    Py_intptr_t x, y, z;
     _pc_pixel_t pixel = { 0 };
     Uint8 r, g, b;
 
Index: src/pixelarray.c
===================================================================
--- src/pixelarray.c	(revision 3195)
+++ src/pixelarray.c	(working copy)
@@ -404,9 +404,9 @@
 _pxarray_get_shape(PyPixelArray *self, void *closure)
 {
     if (self->dim1) {
-        return Py_BuildValue("(ll)", (long)self->dim0, (long)self->dim1);
+        return Py_BuildValue("(nn)", self->dim0, self->dim1);
     }
-    return Py_BuildValue("(l)", (long)self->dim0);
+    return Py_BuildValue("(n)", self->dim0);
 }
 
 /**
@@ -416,9 +416,9 @@
 _pxarray_get_strides(PyPixelArray *self, void *closure)
 {
     if (self->dim1) {
-        return Py_BuildValue("(ll)", (long)self->stride0, (long)self->stride1);
+        return Py_BuildValue("(nn)", self->stride0, self->stride1);
     }
-    return Py_BuildValue("(l)", (long)self->stride0);
+    return Py_BuildValue("(n)", self->stride0);
 }
 
 /**
@@ -1589,8 +1589,8 @@
     /* TODO: by time we can make this faster by avoiding the creation of
      * temporary subarrays.
      */
-    Uint32 dim0 = array->dim0;
-    Uint32 dim1 = array->dim1;
+    Py_ssize_t dim0 = array->dim0;
+    Py_ssize_t dim1 = array->dim1;
     
     /* Note: order matters here.
      * First check array[x,y], then array[x:y:z], then array[x]
Index: test/test_utils/arrinter.py
===================================================================
--- test/test_utils/arrinter.py	(revision 3195)
+++ test/test_utils/arrinter.py	(working copy)
@@ -12,8 +12,8 @@
 class PyArrayInterface(Structure):
     _fields_ = [('two', c_int), ('nd', c_int), ('typekind', c_char),
                 ('itemsize', c_int), ('flags', c_int),
-                ('shape', POINTER(c_int)),
-                ('strides', POINTER(c_int)),
+                ('shape', POINTER(c_ssize_t)),
+                ('strides', POINTER(c_ssize_t)),
                 ('data', c_void_p), ('descr', py_object)]
 
 PAI_Ptr = POINTER(PyArrayInterface)