[pypy-svn] r61036 - in pypy/branch/oo-jit/pypy/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Fri Jan 16 15:41:27 CET 2009


Author: fijal
Date: Fri Jan 16 15:41:25 2009
New Revision: 61036

Modified:
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
The ability to pass around llmemory.GCREF. Note that it's only about
passing it around, address cast to int won't work after translation
(I need to investigate to see whether it'll really be a problem)


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	Fri Jan 16 15:41:25 2009
@@ -193,6 +193,8 @@
     elif isinstance(T, lltype.OpaqueType):
         if T is lltype.RuntimeTypeInfo:
             return ctypes.c_char * 2
+        if T == llmemory.GCREF.TO:
+            return ctypes.c_void_p
         if T.hints.get('external', None) != 'C':
             raise TypeError("%s is not external" % T)
         return ctypes.c_char * T.hints['getsize']()
@@ -472,12 +474,15 @@
         return uninitialized2ctypes(llobj.TYPE)
 
     T = lltype.typeOf(llobj)
+
     if isinstance(T, lltype.Ptr):
         if not llobj:   # NULL pointer
             return get_ctypes_type(T)()
 
         if T is base_ptr_lltype():
             return new_opaque_object(llobj)
+        if T == llmemory.GCREF:
+            return new_opaque_object(llobj._obj)
         container = llobj._obj
         if isinstance(T.TO, lltype.FuncType):
             # XXX a temporary workaround for comparison of lltype.FuncType
@@ -589,7 +594,7 @@
     if isinstance(T, lltype.Ptr):
         if not cobj:   # NULL pointer
             return lltype.nullptr(T.TO)
-        if T is base_ptr_lltype():
+        if T is base_ptr_lltype() or T == llmemory.GCREF:
             return _opaque_list[ctypes.cast(cobj, ctypes.c_void_p).value]
         if isinstance(T.TO, lltype.Struct):
             if T.TO._arrayfld is not None:

Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Fri Jan 16 15:41:25 2009
@@ -925,3 +925,10 @@
         res = cast_adr_to_int(someaddr())
         assert isinstance(res, int)
         assert res == -sys.maxint/2 - 1
+
+    def test_cast_gcref_back_and_forth(self):
+        NODE = lltype.GcStruct('NODE')
+        node = lltype.malloc(NODE)
+        ref = lltype.cast_opaque_ptr(llmemory.GCREF, node)
+        back = rffi.cast(llmemory.GCREF, rffi.cast(lltype.Signed, ref))
+        assert lltype.cast_opaque_ptr(lltype.Ptr(NODE), ref) == node



More information about the Pypy-commit mailing list