I have some cffi definitions spread over a few project sub-directories -- each cffi file defines types and functions, each compiles into a _<package>.py
file to be loaded. In the final application I ffi.include()
the top level ones (which recursively ffi.include()
the lower level ones) and generate an compile an _<app>.py
file to be loaded in the application. I use a single ffi
instance for loading the *.so
files. I cannot see however how this loads the spread _<package>.py
files into the application. I get the following error (example):
two separate FFI definition files,
root/get/ffi_getA.py
androot/use/ffi_useA.py
which C functions are both part of the same library, say libA.so
.
ffi_getA.py
:
from cffi import FFI
ffi=FFI()
ffi.set_source("getA",None)
ffi.cdef('''
typedef ... A; // type also used in another ffi definition.
const A* get_A();
''')
ffi_useA.py
:
from cffi import FFI
ffi=FFI()
ffi.set_source("useA",None)
from root.get import ffi_getA
ffi.include(ffi_getA.ffi) # makes available type A
ffi.cdef('''
const void* use_A(const A*); // use type A
''')
In an application:
from root.get import getA # compiled ffi
from root.use import useA # compiled ffi
libAget = getA.ffi.dlopen("libA.so")
libAuse = useA.ffi.dlopen("libA.so")
a = libAget.getA()
libAuse.useA(a) # !!! mixing !!!, a is indeed of type A ...
# ... but from a different ffi instance.
This mixing is not going to work, so the question is:
How to access/load cdef functions spread over various compiled ffi objects through a common/single ffi object?