Author: Armin Rigo <[email protected]>
Branch: cpyext-gc-support
Changeset: r80289:0e4355b1faf4
Date: 2015-10-16 19:51 +0200
http://bitbucket.org/pypy/pypy/changeset/0e4355b1faf4/
Log: Adapt the 3rd test
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -2774,6 +2774,13 @@
self.rrc_singleaddr = llmemory.cast_ptr_to_adr(p)
self.rrc_enabled = True
+ def check_no_more_rawrefcount_state(self):
+ "NOT_RPYTHON: for tests"
+ assert self.rrc_p_list_young.length() == 0
+ assert self.rrc_p_list_old .length() == 0
+ assert self.rrc_o_list_young.length() == 0
+ assert self.rrc_o_list_old .length() == 0
+
def rawrefcount_create_link_pypy(self, gcobj, pyobject):
ll_assert(self.rrc_enabled, "rawrefcount.init not called")
obj = llmemory.cast_ptr_to_adr(gcobj)
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
@@ -69,7 +69,7 @@
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)
- assert r1.ob_refcnt == REFCNT_FROM_PYPY_DIRECT
+ check_alive(0)
r1.ob_refcnt += 1
self.gc.minor_collection()
check_alive(+1)
@@ -80,42 +80,25 @@
check_alive(0)
self.gc.collect()
py.test.raises(RuntimeError, "r1.ob_refcnt") # dead
+ self.gc.check_no_more_rawrefcount_state()
def test_rawrefcount_objects_collection_survives_from_obj(self):
- for do_collect in [self.gc.minor_collection, self.gc.collect] * 2:
- p1, p1ref, r1, r1addr = self._rawrefcount_pair(42)
- assert r1.ob_refcnt == REFCNT_FROM_PYPY_OBJECT
- self.stackroots.append(p1)
- do_collect()
- assert r1.ob_refcnt == REFCNT_FROM_PYPY_OBJECT
- assert r1.ob_pypy_link != llmemory.NULL
+ 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
-
- def test_rawrefcount_objects_collection_dies(self):
- p1, p1ref, r1, r1addr = self._rawrefcount_pair(43)
- seen = []
- self.gc.rawrefcount_set_callback(seen.append)
+ p1, p1ref, r1, r1addr = self._rawrefcount_pair(42, is_direct=True)
+ check_alive(0)
+ self.stackroots.append(p1)
self.gc.minor_collection()
- assert r1.ob_refcnt == REFCNT_FROM_PYPY_OBJECT
- assert r1.ob_pypy_link != llmemory.NULL
- p1ref = self.gc.rawrefcount_to_obj(r1addr)
- assert seen == [p1ref]
- assert lltype.cast_opaque_ptr(lltype.Ptr(S), p1ref).x == 43
- assert self.gc.rawrefcount_from_obj(p1ref) == r1addr
- #
- del seen[:]
+ check_alive(0)
+ self.gc.collect()
+ check_alive(0)
+ self.stackroots.pop()
self.gc.minor_collection()
- assert seen == []
+ check_alive(0)
self.gc.collect()
- assert seen == [p1ref]
- assert r1.ob_pypy_link == llmemory.cast_ptr_to_adr(p1ref)
-
- def test_rawrefcount_objects_detach(self):
- p1, p1ref, r1, r1addr = self._rawrefcount_pair(43)
- self.gc.rawrefcount_detach(r1addr)
- assert r1.ob_pypy_link == llmemory.NULL
- assert self.gc.rawrefcount_from_obj(p1ref) == llmemory.NULL
- assert self.gc.rawrefcount_to_obj(r1addr) == lltype.nullptr(
- llmemory.GCREF.TO)
+ py.test.raises(RuntimeError, "r1.ob_refcnt") # dead
+ self.gc.check_no_more_rawrefcount_state()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit