[Numpy-discussion] Segfault with simplest operation on extension module using numpy

Robert Kern robert.kern at gmail.com
Fri Jun 16 11:44:53 CDT 2006


Glen W. Mabey wrote:

> That is, when I run:
>     import DFALG
>     DFALG.bsvmdf( 3 )
> after compiling the below code, it always segfaults, regardless of the
> type of the argument given.  Just as a sanity check (it's been a little
> while since I have written an extension module for Python) I changed the
> line containing PyArray_Check() to one that calls PyInt_Check(), which
> does perform exactly how I would expect it to.
> 
> Is there something I'm missing?

Yes!

> #include <Python.h>
> #include <arrayobject.h>

This should be "numpy/arrayobject.h" for consistency with every other
numpy-using extension.

> PyMODINIT_FUNC
> initDFALG(void)
> {
> 	(void) Py_InitModule("DFALG", DFALGMethods);
> }

You need to call import_array() in this function.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco





More information about the Numpy-discussion mailing list