[pypy-commit] cffi default: Document the workaround for taking pointers to functions.

arigo noreply at buildbot.pypy.org
Mon Oct 21 14:47:48 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1378:f37a06c4c060
Date: 2013-10-21 14:31 +0200
http://bitbucket.org/cffi/cffi/changeset/f37a06c4c060/

Log:	Document the workaround for taking pointers to functions.

diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -981,6 +981,17 @@
 
 Aside from these limitations, functions and callbacks can return structs.
 
+CPython only: for performance, ``ffi.verify()`` returns functions as
+objects of type ``<built-in function>``.  They are not ``<cdata>``, so
+you cannot e.g. pass them to some other C function expecting a function
+pointer argument.  Only ``ffi.typeof()`` works on them.  If you really
+need a pointer to the function, use the following workaround::
+  
+    ffi.cdef(""" int (*foo)(int a, int b); """)
+
+i.e. declare them as pointer-to-function in the cdef (even if they are
+regular functions in the C code).
+
 
 Variadic function calls
 -----------------------


More information about the pypy-commit mailing list