Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r376:c1ff6d753e22 Date: 2012-06-15 20:47 +0200 http://bitbucket.org/cffi/cffi/changeset/c1ff6d753e22/
Log: A test with a global callback that we set from a Python function. Mildly impressive: it works out of the box. diff --git a/testing/test_verify.py b/testing/test_verify.py --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -415,3 +415,17 @@ lib.stuff.x = -6 assert lib.foo(0) == -42 assert lib.foo(1) == 35 + +def test_access_callback(): + ffi = FFI() + ffi.cdef("int (*cb)(int);\n" + "int foo(int);") + lib = ffi.verify(""" + static int g(int x) { return x * 7; } + static int (*cb)(int) = g; + static int foo(int i) { return cb(i) - 1; } + """) + assert lib.foo(6) == 41 + my_callback = ffi.callback("int(*)(int)", lambda n: n * 222) + lib.cb = my_callback + assert lib.foo(4) == 887 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit