Author: Armin Rigo <[email protected]>
Branch: stmgc-static-barrier
Changeset: r66178:274f8205ec11
Date: 2013-08-17 11:03 +0200
http://bitbucket.org/pypy/pypy/changeset/274f8205ec11/

Log:    Add a test that actually shows that GCREFs work, even if slightly
        inefficiently --- which is probably fine.

diff --git a/rpython/translator/stm/test/test_writebarrier.py 
b/rpython/translator/stm/test/test_writebarrier.py
--- a/rpython/translator/stm/test/test_writebarrier.py
+++ b/rpython/translator/stm/test/test_writebarrier.py
@@ -1,5 +1,5 @@
 from rpython.rlib.rstm import register_invoke_around_extcall
-from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.translator.stm.test.transform_support import BaseTestTransform
 
 
@@ -324,6 +324,32 @@
         assert res == 84
         assert self.barriers == ['a2r', 'a2r', 'r2w', 'q2r']
 
+    def test_subclassing_gcref(self):
+        Y = lltype.GcStruct('Y', ('foo', lltype.Signed),
+                                 ('ybar', lltype.Signed))
+        YPTR = lltype.Ptr(Y)
+        #
+        def handle(y):
+            y.ybar += 1
+        def f1(i):
+            if i > 5:
+                y = lltype.malloc(Y); y.foo = 52 - i; y.ybar = i
+                x = lltype.cast_opaque_ptr(llmemory.GCREF, y)
+            else:
+                y = lltype.nullptr(Y)
+                x = lltype.cast_opaque_ptr(llmemory.GCREF, y)
+            external_any_gcobj()
+            prev = lltype.cast_opaque_ptr(YPTR, x).foo           # a2r
+            handle(y)                            # inside handle(): a2r, r2w
+            return prev + lltype.cast_opaque_ptr(YPTR, x).ybar   # q2r?
+
+        res = self.interpret(f1, [10])
+        assert res == 42 + 11
+        assert self.barriers == ['a2r', 'a2r', 'r2w', 'a2r']
+        # Ideally we should get [... 'q2r'] but getting 'a2r' is not wrong
+        # either.  This is because from a GCREF the only thing we can do is
+        # cast_opaque_ptr, which is not special-cased in writebarrier.py.
+
     def test_write_barrier_repeated(self):
         class X:
             pass
diff --git a/rpython/translator/stm/test/transform_support.py 
b/rpython/translator/stm/test/transform_support.py
--- a/rpython/translator/stm/test/transform_support.py
+++ b/rpython/translator/stm/test/transform_support.py
@@ -130,6 +130,14 @@
         return LLFrame.op_cast_pointer(self, RESTYPE, obj)
     op_cast_pointer.need_result_type = True
 
+    def op_cast_opaque_ptr(self, RESTYPE, obj):
+        if obj._TYPE.TO._gckind == 'gc':
+            cat = self.check_category(obj, None)
+            p = lltype.cast_opaque_ptr(RESTYPE, obj)
+            return _stmptr(p, cat)
+        return LLFrame.op_cast_opaque_ptr(self, RESTYPE, obj)
+    op_cast_opaque_ptr.need_result_type = True
+
     def op_malloc(self, obj, flags):
         assert flags['flavor'] == 'gc'
         # convert all existing pointers W -> V
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to