Dr. Dobb's Journal February 1998
// Make 'double *vector' accept a list of values
%typemap(python,in) double *vector {
/* Convert a Python List into an array of values */
int i,sz;
sz = PyList_Size($source);
$target = (double *) malloc(sz*sizeof(double));
for (i = 0; i < sz; i++) {
$target[i] = (double)
PyFloat_AsDouble(PyList_GetItem($source,i));
}
}
%typemap(python,freearg) double *vector {
free($source); /* clean up to avoid memory leaks */
}
void foo(double *vector);