[Numpy-discussion] PyArray_SimpleNewFromData segfaults

Ondrej Certik ondrej at certik.cz
Mon Oct 5 23:38:18 EDT 2009


On Mon, Oct 5, 2009 at 7:34 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
>
>
> On Mon, Oct 5, 2009 at 7:40 PM, Ondrej Certik <ondrej at certik.cz> wrote:
[...]
>> still alive
>> Segmentation fault
>>
>>
>>
>> What puzzles me is that there is no debugging print statement just
>> before the segfault.
>
> Maybe you need to flush the buffer. That is a good thing to do when
> segfaults are about.

I tried to put "fflush(NULL);" after it, but it didn't help. I have
created a super simple demo for anyone to play:


$ git clone git://github.com/certik/segfault.git
$ cd segfault/
$ vim Makefile     # <-- edit the python and numpy include paths
$ make
$ python test.py
I am still alive
Segmentation fault

where test.py is:

$ cat test.py
import _hermes1d
v = _hermes1d.test()
print v


and _hermes1d.pyx is:

$ cat _hermes1d.pyx
def test():
    cdef npy_intp size
    cdef ndarray newarr
    cdef double *arrsource

    size = 10
    arrsource = <double *>malloc(sizeof(double) * size)
    print "I am still alive"
    newarr = PyArray_SimpleNewFromData(1, &size, NPY_DOUBLE, <void *>arrsource)
    print "I am dead."

    return newarr


So I bet there is something very stupid that I am missing. Still
investigating...

Ondrej



More information about the NumPy-Discussion mailing list