I want to access a C function that returns a struct containing double arrays (where the lengths of these arrays is given by other int members of the struct) from python. The dec
Check out SWIG's typemaps. They let you write your own code for handling specific types, specific instances (type+name) or even groups of arguments. I haven't done it for structures, but to specially handle a case where the C function takes an array and its size:
%typemap(in) (int argc, Descriptor* argv) {
/* Check if is a list */
if (PyList_Check($input)) {
int size = PyList_Size($input);
$1 = size;
...
$2 = ...;
}
}
That will take the pair of arguments int argc, Descriptor* argv
(since the names are provided they have to match as well) and pass you the PyObject used and you write whatever C code you need to do the conversion. You could do a typemap for double *dn
that would use the NumPy C API to do the conversion.