I have a C file that is wrapped with swig. This C file contains an API with function pointer as an argument(shown below).
example.c
int binary_op (int a, int b, int (*op)(int,int))
{
return (*op)(a,b);
}
I can map a function to the pointer argument provided that mapping function is defined in same file using swig. But the mapping function is defined in another C file which is wrapped with Ctypes.
testing.c
int add_int(int a, int b){
return a+b;
}
In Python, I imported swig generated module and called the API with ctypes generated mapping function, it resulted error.
In testfile.py
import example # Module generated by swig
from ctypes import *
wrap_dll = CDLL('testing.dll') # testing.dll is generated with File_2.c
# Mapping function 'add_int' to argument in 'binary_op'
example.binary_op(3,4,wrap_dll.add_int)
The error shown is the type of argument is not matching.
TypeError: in method 'binary_op', argument 3 of type 'int (*)(int,int)'