[pypy-svn] r25294 - pypy/branch/explicit-exceptions/translator/c/test

mwh at codespeak.net mwh at codespeak.net
Tue Apr 4 15:57:40 CEST 2006


Author: mwh
Date: Tue Apr  4 15:57:40 2006
New Revision: 25294

Modified:
   pypy/branch/explicit-exceptions/translator/c/test/test_exceptiontransform.py
Log:
(mwh, hpk)
a test that shows the problems of not inserting keepalives during the exception
transform.  needs a debug build of python.


Modified: pypy/branch/explicit-exceptions/translator/c/test/test_exceptiontransform.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/test/test_exceptiontransform.py	(original)
+++ pypy/branch/explicit-exceptions/translator/c/test/test_exceptiontransform.py	Tue Apr  4 15:57:40 2006
@@ -6,6 +6,11 @@
 from pypy.rpython.test.test_llinterp import get_interpreter
 from pypy.translator.tool.cbuild import skip_missing_compiler
 from pypy import conftest
+import sys
+
+def check_debug_build():
+    if not hasattr(sys, 'gettotalrefcount'):
+        py.test.skip("test needs a debug build of Python")
 
 def transform_func(fn, inputtypes):
     t = TranslationContext()
@@ -149,3 +154,22 @@
     f(0)
     py.test.raises(ValueError, f, 1)
 
+def test_needs_keepalive():
+    check_debug_build()
+    from pypy.rpython.lltypesystem import lltype
+    X = lltype.GcStruct("X",
+                        ('y', lltype.Struct("Y", ('z', lltype.Signed))))
+    def can_raise(n):
+        if n:
+            raise Exception
+        else:
+            return 1
+    def foo(n):
+        x = lltype.malloc(X)
+        y = x.y
+        y.z = 42
+        r = can_raise(n)
+        return r + y.z
+    f = compile_func(foo, [int])
+    res = f(0)
+    assert res == 43



More information about the Pypy-commit mailing list