Hi, Does anyone have an insight on the following problem? PyObject* descr(PyObject* self, PyObject* args) { PyObject *d; PyArg_ParseTuple(args, "O&", PyArray_DescrConverter, &d); return d; }
import numpy import mymodule numpy.__version__ '1.2.1' mymodule.descr([('a', 'i4'), ('b', 'i8')]) segmentation fault (core dumped) ipython
Thanks! -Igor
I realize I need to call import_array() in the module initialization module. Why isn't this equivalent to importing numpy before importing my module? ---------- Forwarded message ---------- From: Igor Sylvester <igorsyl@gmail.com> Date: Thu, Jan 1, 2009 at 1:09 PM Subject: PyArray_DescrConverter segfault To: Numpy-discussion@scipy.org Hi, Does anyone have an insight on the following problem? PyObject* descr(PyObject* self, PyObject* args) { PyObject *d; PyArg_ParseTuple(args, "O&", PyArray_DescrConverter, &d); return d; }
import numpy import mymodule numpy.__version__ '1.2.1' mymodule.descr([('a', 'i4'), ('b', 'i8')]) segmentation fault (core dumped) ipython
Thanks! -Igor
On Thu, Jan 1, 2009 at 14:21, Igor Sylvester <igorsyl@gmail.com> wrote:
I realize I need to call import_array() in the module initialization module. Why isn't this equivalent to importing numpy before importing my module?
In 3rd party extension modules, all of the PyArray_* API functions are actually #define macros pointing to an array of function pointers. import_array() imports numpy.core.multiarray and sets up this array. If you don't do this, then trying to call one of the PyArray_* functions will result in a segfault because it tries to dereference a pointer in the array that is not set up. -- 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
Robert, If I import numpy and then import a 3rd party extension module, why does the extension module still have to call import_array if numpy sets this array in the first place? I assume that there's a single array of API functions in a single python process with multiple extension modules. Igor. On Thu, Jan 1, 2009 at 4:11 PM, Robert Kern <robert.kern@gmail.com> wrote:
On Thu, Jan 1, 2009 at 14:21, Igor Sylvester <igorsyl@gmail.com> wrote:
I realize I need to call import_array() in the module initialization module. Why isn't this equivalent to importing numpy before importing my module?
In 3rd party extension modules, all of the PyArray_* API functions are actually #define macros pointing to an array of function pointers. import_array() imports numpy.core.multiarray and sets up this array. If you don't do this, then trying to call one of the PyArray_* functions will result in a segfault because it tries to dereference a pointer in the array that is not set up.
-- 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 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Thu, Jan 1, 2009 at 17:25, Igor Sylvester <igorsyl@gmail.com> wrote:
Robert,
If I import numpy and then import a 3rd party extension module, why does the extension module still have to call import_array if numpy sets this array in the first place? I assume that there's a single array of API functions in a single python process with multiple extension modules.
Your 3rd party extension module does not know the location of that array until you call import_array(). -- 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
participants (2)
-
Igor Sylvester
-
Robert Kern