This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit f06e56ff authored by Armin Rigo's avatar Armin Rigo
Browse files

Add another example showing the API level with verify().

parent df89dccc974a
Foreign Function Interface for Python calling C code. The aim of this project
......@@ -31,8 +31,8 @@ follows a few principles:
but all C89 should be, including macros (apart from the most advanced
(ab)uses of these macros).
Simple example
Simple example (ABI level)
>>> from cffi import FFI
>>> ffi = FFI()
......@@ -45,6 +45,29 @@ Simple example
hi there, world!
Simple example (API level)
from cffi import FFI
ffi = FFI()
ffi.cdef(""" // some declarations from the man page
struct passwd {
char *pw_name;
struct passwd *getpwuid(int uid);
C = ffi.verify(""" // passed to the real C compiler
#include <sys/types.h>
#include <pwd.h>
assert str(C.getpwuid(0).pw_name) == 'root'
Note that the above example works independently of the exact layout of
"struct passwd", but so far require a C compiler at runtime. (This will
be improved with caching and distribution of the compiled code.)
More documentation
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment