First of all, I don’t understand why you want to return the C function pointer from the Python extension only to call it from Python (via ctypes), while the logical task would be to call the C function through the Python extension (if I am missing something )
-, , ctypes PyCObject. CFUNCTYPE (None, c_int) [ c_void None] PyCObject, CFUNCTYPE , PyCObject.
Python my_cfunc, Python ctypes? :
PyObject *call_fptr(PyObject *self, PyObject *args)
{
int arg;
if (!PyArg_ParseTuple(args, "i", &arg))
return NULL;
my_cfunc(arg);
Py_RETURN_NONE;
}
, ctypes - , Python my_func ctypes ( PyCObject)!
from ctypes import *
import foo
SOMEFUNC_T = CFUNCTYPE(None, c_int)
cfunc = SOMEFUNC_T(foo.call_fptr)
cfunc(1)
Edit:
, C , ... C ctypes, , CFUNCTYPE ?
Python C, , , , . SWIG , , , : , .
, , libffi.
, , , SWIG .