[pypy-svn] r12157 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Tue May 10 16:02:03 CEST 2005
Author: pedronis
Date: Tue May 10 16:02:03 2005
New Revision: 12157
Modified:
pypy/dist/pypy/rpython/lltypes.py
pypy/dist/pypy/rpython/test/test_lltypes.py
Log:
added simple tests for best-effort gc detection for parents, fixed bug discovered by them
Modified: pypy/dist/pypy/rpython/lltypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypes.py (original)
+++ pypy/dist/pypy/rpython/lltypes.py Tue May 10 16:02:03 2005
@@ -299,7 +299,7 @@
if isinstance(typ, Struct):
value = _struct(typ, parent=self)
elif fld == TYPE._arrayfld:
- value = _array(typ, n)
+ value = _array(typ, n, parent=self)
else:
value = typ._defl()
setattr(self, fld, value)
Modified: pypy/dist/pypy/rpython/test/test_lltypes.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_lltypes.py (original)
+++ pypy/dist/pypy/rpython/test/test_lltypes.py Tue May 10 16:02:03 2005
@@ -158,3 +158,18 @@
assert p3 == p1
py.test.raises(TypeError, "cast_parent(GcPtr(S1), p1.sub2)")
py.test.raises(TypeError, "cast_parent(_TmpPtr(S1), p1.sub2)")
+
+def test_best_effort_gced_parent_detection():
+ S2 = Struct("s2", ('a', Signed))
+ S1 = Struct("s1", ('sub1', S2), ('sub2', S2), ('tail', Array(('e', Signed))))
+ p1 = malloc(S1, 1)
+ p2 = p1.sub2
+ assert p2.a == 0
+ p3 = p1.tail
+ p3[0].e = 1
+ assert p3[0].e == 1
+ del p1
+ import gc
+ gc.collect()
+ py.test.raises(RuntimeError, "p2.a")
+ py.test.raises(RuntimeError, "p3[0]")
More information about the Pypy-commit
mailing list