[pypy-svn] r60753 - pypy/branch/oo-jit/pypy/rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Jan 1 18:37:38 CET 2009


Author: arigo
Date: Thu Jan  1 18:37:38 2009
New Revision: 60753

Modified:
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py
Log:
Revert the change to lltype and implement it as ll2ctypes.cast_adr_to_int().


Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py	Thu Jan  1 18:37:38 2009
@@ -881,6 +881,20 @@
     def _cast_to_int(self):
         return ctypes.cast(self.void_p, ctypes.c_long)
 
+def cast_adr_to_int(addr):
+    if isinstance(addr, llmemory.fakeaddress):
+        # use ll2ctypes to obtain a real ctypes-based representation of
+        # the memory, and cast that address as an integer
+        if addr.ptr is None:
+            return 0
+        else:
+            c = lltype2ctypes(addr.ptr)
+            c = ctypes.cast(c, ctypes.c_void_p)
+            assert c.value
+            return c.value
+    else:
+        return addr._cast_to_int()
+
 # ____________________________________________________________
 # errno
 

Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/lltype.py	Thu Jan  1 18:37:38 2009
@@ -1171,14 +1171,12 @@
         obj = self._obj
         if isinstance(obj, int):
             return obj     # special case for cast_int_to_ptr() results
-        # use ll2ctypes to obtain a real ctypes-based representation of
-        # the memory, and cast that address as an integer
-        import ctypes
-        from pypy.rpython.lltypesystem import ll2ctypes
-        c = ll2ctypes.lltype2ctypes(self)
-        c = ctypes.cast(c, ctypes.c_void_p)
-        assert c.value
-        return c.value
+        obj = normalizeptr(self)._obj
+        result = intmask(obj._getid())
+        # assume that id() returns an addressish value which is
+        # not zero and aligned to at least a multiple of 4
+        assert result != 0 and (result & 3) == 0
+        return result
 
     def _cast_to_adr(self):
         from pypy.rpython.lltypesystem import llmemory



More information about the Pypy-commit mailing list