[pypy-commit] cffi default: Add errno on the ffi objects, and document it.

arigo noreply at buildbot.pypy.org
Thu Jun 14 23:29:14 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r359:d79455da114a
Date: 2012-06-14 23:29 +0200
http://bitbucket.org/cffi/cffi/changeset/d79455da114a/

Log:	Add errno on the ffi objects, and document it.

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -196,6 +196,13 @@
         from .verifier import Verifier
         return Verifier(self).verify(source, **kwargs)
 
+    def _get_errno(self):
+        return self._backend.get_errno()
+    def _set_errno(self, errno):
+        self._backend.set_errno(errno)
+    errno = property(_get_errno, _set_errno, None,
+                     "the value of 'errno' from/to the C calls")
+
 def _make_ffi_library(ffi, libname):
     name = libname
     if name is None:
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -465,10 +465,21 @@
 
 Note that callbacks of a variadic function type are not supported.
 
+Be careful when writing the Python callback function: if it returns an
+object of the wrong type, or more generally raises an exception, then
+the exception cannot be propagated.  Instead, it is printed to stderr
+and the C-level callback is made to return, randomly, a null value.
+
 
 Miscellaneous
 -------------
 
+``errno``: the value of ``errno`` received from the most recent C call
+in this thread, and passed to the following C call, is available via
+``ffi.dlopen(None).errno`` as a global variable of the C standard
+library.  It can also be accessed more directly via reads and writes of
+``ffi.errno``.
+
 ``ffi.string(pointer, length)``: return a Python string containing all
 the data at the given location with the given size.  The pointer must be
 a cdata of type ``void *`` or ``char *``.  Null characters are not


More information about the pypy-commit mailing list