Hi there,
I have C code which uses a variable data
, which is a large 2d array created with malloc with variable size. Now I have to write an interface, so that the C functions can be called from within Python. I use ctypes for that.
C code:
FOO* pytrain(float **data){
FOO *foo = foo_autoTrain((float (*)[])data);
return foo;
}
with
FOO *foo_autoTrain(float data[nrows][ncols]) {...}
Python code:
autofoo=cdll.LoadLibrary("./libfoo.so")
... data gets filled ...
foo = autofoo.pytrain(pointer(pointer(p_data)))
My problem is, that when I try to access data
in foo_autoTrain I only get 0.0
or other random values and a seg fault later. So how could I pass float (*)[])data
to foo_autoTrain in Python?
Please don't hesitate to point out, if I described some part of my problem not sufficient enough.