[pypy-commit] cffi default: Document the simpler form of giving a C function type.
arigo
noreply at buildbot.pypy.org
Tue Sep 18 11:14:30 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r939:beb3625be215
Date: 2012-09-18 11:12 +0200
http://bitbucket.org/cffi/cffi/changeset/beb3625be215/
Log: Document the simpler form of giving a C function type.
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -898,16 +898,20 @@
>>> def myfunc(x, y):
... return x + y
...
- >>> ffi.callback("int(*)(int, int)", myfunc)
+ >>> ffi.callback("int(int, int)", myfunc)
<cdata 'int(*)(int, int)' calling <function myfunc at 0xf757bbc4>>
.. versionadded:: 0.4
Or equivalently as a decorator:
- >>> @ffi.callback("int(*)(int, int)")
+ >>> @ffi.callback("int(int, int)")
... def myfunc(x, y):
... return x + y
+Note that you can also use a C function pointer type like ``"int(*)(int,
+int)"`` (as opposed to a C function type like ``"int(int, int)"``). It
+is equivalent here.
+
Warning: like ffi.new(), ffi.callback() returns a cdata that has
ownership of its C data. (In this case, the necessary C data contains
the libffi data structures to do a callback.) This means that the
@@ -931,7 +935,7 @@
The returned value in case of errors is 0 or null by default, but can be
specified with the ``error`` keyword argument to ``ffi.callback()``::
- >>> ffi.callback("int(*)(int, int)", myfunc, error=42)
+ >>> ffi.callback("int(int, int)", myfunc, error=42)
In all cases the exception is printed to stderr, so this should be
used only as a last-resort solution.
More information about the pypy-commit
mailing list