[pypy-commit] lang-smalltalk default: dynamically get the pixelbuffer, because realloc may move it

timfel noreply at buildbot.pypy.org
Fri Feb 7 09:55:32 CET 2014


Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: 
Changeset: r595:1bcfc3ded0b0
Date: 2014-02-05 10:14 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/1bcfc3ded0b0/

Log:	dynamically get the pixelbuffer, because realloc may move it

diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -39,7 +39,8 @@
 class SDLDisplay(object):
     _attrs_ = ["screen", "width", "height", "depth", "surface", "has_surface",
                "mouse_position", "button", "key", "interrupt_key", "_defer_updates",
-               "_deferred_event"]
+               "_deferred_event", "pixelbuffer"]
+    _immutable_fields_ = ["pixelbuffer?"]
 
     def __init__(self, title):
         assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
@@ -69,9 +70,10 @@
             raise RuntimeError
         elif d == 8:
             self.set_squeak_colormap(self.screen)
+        self.pixelbuffer = rffi.cast(rffi.UINTP, self.screen.c_pixels)
 
     def get_pixelbuffer(self):
-        return rffi.cast(rffi.ULONGP, self.screen.c_pixels)
+        return jit.promote(self.pixelbuffer)
 
     def defer_updates(self, flag):
         self._defer_updates = flag
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -991,7 +991,6 @@
     def __init__(self, space, w_class, size, depth, display):
         W_AbstractObjectWithClassReference.__init__(self, space, w_class)
         self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT), size, flavor='raw')
-        self.pixelbuffer = display.get_pixelbuffer()
         self._realsize = size
         self.display = display
         self._depth = depth
@@ -1027,7 +1026,7 @@
 
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        self.pixelbuffer[n] = word
+        self.display.get_pixelbuffer()[n] = word
 
     def is_array_object(self):
         return True
@@ -1061,13 +1060,13 @@
             ((msb & mask) << 11)
         )
 
-        self.pixelbuffer[n] = r_uint(lsb | (msb << 16))
+        self.display.get_pixelbuffer()[n] = r_uint(lsb | (msb << 16))
 
 
 class W_8BitDisplayBitmap(W_DisplayBitmap):
     def setword(self, n, word):
         self._real_depth_buffer[n] = word
-        self.pixelbuffer[n] = r_uint(
+        self.display.get_pixelbuffer()[n] = r_uint(
             (word >> 24) |
             ((word >> 8) & 0x0000ff00) |
             ((word << 8) & 0x00ff0000) |
@@ -1092,7 +1091,7 @@
                 pixel = r_uint(word) >> rshift
                 mapword |= (r_uint(pixel) << (i * 8))
                 word <<= self._depth
-            self.pixelbuffer[pos] = mapword
+            self.display.get_pixelbuffer()[pos] = mapword
             pos += 1
 
     def compute_pos(self, n):


More information about the pypy-commit mailing list