From fc092a1a98bec97de52ba671aa177069a513fa38 Mon Sep 17 00:00:00 2001 From: aaron Date: Sun, 1 Nov 2015 11:40:05 -0600 Subject: [PATCH] Added CFFI section --- docs/scenarios/clibs.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/scenarios/clibs.rst b/docs/scenarios/clibs.rst index 3f92627..c4d4110 100644 --- a/docs/scenarios/clibs.rst +++ b/docs/scenarios/clibs.rst @@ -1,6 +1,29 @@ Interfacing with C/C++ Libraries ================================ +C Foreign Function Interface +---------------------------- + +`CFFI `_ provides a simple to use +mechanism for interfacing with C from both CPython and PyPy. It supports two +modes: an inline ABI compatibility mode (example provided below), which allows +you to dynamically load and run functions from executable modules (essentially +exposing the same functionality as LoadLibrary or dlopen), and an API mode, +which allows you to build C extension modules. + +ABI Interaction +~~~~~~~~~~~~~~~ + +.. code-block:: python + :linenos: + + from cffi import FFI + ffi = FFI() + ffi.cdef("size_t strlen(const char*);") + clib = ffi.dlopen(None) + length = clib.strlen("String to be evaluated.") + # prints: 23 + print("{}".format(length)) ctypes ------