[pypy-svn] r47335 - pypy/dist/pypy/rpython/memory/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Oct 9 12:39:23 CEST 2007


Author: cfbolz
Date: Tue Oct  9 12:39:22 2007
New Revision: 47335

Modified:
   pypy/dist/pypy/rpython/memory/test/test_gc.py
Log:
two more passing finalizer tests


Modified: pypy/dist/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_gc.py	Tue Oct  9 12:39:22 2007
@@ -125,6 +125,64 @@
         res = self.interpret(f, [5])
         assert res == 6
 
+    def test_finalizer_calls_malloc(self):
+        class B(object):
+            pass
+        b = B()
+        b.nextid = 0
+        b.num_deleted = 0
+        class A(object):
+            def __init__(self):
+                self.id = b.nextid
+                b.nextid += 1
+            def __del__(self):
+                b.num_deleted += 1
+                C()
+        class C(A):
+            def __del__(self):
+                b.num_deleted += 1
+        def f(x):
+            a = A()
+            i = 0
+            while i < x:
+                i += 1
+                a = A()
+            llop.gc__collect(lltype.Void)
+            llop.gc__collect(lltype.Void)
+            return b.num_deleted
+        res = self.interpret(f, [5])
+        assert res == 12
+
+    def test_finalizer_resurrects(self):
+        class B(object):
+            pass
+        b = B()
+        b.nextid = 0
+        b.num_deleted = 0
+        class A(object):
+            def __init__(self):
+                self.id = b.nextid
+                b.nextid += 1
+            def __del__(self):
+                b.num_deleted += 1
+                b.a = self
+        def f(x):
+            a = A()
+            i = 0
+            while i < x:
+                i += 1
+                a = A()
+            llop.gc__collect(lltype.Void)
+            llop.gc__collect(lltype.Void)
+            aid = b.a.id
+            b.a = None
+            # check that __del__ is not called again
+            llop.gc__collect(lltype.Void)
+            llop.gc__collect(lltype.Void)
+            return b.num_deleted * 10 + aid + 100 * (b.a is None)
+        res = self.interpret(f, [5])
+        assert 160 <= res <= 165
+
 
 class TestMarkSweepGC(GCTest):
     from pypy.rpython.memory.gc import MarkSweepGC as GCClass



More information about the Pypy-commit mailing list