I have a function that accepts a double array as first parameter
cb_type = CFUNCTYPE(c_void_p, c_double * 2, c_int, c_int)
def mycb(cube, ndim, nparams):
print "cube before", [v for v in cube]
for i in range(ndim):
cube[i] = cube[i] * 10 * math.pi
print "cube after", [v for v in cube]
I hand it over to C via the usual cb_type(mycb).
C calls it:
printf("values before: %f, %f\n", Cube[0], Cube[1]);
cb(Cube, *ndim, *npars);
printf("values after : %f, %f\n", Cube[0], Cube[1]);
When I run the program, there is some packing/unpacking or decoding issue:
values before: 0.047098, 0.010474 | C
cube before [4.3191267336e-314, 1e-323] | Python, should be the same values
cube after [1.35689368162e-312, 3.1e-322] | Python
values after : 0.047098, 0.010474 | C
How can I fix the encoding issue (receive [0.047098, 0.010474] in the python function)?
I fixed it by using POINTER(c_double) instead of c_double * 2.
The new output looks like this: