Creating a python c-module: passing double arrays to c functions. segmentation fault. swig

sturlamolden sturlamolden at
Mon Mar 31 21:39:43 CEST 2008

On 31 Mar, 20:52, kim <kmg... at> wrote:

> array_pointer_t = ndpointer(dtype=c_double)

This one is wrong. The dtype should be the datatype kept in the array,
which is 'float' (Python doubles) or 'numpy.float64'.

array_pointer_t = ndpointer(dtype=numpy.float64)

I'd take a good look at that C code. For example, this is not valid C:

   double timewarp(double x[], int lenx, double y[], int leny) {

        double prev;
        double recx[lenx+1];
        double recy[leny+1];
        double warp[lenx+2][leny+2];
        int i,j;

I would be valid C99, but you are not compiling it as C99 (gcc does
not implement automatic arrays correctly in C99 anyway). If Fortran is
what you want, get gfortran or Intel Fortran. To make this valid C,
you will need to malloc these buffers, and free them when you are
done. Another option is to give them a fixed maximum size:

#define MAXLEN 1024
double recx[MAXLEN + 1];
double recy[MAXLEN + 1];
double warp[MAXLEN +2][MAXLEN +2];

There may be other errors as well, I did not look at it carefully.

More information about the Python-list mailing list