I'm trying to call c functions from python, I have the following code in c.
struct _returndata
{
double* data;
int row;
int col;
};
int mlfAddmatrixW(struct _returndata* retArr)
{
double data[] = {1,2,3,4,5,6,7,8,9}
retArr->row = 3;
retArr->col = 3;
memcpy(retArr->data, data, 9*sizeof(double));
return 1;
}
This is my code in python:
class RETARRAY(Structure):
_fields_= [("data", c_double*9),
("row", c_int),
("col", c_int)]
if __name__ == '__main__':
dll = CDLL("/home/robu/Documents/tmo_compile/libmatrix/distrib/libmatrixwrapper.so")
#Initializing the matrix
retArr = pointer(RETARRAY())
for i in retArr.contents.data:
print i;
dll.mlfAddmatrixW(pointer(retArr))
for i in retArr.contents.data:
print i;
print retArr.contents.row
print retArr.contents.col
The content of the data has changed, but the col and row is still 0. How can I fix that?
Is it possible to create a dynamic array in python , because in this case I created an array with 9 elements ("data", c_double*9),
. I know the size of the array after I called mlfAddmatrixW
function, the size of the array will be col*row
.