Commits

illume committed 46cf8ee

64bit issues with Surface.get_masks and UintFromObj. thanks Lorenz Quack!

  • Participants
  • Parent commits 7ee7f7c

Comments (0)

Files changed (4)

 # BREAK = change breaks existing code
 # BUG    = fixed a bug that was (or could have been) crashing
 
+[SVN 2486]
+    [BUG] 64bit issues with Surface.get_masks and UintFromObj. 
+        thanks Lorenz Quack!
 
 [SVN 2481] July 7, 2009
     [BUG] typo in examples/sound_array_demos.py Thanks Evan Kroske!
 static int
 UintFromObj (PyObject* obj, Uint32* val)
 {
-    PyObject* intobj;
+    PyObject* longobj;
 
     if (PyNumber_Check (obj))
     {
-        if (!(intobj = PyNumber_Int (obj)))
+        if (!(longobj = PyNumber_Long (obj)))
             return 0;
-        *val = (Uint32) PyInt_AsLong (intobj);
-        Py_DECREF (intobj);
+        *val = (Uint32) PyLong_AsUnsignedLong (longobj);
+        Py_DECREF (longobj);
         return 1;
     }
     return 0;
 }
 
-static Uint32
+static int
 UintFromObjIndex (PyObject* obj, int _index, Uint32* val)
 {
     int result = 0;

File src/surface.c

 
     if (!surf)
         return RAISE (PyExc_SDLError, "display Surface quit");
-    return Py_BuildValue ("(iiii)", surf->format->Rmask, surf->format->Gmask,
+    return Py_BuildValue ("(IIII)", surf->format->Rmask, surf->format->Gmask,
                           surf->format->Bmask, surf->format->Amask);
 }
 

File test/surface_test.py

 
 def intify(i):
     """If i is a long, cast to an int while preserving the bits"""
-    if 0x10000000 & i:
-        return int(~(0xFFFFFFFF ^ i))
+    if 0x80000000 & i:
+        return int((0xFFFFFFFF & i))
     return i
 
 def longify(i):
-    """If i in an int, cast to a long while preserving the bits"""
+    """If i is an int, cast to a long while preserving the bits"""
     if i < 0:
         return 0xFFFFFFFF & i
     return long(i)
         if surf2.get_bitsize() == 32:
             self.assertEqual(surf2.get_flags() & SRCALPHA, SRCALPHA)
 
-    def test_flags(self):
+    def test_masks(self):
         def make_surf(bpp, flags, masks):
             pygame.Surface((10, 10), flags, bpp, masks)
         # With some masks SDL_CreateRGBSurface does not work properly.
         masks = (0xFF000000, 0xFF0000, 0xFF00, 0)
-        self.failUnlessRaises(ValueError, make_surf, 32, 0, masks)
+        self.assertEqual(make_surf(32, 0, masks), None)
         # For 24 and 32 bit surfaces Pygame assumes no losses.
         masks = (0x7F0000, 0xFF00, 0xFF, 0)
         self.failUnlessRaises(ValueError, make_surf, 24, 0, masks)