1

I am developing a program that extends python with C++ code, and it looks like I'm missing something in initialization or cleanup. The symptom is that when the program terminates it prints out something like this:

*** glibc detected *** ... corrupted double-linked list: 0x0000000001ad0700 ***
======= Backtrace: =========
.../python2.7/site-packages/numpy/core/../.libs/libgfortran-ed201abd.so.3.0.0(+0xc249a)[0x7f242063749a]
...

I do this for initialization:

PyMODINIT_FUNC init_dosemap()
{
    Py_InitModule3( "_dosemap", methods, ... );
    import_array();
}

The array is initialized like this:

npy_intp dims[] = { width, height };
int nd = sizeof(dims) / sizeof(dims[0]);
PyObject * ndArray = PyArray_SimpleNew( nd , dims, NPY_FLOAT32 );
Py_INCREF( ndArray );

filled like this:

for( int y = 0; y < dims[ 1 ]; ++y )
    for( int x = 0; x < dims[ 0 ]; ++x )
        * (float *) PyArray_GETPTR2( ndArray, x, y ) = ...

and returned like this:

PyObject* out = Py_BuildValue( "(Offf)", ndArray, ... );
Py_INCREF( out );
return out;

There seem to be no problems until the program exits. What I am missing here?

Michael
  • 5,775
  • 2
  • 34
  • 53

0 Answers0