Author: Armin Rigo <[email protected]>
Branch: static-callback
Changeset: r2406:919e3cdd4fb6
Date: 2015-11-16 11:52 +0100
http://bitbucket.org/cffi/cffi/changeset/919e3cdd4fb6/
Log: Add a minimal demo of CFFI_CALL_PYTHON
diff --git a/demo/cdef_call_python.py b/demo/cdef_call_python.py
new file mode 100644
--- /dev/null
+++ b/demo/cdef_call_python.py
@@ -0,0 +1,29 @@
+import cffi
+
+ffi = cffi.FFI()
+
+ffi.cdef("""
+ int add(int x, int y);
+ CFFI_CALL_PYTHON long mangle(int);
+""")
+
+ffi.set_source("_cdef_call_python_cffi", """
+
+ static long mangle(int);
+
+ static int add(int x, int y)
+ {
+ return mangle(x) + mangle(y);
+ }
+""")
+
+ffi.compile()
+
+
+from _cdef_call_python_cffi import ffi, lib
+
[email protected]_python("mangle") # optional argument, default to func.__name__
+def mangle(x):
+ return x * x
+
+assert lib.add(40, 2) == 1604
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit