[pypy-commit] cffi default: A test: how you should(?) write a function pointer that you want
arigo
noreply at buildbot.pypy.org
Sun Jul 8 10:36:14 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r595:a237412122bd
Date: 2012-07-08 10:35 +0200
http://bitbucket.org/cffi/cffi/changeset/a237412122bd/
Log: A test: how you should(?) write a function pointer that you want to
cast around
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -596,3 +596,16 @@
assert repr(s) == "<cdata 'struct foo_s' owning 8 bytes>"
assert s.aa == 36
assert s.bb == 49
+
+def test_func_as_funcptr():
+ ffi = FFI()
+ ffi.cdef("int *(*const fooptr)(void);")
+ lib = ffi.verify("""
+ int *foo(void) {
+ return (int*)"foobar";
+ }
+ int *(*fooptr)(void) = foo;
+ """)
+ foochar = ffi.cast("char *(*)(void)", lib.fooptr)
+ s = foochar()
+ assert str(s) == "foobar"
More information about the pypy-commit
mailing list