File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1
1
Interfacing with C/C++ Libraries
2
2
================================
3
3
4
+ C Foreign Function Interface
5
+ ----------------------------
6
+
7
+ `CFFI <https://cffi.readthedocs.org/en/latest/ >`_ provides a simple to use
8
+ mechanism for interfacing with C from both CPython and PyPy. It supports two
9
+ modes: an inline ABI compatibility mode (example provided below), which allows
10
+ you to dynamically load and run functions from executable modules (essentially
11
+ exposing the same functionality as LoadLibrary or dlopen), and an API mode,
12
+ which allows you to build C extension modules.
13
+
14
+ ABI Interaction
15
+ ~~~~~~~~~~~~~~~
16
+
17
+ .. code-block :: python
18
+ :linenos:
19
+
20
+ from cffi import FFI
21
+ ffi = FFI()
22
+ ffi.cdef(" size_t strlen(const char*);" )
23
+ clib = ffi.dlopen(None )
24
+ length = clib.strlen(" String to be evaluated." )
25
+ # prints: 23
26
+ print (" {} " .format(length))
4
27
5
28
ctypes
6
29
------
You can’t perform that action at this time.
0 commit comments