Debian Codegraph @

doc/source/goals.rst

raw
1 Goals
2 -----
3
4 The interface is based on `LuaJIT's FFI`_, and follows a few principles:
5
6 * The goal is to call C code from Python without learning a 3rd language:
7 existing alternatives require users to learn domain specific language
8 (Cython_, SWIG_) or API (ctypes_). The CFFI design requires users to know
9 only C and Python, minimizing the extra bits of API that need to be learned.
10
11 * Keep all the Python-related logic in Python so that you don't need to
12 write much C code (unlike `CPython native C extensions`_).
13
14 * The preferred way is to work at the level of the API (Application
15 Programming Interface): the C compiler is called from the declarations
16 you write to validate and link to the C language constructs.
17 Alternatively, it is also possible to work at the ABI level
18 (Application Binary Interface), the way ctypes_ work.
19 However, on non-Windows platforms, C libraries typically
20 have a specified C API but not an ABI (e.g. they may
21 document a "struct" as having at least these fields, but maybe more).
22
23 * Try to be complete. For now some C99 constructs are not supported,
24 but all C89 should be, including macros (and including macro "abuses",
25 which you can `manually wrap`_ in saner-looking C functions).
26
27 * Attempt to support both PyPy and CPython, with a reasonable path
28 for other Python implementations like IronPython and Jython.
29
30 * Note that this project is **not** about embedding executable C code in
31 Python, unlike `Weave`_. This is about calling existing C libraries
32 from Python.
33
34 * There is no C++ support. Sometimes, it is reasonable to write a C
35 wrapper around the C++ code and then call this C API with CFFI.
36 Otherwise, look at other projects. I would recommend cppyy_, which
37 has got some similarities (and also works efficiently on both CPython
38 and PyPy).
39
40 .. _`LuaJIT's FFI`: http://luajit.org/ext_ffi.html
41 .. _`Cython`: http://www.cython.org
42 .. _`SWIG`: http://www.swig.org/
43 .. _`CPython native C extensions`: http://docs.python.org/extending/extending.html
44 .. _`native C extensions`: http://docs.python.org/extending/extending.html
45 .. _`ctypes`: http://docs.python.org/library/ctypes.html
46 .. _`Weave`: http://wiki.scipy.org/Weave
47 .. _`cppyy`: http://cppyy.readthedocs.io/en/latest/
48 .. _`manually wrap`: overview.html#abi-versus-api
49
50 Get started by reading `the overview`__.
51
52 .. __: overview.html
53
54
55 Comments and bugs
56 -----------------
57
58 The best way to contact us is on the IRC ``#cffi`` or ``#pypy`` channels of
59 ``irc.libera.chat``. Feel free to discuss matters either there or in
60 the `mailing list`_. Please report to the `issue tracker`_ any bugs.
61
62 As a general rule, when there is a design issue to resolve, we pick the
63 solution that is the "most C-like". We hope that this module has got
64 everything you need to access C code and nothing more.
65
66 --- the authors, Armin Rigo and Maciej Fijalkowski
67
68 .. _`issue tracker`: https://github.com/python-cffi/cffi/issues
69 .. _`mailing list`: https://groups.google.com/forum/#!forum/python-cffi