[Numpy-discussion] segv PyArray_Check

David Froger david.froger at inria.fr
Thu Nov 14 01:48:37 EST 2013


Hi Burlen,

SWIG will generate a file named for example foo_wrap.c, which will
contains a call to import_array() inserted by SWIG because of the
%init %{
    import_array();
%}
in the SWIG script.
So in the file foo_wrap.c (which will be compiled to a Python module
_foo.so), you should be able to used PyArray_Check without segfault.
Typically, PyArray_Check will be inserted in foo_wrap.c by a typemap,
for example a typemap from numpy.i .

Do you use PyArray_Check in the foo_wrap.c or in another file? Is 
PyArray_Check in called in another C library, that _foo.so is linked
with? 

David

Quoting Burlen Loring (2013-11-14 02:21:19)
> Hi,
> 
> I'd like to add numpy support to an existing code that uses swig. I've 
> changed the source file that has code to convert python lists into 
> native data from c to c++ so I can use templates to handle data 
> conversions. The problem I'm having is a segfault on PyArray_Check 
> called from my c++ source. Looking at things in the debugger the 
> argument passed to it is indeed an intialized python list, my swig file 
> has import_array() in it's init, and I've verified that it is getting 
> called. adding a function in my c++ source to call import_array() a 
> second time prevents the segfault. Could anyone explain why I need the 
> import_array() in both places? If that's the correct way to handle it?
> 
> Thanks
> Burlen
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list