[pypy-commit] pypy stm-thread-2: Add a test for what occurs around cast_pointer. Currently fails.

arigo noreply at buildbot.pypy.org
Sun Sep 2 17:59:53 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r57089:d357d1a15bec
Date: 2012-09-02 17:39 +0200
http://bitbucket.org/pypy/pypy/changeset/d357d1a15bec/

Log:	Add a test for what occurs around cast_pointer. Currently fails.

diff --git a/pypy/translator/stm/test/test_transform2.py b/pypy/translator/stm/test/test_transform2.py
--- a/pypy/translator/stm/test/test_transform2.py
+++ b/pypy/translator/stm/test/test_transform2.py
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.lltypesystem import lltype, rffi, opimpl
 from pypy.rpython.llinterp import LLFrame
 from pypy.rpython.test.test_llinterp import get_interpreter, clear_tcache
 from pypy.objspace.flow.model import Constant
@@ -92,17 +92,25 @@
         return obj1 == obj2
 
     def op_getfield(self, obj, field):
-        self.check_category(obj, 'R')
+        if not obj._TYPE.TO._immutable_field(field):
+            self.check_category(obj, 'R')
         return LLFrame.op_getfield(self, obj, field)
 
     def op_setfield(self, obj, fieldname, fieldvalue):
-        self.check_category(obj, 'W')
-        # convert R -> O all other pointers to the same object we can find
-        for p in self.all_stm_ptrs():
-            if p._category == 'R' and p._T == obj._T and p == obj:
-                _stmptr._category.__set__(p, 'O')
+        if not obj._TYPE.TO._immutable_field(fieldname):
+            self.check_category(obj, 'W')
+            # convert R -> O all other pointers to the same object we can find
+            for p in self.all_stm_ptrs():
+                if p._category == 'R' and p._T == obj._T and p == obj:
+                    _stmptr._category.__set__(p, 'O')
         return LLFrame.op_setfield(self, obj, fieldname, fieldvalue)
 
+    def op_cast_pointer(self, RESTYPE, obj):
+        cat = self.check_category(obj, 'P')
+        p = opimpl.op_cast_pointer(RESTYPE, obj)
+        return _stmptr(p, cat)
+    op_cast_pointer.need_result_type = True
+
     def op_malloc(self, obj, flags):
         p = LLFrame.op_malloc(self, obj, flags)
         ptr2 = _stmptr(p, 'W')
@@ -211,10 +219,6 @@
 
     def test_call_external_random_effects(self):
         X = lltype.GcStruct('X', ('foo', lltype.Signed))
-        external_stuff = rffi.llexternal('external_stuff', [], lltype.Void,
-                                         _callable=lambda: None,
-                                         random_effects_on_gcobjs=True,
-                                         threadsafe=False)
         def f1(p):
             x1 = p.foo
             external_stuff()
@@ -320,3 +324,38 @@
         assert res == 0
         # for now we get this.  Later, we could probably optimize it
         assert self.barriers == ['P2W', 'p2w', 'p2w', 'p2w', 'p2w']
+
+    def test_subclassing(self):
+        class X:
+            __slots__ = ['foo']
+        class Y(X):
+            pass
+        class Z(X):
+            pass
+        def f1(i):
+            if i > 5:
+                x = Y()
+                x.foo = 42
+                x.ybar = i
+            else:
+                x = Z()
+                x.foo = 815
+                x.zbar = 'A'
+            external_stuff()
+            result = x.foo
+            if isinstance(x, Y):
+                result += x.ybar
+            return result
+
+        res = self.interpret(f1, [10])
+        assert res == 42 + 10
+        assert self.barriers == ['p2r']
+        res = self.interpret(f1, [-10])
+        assert res == 815
+        assert self.barriers == ['p2r']
+
+
+external_stuff = rffi.llexternal('external_stuff', [], lltype.Void,
+                                 _callable=lambda: None,
+                                 random_effects_on_gcobjs=True,
+                                 threadsafe=False)


More information about the pypy-commit mailing list