Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: 
Changeset: r48473:990f8f82e063
Date: 2011-10-26 16:31 +0200
http://bitbucket.org/pypy/pypy/changeset/990f8f82e063/

Log:    yet another case of tagged pointer handling in the C backend.

diff --git a/pypy/translator/c/primitive.py b/pypy/translator/c/primitive.py
--- a/pypy/translator/c/primitive.py
+++ b/pypy/translator/c/primitive.py
@@ -144,14 +144,19 @@
         obj = value._obj
         if isinstance(obj, int):
             # a tagged pointer
-            assert obj & 1 == 1
-            return '((%s) %d)' % (cdecl("void*", ''), obj)
+            return _name_tagged(obj, db)
         realobj = obj.container
+        if isinstance(realobj, int):
+            return _name_tagged(realobj, db)
         realvalue = cast_opaque_ptr(Ptr(typeOf(realobj)), value)
         return db.get(realvalue)
     else:
         return 'NULL'
 
+def _name_tagged(obj, db):
+    assert obj & 1 == 1
+    return '((%s) %d)' % (cdecl("void*", ''), obj)
+
 def name_small_integer(value, db):
     """Works for integers of size at most INT or UINT."""
     if isinstance(value, Symbolic):
diff --git a/pypy/translator/c/test/test_rtagged.py 
b/pypy/translator/c/test/test_rtagged.py
--- a/pypy/translator/c/test/test_rtagged.py
+++ b/pypy/translator/c/test/test_rtagged.py
@@ -77,3 +77,12 @@
     data = g.read()
     g.close()
     assert data.rstrip().endswith('ALL OK')
+
+def test_name_gcref():
+    from pypy.rpython.lltypesystem import lltype, llmemory, rclass
+    from pypy.translator.c import primitive
+    from pypy.translator.c.database import LowLevelDatabase
+    x = lltype.cast_int_to_ptr(rclass.OBJECTPTR, 19)
+    y = lltype.cast_opaque_ptr(llmemory.GCREF, x)
+    db = LowLevelDatabase()
+    assert primitive.name_gcref(y, db) == "((void*) 19)"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to