I'm currently learning about interfacing Python and C code (e.g. in this case with cffi). I understood that "out-of-line mode" means that the C-code was compiled to a shared object at install time and in-line mode means that it is done at import time.
I struggle with how to recognize ABI vs API mode in cffi. Is the following MVCE an example for ABI or API?
MVCE
libfib.cpp
int fib(int n) {
int a = 0, b = 1, i, tmp;
if (n <= 1) {
return n;
}
for (int i = 0; i < n - 1; i++) {
tmp = a + b;
a = b;
b = tmp;
}
return b;
}
extern "C" {
extern int cffi_fib(int n) {
return fib(n);
}
}
Compile with g++ -o ./libfib.so ./libfib.cpp -fPIC -shared
import cffi
ffi = cffi.FFI()
ffi.cdef("int cffi_fib(int n);")
C = ffi.dlopen("./libfib.so")
for i in range(10):
print(f"{i}: {C.cffi_fib(i)}")