[pypy-svn] r22525 - in pypy/dist/pypy/rpython/memory: . test

rxe at codespeak.net rxe at codespeak.net
Mon Jan 23 15:51:30 CET 2006


Author: rxe
Date: Mon Jan 23 15:51:28 2006
New Revision: 22525

Modified:
   pypy/dist/pypy/rpython/memory/lladdress.py
   pypy/dist/pypy/rpython/memory/test/test_address.py
Log:
(cfbolz, rxe): made addr.signed[0] = offset convert offset to an int correctly


Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py	(original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py	Mon Jan 23 15:51:28 2006
@@ -48,6 +48,9 @@
         return simulator.getstruct(fmt, self.intaddress)
 
     def _store(self, fmt, *values):
+        # XXX annoyance: suddenly an OffsetOf changes into a Signed?!
+        if len(values) == 1 and isinstance(values[0], llmemory.OffsetOf):
+            values = [convert_offset_to_int(values[0])]
         simulator.setstruct(fmt, self.intaddress, *values)
 
     def __nonzero__(self):
@@ -67,12 +70,19 @@
     def __setitem__(self, offset, value):
         simulator.setstruct(self.format, self.intaddress + offset * self.size,
                             self.convert_to(value))
-           
+
+
 class _signed_accessor(_accessor):
     format = "l"
     size = struct.calcsize("l")
     convert_from = int
-    convert_to = int
+
+    def convert_to(self, offset):
+        from pypy.rpython.memory.lltypelayout import convert_offset_to_int
+        # XXX same annoyance as in _store
+        if isinstance(offset, llmemory.OffsetOf):
+            return convert_offset_to_int(offset)
+        return int(offset)
 
 class _unsigned_accessor(_accessor):
     format = "L"

Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py	Mon Jan 23 15:51:28 2006
@@ -419,4 +419,6 @@
         addr = raw_malloc(100)
         (addr + offsetof(S, 'b')).signed[0] = 42
         assert (addr + offsetof(S, 'b')).signed[0] == 42
-        
+        addr.signed[5] = offsetof(S, 'b')
+        offset = addr.signed[5]
+        assert (addr + offset).signed[0] == 42



More information about the Pypy-commit mailing list