I need to pass a pointer from Python to a C function. I'm currently trying with SWIG but I'm ready to switch to anything that will solve my issue :)
To simplify my problem, I wrote this empty C function in SWIG:
extern void myvoidp(void *p);
I've setup my .i and .c files, all compile fine and work in Python.
I'd like to pass a Numpy array. I can get the memory address of the Numpy data like this
>>> anp = array([1,2,3])
array([1, 2, 3])
>>> anp.ctypes.data
40546992
I can cast it to a void * like this with ctypes and numpy:
>>> anp.ctypes.data_as(ctypes.c_void_p)
c_void_p(40546992)
I've tried endless variants. Whatever I do, when I invoke my C function I get this error.
>>> myswig.myvoidp(anp.ctypes.data_as(ctypes.c_void_p))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: in method 'myvoidp', argument 1 of type 'void *'
I can't figure out how to write a Python / numpy statement that allows me to (simply) pass a pointer to my C function. :-(