Commits

illume  committed a76f2f4

Fixes some array interface related crashes and test failures on the amd64 platform(win and osx). Thanks Christoph Gohlke.

  • Participants
  • Parent commits 1d7d6b8

Comments (0)

Files changed (5)

     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;
     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';
     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

File src/pixelarray.c

 _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);
 }
 
 /**
 _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);
 }
 
 /**
     /* 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]

File src/pixelcopy.c

     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,
     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 };
     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;
 

File src/surface.c

     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:

File test/test_utils/arrinter.py

 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)