From cb999cd1b28d01a81f994ce4798acec7a4086d4a Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Mon, 30 Nov 2015 16:45:46 +0100 Subject: "embedding" mode, where we produce a .so with the given C API usable from a non-Python-aware program --- demo/embedding.py | 19 +++++++++++++++++++ demo/embedding_test.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 demo/embedding.py create mode 100644 demo/embedding_test.c (limited to 'demo') diff --git a/demo/embedding.py b/demo/embedding.py new file mode 100644 index 0000000..4e3d71c --- /dev/null +++ b/demo/embedding.py @@ -0,0 +1,19 @@ +import cffi + +ffi = cffi.FFI() + +ffi.export_cdef(""" + extern "Python" int add(int, int); +""", """ + from _embedding_cffi import ffi, lib + + @ffi.def_extern() + def add(x, y): + print "adding", x, "and", y + return x + y +""") + +ffi.set_source("libembedding_test", """ +""") + +ffi.compile() diff --git a/demo/embedding_test.c b/demo/embedding_test.c new file mode 100644 index 0000000..39c6e26 --- /dev/null +++ b/demo/embedding_test.c @@ -0,0 +1,17 @@ +/* Link this program with libembedding_test.so. + E.g. with gcc: + + gcc -o embedding_test embedding_test.c -L. -lembedding_test +*/ + +#include + +extern int add(int x, int y); + + +int main(void) +{ + int res = add(40, 2); + printf("result: %d\n", res); + return 0; +} -- cgit v1.2.1