[pypy-svn] r51435 - pypy/dist/pypy/translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 13 14:00:55 CET 2008


Author: arigo
Date: Wed Feb 13 14:00:53 2008
New Revision: 51435

Modified:
   pypy/dist/pypy/translator/c/test/test_boehm.py
Log:
A test for r51431.  Before that revision, this test causes a C stack
overflow on my Linux laptop.


Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Wed Feb 13 14:00:53 2008
@@ -332,4 +332,36 @@
         c_fn = self.getcompiled(fn, [int])
         c_fn(100)
 
+    def test_nested_finalizers(self):
+        from pypy.rlib import rgc
+        class State:
+            pass
+        state = State()
+        def g():
+            n = state.counter
+            if n > 0:
+                for i in range(5):
+                    state.a = A(n)
+                state.a = None
+            rgc.collect()
+            return n
 
+        fun = g
+        for i in range(200):
+            def fun(next=fun):
+                return next() + 1     # prevents tail-call optimization
+
+        class A:
+            def __init__(self, level):
+                self.level = level
+            def __del__(self):
+                if state.counter == self.level:
+                    state.counter -= 1
+                    fun()
+        def fn(n):
+            state.counter = n
+            fun()
+            return state.counter
+        c_fn = self.getcompiled(fn, [int])
+        res = c_fn(10000)
+        assert res == 0



More information about the Pypy-commit mailing list