[pypy-svn] r64102 - pypy/trunk/pypy/translator/stackless/test
arigo at codespeak.net
arigo at codespeak.net
Wed Apr 15 17:33:47 CEST 2009
Author: arigo
Date: Wed Apr 15 17:33:47 2009
New Revision: 64102
Added:
pypy/trunk/pypy/translator/stackless/test/test_callback.py (contents, props changed)
Log:
(niko, arigo)
Goes with the previous checkin.
Added: pypy/trunk/pypy/translator/stackless/test/test_callback.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/translator/stackless/test/test_callback.py Wed Apr 15 17:33:47 2009
@@ -0,0 +1,30 @@
+import py
+from pypy.rlib import rstack
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.translator.stackless.test.test_transform import \
+ run_stackless_function
+
+eci = ExternalCompilationInfo(
+ separate_module_sources = ["""
+ int f1(int (*callback)(int))
+ {
+ return callback(25) + 1;
+ }
+ """])
+
+CALLBACK = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
+f1 = rffi.llexternal("f1", [CALLBACK], lltype.Signed, compilation_info=eci)
+
+def my_callback(n):
+ try:
+ rstack.stack_unwind()
+ except RuntimeError:
+ return -20
+ return n * 10
+
+def test_my_callback():
+ def fn():
+ return f1(my_callback)
+ res = run_stackless_function(fn)
+ assert res == -19
More information about the Pypy-commit
mailing list