[pypy-svn] r79236 - pypy/trunk/pypy/rpython/memory/test

arigo at codespeak.net arigo at codespeak.net
Thu Nov 18 13:23:11 CET 2010


Author: arigo
Date: Thu Nov 18 13:23:09 2010
New Revision: 79236

Modified:
   pypy/trunk/pypy/rpython/memory/test/test_gc.py
Log:
A test showing why we cannot mark weakrefs as no-longer-valid
if they only point to __del__ objects going away.


Modified: pypy/trunk/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/trunk/pypy/rpython/memory/test/test_gc.py	Thu Nov 18 13:23:09 2010
@@ -352,6 +352,29 @@
         res = self.interpret(f, [])
         assert res == 11
 
+    def test_weakref_bug_1(self):
+        import weakref
+        class A(object):
+            pass
+        class B(object):
+            def __del__(self):
+                self.wref().x += 1
+        def g(a):
+            b = B()
+            b.wref = weakref.ref(a)
+            # the only way to reach this weakref is via B, which is an
+            # object with finalizer (but the weakref itself points to
+            # a, which does not go away but will move during the next
+            # gc.collect)
+        def f():
+            a = A()
+            a.x = 10
+            g(a)
+            llop.gc__collect(lltype.Void)
+            return a.x
+        res = self.interpret(f, [])
+        assert res == 11
+
     def test_id(self):
         class A(object):
             pass



More information about the Pypy-commit mailing list