Commits

Lenard Lindstrom  committed c4a65a9 Merge

merge in Mac specific fixes

  • Participants
  • Parent commits 11814df, 82f658d

Comments (0)

Files changed (2)

File src/pixelarray.c

     PyObject *dict;        /* dict for subclassing */
     PyObject *weakrefs;    /* Weakrefs for subclassing */
     PyObject *surface;     /* Surface associated with the array */
-    PyObject *lock;        /* Lock object for the surface */
     Py_ssize_t shape[2];   /* (row,col) shape of array in pixels */
     Py_ssize_t strides[2]; /* (row,col) offsets in bytes */
     Uint8  *pixels;        /* Start of array data */
 {
     PyObject *result = 0;
     if (*string && newpart) {
-        PyUnicode_Concat(*string, newpart);
+        result = PyUnicode_Concat(*string, newpart);
         Py_DECREF(*string);
         Py_DECREF(newpart);
     }
         return 0;
     }
 
+    self->weakrefs = 0;
+    self->dict = 0;
     if (!parent) {
         if (!surface) {
             Py_TYPE(self)->tp_free((PyObject *)self);
         self->parent = 0;
         self->surface = surface;
         Py_INCREF(surface);
-        self->lock = PySurface_LockLifetime(surface, (PyObject *)self);
-        if (!self->lock) {
+        if (!PySurface_LockBy(surface, (PyObject *)self)) {
             Py_DECREF(surface);
             Py_TYPE(self)->tp_free((PyObject *)self);
             return 0;
         surface = parent->surface;
         self->surface = surface;
         Py_INCREF(surface);
-        self->lock = parent->lock;
-        Py_INCREF(self->lock);
     }
     self->shape[0] = dim0;
     self->shape[1] = dim1;
     self->strides[0] = stride0;
     self->strides[1] = stride1;
     self->pixels = pixels;
-    self->weakrefs = 0;
-    self->dict = 0;
 
     return self;
 }
 static void
 _pxarray_dealloc(PyPixelArray *self)
 {
+    if (self->weakrefs) {
+        PyObject_ClearWeakRefs((PyObject *)self);
+    }
     PyObject_GC_UnTrack(self);
-    if (self->weakrefs) {
-        PyObject_ClearWeakRefs ((PyObject *) self);
+    if (self->parent) {
+        Py_DECREF(self->parent);
     }
-    Py_XDECREF(self->lock);
-    Py_XDECREF(self->parent);
+    else {
+        PySurface_UnlockBy(self->surface, (PyObject *)self);
+    }
+    Py_DECREF(self->surface);
     Py_XDECREF(self->dict);
-    Py_DECREF(self->surface);
     Py_TYPE(self)->tp_free((PyObject *)self);
 }
 
     if (self->dict) {
         Py_VISIT(self->dict);
     }
-    if (self->lock) {
-        Py_VISIT(self->lock);
-    }
     if (self->parent) {
         Py_VISIT((PyObject *)self->parent);
     }
         }
         /* A simple index. */
         i = PyNumber_AsSsize_t(val, PyExc_IndexError);
+        Py_DECREF(val);
 #else
         i = PyInt_Check(op) ? PyInt_AsLong(op) : PyLong_AsLong(op);
 #endif
         }
         /* A simple index. */
         i = PyNumber_AsSsize_t(val, PyExc_IndexError);
+        Py_DECREF(val);
 #else
         i = PyInt_Check(op) ? PyInt_AsLong (op) : PyLong_AsLong (op);
 #endif

File test/pixelarray_test.py

         self.assertRaises (ValueError, ar.__setitem__, Ellipsis, ar[:, 0:2])
         self.assertRaises (ValueError, ar.__setitem__, Ellipsis, ar[0:2, :])
 
+    def test_repr (self):
+        # Python 3.x bug: the tp_repr slot function returned NULL instead
+        # of a Unicode string, triggering an exception.
+        sf = pygame.Surface ((3, 1), pygame.SRCALPHA, 16)
+        ar = pygame.PixelArray(sf)
+        ar[...] = 42
+        pixel = sf.get_at_mapped ((0, 0))
+        self.assertEqual(repr (ar),
+                         type (ar).__name__ + "([\n  [42, 42, 42]]\n)")
+
 class PixelArrayArrayInterfaceTest (unittest.TestCase, TestMixin):
     def test_basic (self):
         # Check unchanging fields.