Commits

Lenard Lindstrom committed 8c69d1a

Bug fix of pygame.PixelArray involving returned repr string

For Python 3.x, the pixelarray.c function Text_ConcatAndDel returned NULL
instead of the concatenated Unicode string. This caused the tp_repr slot
function _pxarray_repr to also return NULL instead of a string representation,
triggering an exception.

Comments (0)

Files changed (2)

 {
     PyObject *result = 0;
     if (*string && newpart) {
-        PyUnicode_Concat(*string, newpart);
+        result = PyUnicode_Concat(*string, newpart);
         Py_DECREF(*string);
         Py_DECREF(newpart);
     }

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.