Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r805:6c95615ccb9a Date: 2012-08-12 10:54 +0200 http://bitbucket.org/cffi/cffi/changeset/6c95615ccb9a/
Log: Add two tests, one passing and one (probably definitely) skipped. diff --git a/testing/test_function.py b/testing/test_function.py --- a/testing/test_function.py +++ b/testing/test_function.py @@ -268,3 +268,14 @@ ina = ffi.new("struct in_addr *", [0x04040404]) a = ffi.C.inet_ntoa(ina[0]) assert ffi.string(a) == '4.4.4.4' + + def test_function_typedef(self): + py.test.skip("using really obscure C syntax") + ffi = FFI(backend=self.Backend()) + ffi.cdef(""" + typedef double func_t(double); + func_t sin; + """) + m = ffi.dlopen("m") + x = m.sin(1.23) + assert x == math.sin(1.23) diff --git a/testing/test_verify.py b/testing/test_verify.py --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -514,6 +514,24 @@ lib.cb = my_callback assert lib.foo(4) == 887 +def test_access_callback_function_typedef(): + ffi = FFI() + ffi.cdef("typedef int mycallback_t(int);\n" + "mycallback_t *cb;\n" + "int foo(int);\n" + "void reset_cb(void);") + lib = ffi.verify(""" + static int g(int x) { return x * 7; } + static int (*cb)(int); + static int foo(int i) { return cb(i) - 1; } + static void reset_cb(void) { cb = g; } + """) + lib.reset_cb() + assert lib.foo(6) == 41 + my_callback = ffi.callback("int(*)(int)", lambda n: n * 222) + lib.cb = my_callback + assert lib.foo(4) == 887 + def test_ctypes_backend_forces_generic_engine(): from cffi.backend_ctypes import CTypesBackend ffi = FFI(backend=CTypesBackend()) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit