Python/SWIG: Output an array

Viewed 5420

I am trying to output an array of values from a C function wrapped using SWIG for Python. The way I am trying to do is using the following typemap.

Pseudo code:

int oldmain() {
float *output = {0,1};
return output;
}

Typemap:

%typemap(out) float* { 
   int i; 
  $result = PyList_New($1_dim0); 
   for (i = 0; i < $1_dim0; i++) { 
 PyObject *o = PyFloat_FromDouble((double) $1[i]); 
 PyList_SetItem($result,i,o); 
 } 
} 

My code compiles well, but it hangs when I run access this function (with no more ways to debug it).

Any suggestions on where I am going wrong?

Thanks.

2 Answers
Related