blob: 24f420f6f0fa2b55aa4756d62e9ec76238ec1262 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
@ffi.call_python("mangle") # optional argument, default to func.__name__
def mangle(x):
return x * x
assert lib.add(40, 2) == 1604
|