Author: Armin Rigo <[email protected]>
Branch: cpyext-gc-support
Changeset: r80290:b67cad237592
Date: 2015-10-16 19:57 +0200
http://bitbucket.org/pypy/pypy/changeset/b67cad237592/

Log:    Tweak the tests

diff --git a/rpython/memory/gc/test/test_rawrefcount.py 
b/rpython/memory/gc/test/test_rawrefcount.py
--- a/rpython/memory/gc/test/test_rawrefcount.py
+++ b/rpython/memory/gc/test/test_rawrefcount.py
@@ -39,10 +39,20 @@
             self.gc.rawrefcount_create_link_pypy(p1ref, r1addr)
         assert r1.ob_refcnt == rc
         assert r1.ob_pypy_link != 0
-        return p1, p1ref, r1, r1addr
+
+        def check_alive(extra_refcount):
+            assert r1.ob_refcnt == rc + extra_refcount
+            assert r1.ob_pypy_link != 0
+            p1ref = self.gc.rawrefcount_to_obj(r1addr)
+            p1 = lltype.cast_opaque_ptr(lltype.Ptr(S), p1ref)
+            assert p1.x == 42
+            assert self.gc.rawrefcount_from_obj(p1ref) == r1addr
+            return p1
+        return p1, p1ref, r1, r1addr, check_alive
 
     def test_rawrefcount_objects_basic(self):
-        p1, p1ref, r1, r1addr = self._rawrefcount_pair(42, is_direct=True)
+        p1, p1ref, r1, r1addr, check_alive = (
+            self._rawrefcount_pair(42, is_direct=True))
         p2 = self.malloc(S)
         p2.x = 84
         p2ref = lltype.cast_opaque_ptr(llmemory.GCREF, p2)
@@ -62,13 +72,8 @@
         lltype.free(r2, flavor='raw')
 
     def test_rawrefcount_objects_collection_survives_from_raw(self):
-        def check_alive(extra_refcount):
-            assert r1.ob_refcnt == REFCNT_FROM_PYPY_DIRECT + extra_refcount
-            assert r1.ob_pypy_link != 0
-            p1ref = self.gc.rawrefcount_to_obj(r1addr)
-            assert lltype.cast_opaque_ptr(lltype.Ptr(S), p1ref).x == 42
-            assert self.gc.rawrefcount_from_obj(p1ref) == r1addr
-        p1, p1ref, r1, r1addr = self._rawrefcount_pair(42, is_direct=True)
+        p1, p1ref, r1, r1addr, check_alive = (
+            self._rawrefcount_pair(42, is_direct=True))
         check_alive(0)
         r1.ob_refcnt += 1
         self.gc.minor_collection()
@@ -77,28 +82,26 @@
         check_alive(+1)
         r1.ob_refcnt -= 1
         self.gc.minor_collection()
-        check_alive(0)
+        p1 = check_alive(0)
         self.gc.collect()
         py.test.raises(RuntimeError, "r1.ob_refcnt")    # dead
+        py.test.raises(RuntimeError, "p1.x")            # dead
         self.gc.check_no_more_rawrefcount_state()
 
     def test_rawrefcount_objects_collection_survives_from_obj(self):
-        def check_alive(extra_refcount):
-            assert r1.ob_refcnt == REFCNT_FROM_PYPY_DIRECT + extra_refcount
-            assert r1.ob_pypy_link != 0
-            p1ref = self.gc.rawrefcount_to_obj(r1addr)
-            assert lltype.cast_opaque_ptr(lltype.Ptr(S), p1ref).x == 42
-            assert self.gc.rawrefcount_from_obj(p1ref) == r1addr
-        p1, p1ref, r1, r1addr = self._rawrefcount_pair(42, is_direct=True)
+        p1, p1ref, r1, r1addr, check_alive = (
+            self._rawrefcount_pair(42, is_direct=True))
         check_alive(0)
         self.stackroots.append(p1)
         self.gc.minor_collection()
         check_alive(0)
         self.gc.collect()
         check_alive(0)
-        self.stackroots.pop()
+        p1 = self.stackroots.pop()
         self.gc.minor_collection()
         check_alive(0)
+        assert p1.x == 42
         self.gc.collect()
         py.test.raises(RuntimeError, "r1.ob_refcnt")    # dead
+        py.test.raises(RuntimeError, "p1.x")            # dead
         self.gc.check_no_more_rawrefcount_state()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to