[pypy-commit] pypy default: (alex, arigato) Fixed unwrap() to work with non-GC structs. This is needed for virtualizables which aren't GC pointers, which is in turn needed for micronumpy.

alex_gaynor noreply at buildbot.pypy.org
Sat May 14 18:28:49 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r44162:18c7629228fa
Date: 2011-05-14 11:36 -0500
http://bitbucket.org/pypy/pypy/changeset/18c7629228fa/

Log:	(alex, arigato) Fixed unwrap() to work with non-GC structs. This is
	needed for virtualizables which aren't GC pointers, which is in turn
	needed for micronumpy.

diff --git a/pypy/jit/metainterp/test/test_warmstate.py b/pypy/jit/metainterp/test/test_warmstate.py
--- a/pypy/jit/metainterp/test/test_warmstate.py
+++ b/pypy/jit/metainterp/test/test_warmstate.py
@@ -18,6 +18,7 @@
 
 def test_unwrap():
     S = lltype.GcStruct('S')
+    RS = lltype.Struct('S')
     p = lltype.malloc(S)
     po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
     assert unwrap(lltype.Void, BoxInt(42)) is None
@@ -25,6 +26,7 @@
     assert unwrap(lltype.Char, BoxInt(42)) == chr(42)
     assert unwrap(lltype.Float, boxfloat(42.5)) == 42.5
     assert unwrap(lltype.Ptr(S), BoxPtr(po)) == p
+    assert unwrap(lltype.Ptr(RS), BoxInt(0)) == lltype.nullptr(RS)
 
 def test_wrap():
     def _is(box1, box2):
diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py
--- a/pypy/jit/metainterp/warmstate.py
+++ b/pypy/jit/metainterp/warmstate.py
@@ -54,7 +54,10 @@
     if TYPE is lltype.Void:
         return None
     if isinstance(TYPE, lltype.Ptr):
-        return box.getref(TYPE)
+        if TYPE.TO._gckind == "gc":
+            return box.getref(TYPE)
+        else:
+            return llmemory.cast_adr_to_ptr(box.getaddr(), TYPE)
     if isinstance(TYPE, ootype.OOType):
         return box.getref(TYPE)
     if TYPE == lltype.Float:
@@ -578,7 +581,7 @@
                 cell.set_entry_loop_token(entry_loop_token)
             return entry_loop_token
         self.get_assembler_token = get_assembler_token
-        
+
         #
         get_location_ptr = self.jitdriver_sd._get_printable_location_ptr
         if get_location_ptr is None:


More information about the pypy-commit mailing list