Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84496:27fa17a7e80b
Date: 2016-05-16 23:03 +0200
http://bitbucket.org/pypy/pypy/changeset/27fa17a7e80b/
Log: Fix the debug logic here (I think), it used to crash cpyext tests
intermittently.
diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py
--- a/rpython/rlib/rawrefcount.py
+++ b/rpython/rlib/rawrefcount.py
@@ -27,13 +27,13 @@
"""NOT_RPYTHON: set up rawrefcount with the GC. This is only used
for tests; it should not be called at all during translation.
"""
- global _p_list, _o_list, _adr2pypy, _pypy2ob, _ob_set
+ global _p_list, _o_list, _adr2pypy, _pypy2ob, _pypy2ob_rev
global _d_list, _dealloc_trigger_callback
_p_list = []
_o_list = []
_adr2pypy = [None]
_pypy2ob = {}
- _ob_set = set()
+ _pypy2ob_rev = {}
_d_list = []
_dealloc_trigger_callback = dealloc_trigger_callback
@@ -41,23 +41,22 @@
"NOT_RPYTHON: a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
- assert ob._obj not in _ob_set
+ assert ob._obj not in _pypy2ob_rev
assert not ob.c_ob_pypy_link
ob.c_ob_pypy_link = _build_pypy_link(p)
_pypy2ob[p] = ob
+ _pypy2ob_rev[ob._obj] = p
_p_list.append(ob)
- _ob_set.add(ob._obj)
def create_link_pyobj(p, ob):
"""NOT_RPYTHON: a link where the PyObject contains all the data.
from_obj() will not work on this 'p'."""
#print 'create_link_pyobj\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
- assert ob._obj not in _ob_set
+ assert ob._obj not in _pypy2ob_rev
assert not ob.c_ob_pypy_link
ob.c_ob_pypy_link = _build_pypy_link(p)
_o_list.append(ob)
- _ob_set.add(ob._obj)
def from_obj(OB_PTR_TYPE, p):
"NOT_RPYTHON"
@@ -65,7 +64,7 @@
if ob is None:
return lltype.nullptr(OB_PTR_TYPE.TO)
assert lltype.typeOf(ob) == OB_PTR_TYPE
- assert ob
+ assert _pypy2ob_rev[ob._obj] is p
return ob
def to_obj(Class, ob):
@@ -112,8 +111,10 @@
new_p_list.append(ob)
else:
p = detach(ob, wr_p_list)
- del _pypy2ob[p]
- del p
+ ob_test = _pypy2ob.pop(p)
+ p_test = _pypy2ob_rev.pop(ob_test._obj)
+ assert p_test is p
+ del p, p_test
ob = None
_p_list = Ellipsis
@@ -157,6 +158,10 @@
p = attach(ob, wr, _p_list)
if p is not None:
_pypy2ob[p] = ob
+ _pypy2ob_rev.clear() # rebuild this dict from scratch
+ for p, ob in _pypy2ob.items():
+ assert ob._obj not in _pypy2ob_rev
+ _pypy2ob_rev[ob._obj] = p
_o_list = []
for ob, wr in wr_o_list:
attach(ob, wr, _o_list)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit