[pypy-svn] r65732 - in pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 10 18:53:21 CEST 2009


Author: arigo
Date: Wed Jun 10 18:53:20 2009
New Revision: 65732

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Tests and fixes.


Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/ll2ctypes.py	Wed Jun 10 18:53:20 2009
@@ -524,6 +524,8 @@
 
     if isinstance(T, lltype.Ptr):
         if not llobj:   # NULL pointer
+            if T == llmemory.GCREF:
+                return ctypes.c_void_p(0)
             return get_ctypes_type(T)()
 
         if T is base_ptr_lltype():
@@ -946,7 +948,7 @@
     if not isinstance(RESTYPE, lltype.LowLevelType):
         raise TypeError("rffi.cast() first arg should be a TYPE")
     if isinstance(value, llmemory.fakeaddress):
-        value = value.ptr
+        value = value.ptr or 0
     TYPE1 = lltype.typeOf(value)
     cvalue = lltype2ctypes(value)
     cresulttype = get_ctypes_type(RESTYPE)

Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Wed Jun 10 18:53:20 2009
@@ -1005,3 +1005,18 @@
         ref = lltype.cast_opaque_ptr(llmemory.GCREF, node)
         v = lltype2ctypes(ref)
         assert isinstance(v, ctypes.c_void_p)
+
+    def test_gcref_null(self):
+        ref = lltype.nullptr(llmemory.GCREF.TO)
+        v = lltype2ctypes(ref)
+        assert isinstance(v, ctypes.c_void_p)
+
+    def test_cast_null_gcref(self):
+        ref = lltype.nullptr(llmemory.GCREF.TO)
+        value = rffi.cast(lltype.Signed, ref)
+        assert value == 0
+
+    def test_cast_null_fakeaddr(self):
+        ref = llmemory.NULL
+        value = rffi.cast(lltype.Signed, ref)
+        assert value == 0



More information about the Pypy-commit mailing list