Python extension module segmentation fault
Robert Kern
robert.kern at gmail.com
Fri Oct 21 04:41:32 EDT 2005
Rolf Wester wrote:
> Hi,
>
> I' trying to make an extension module that passes Numeric arrays. The
> wrapper function is (swig generated and modified by myself):
>
> static PyObject *_wrap_my_func(PyObject *self, PyObject *args) {
> PyObject * resultobj = 0 ;
> PyObject * obj0 = 0 ;
> PyArrayObject * mat = 0 ;
>
> std::cout << __FILE__ << " " << __LINE__ << std::endl;
> if(!PyArg_ParseTuple(args,(char *)"O:my_func",&obj0)) goto fail;
> std::cout << __FILE__ << " " << __LINE__ << " " << obj0 << std::endl;
> mat = (PyArrayObject *) PyArray_ContiguousFromObject(obj0,
> PyArray_DOUBLE, 1, 1);
> std::cout << __FILE__ << " " << __LINE__ << " " << mat << std::endl;
>
> Py_INCREF(Py_None); resultobj = Py_None;
> return resultobj;
> fail:
> return NULL;
> }
>
> The shared object is build with:
>
> g++ -c -g -fPIC -I./ -I/usr/local/include/python2.4
> -I/usr/local/include/python2.4/Numeric mytest_wrap.cpp -o mytest_wrap.o
>
> g++ -shared -L/usr/local/lib/python2.4/config/ mytest_wrap.o
> -lpython2.4 -lm -o _mytest.so
>
>
> the Python file reads:
>
> import _mytest
> from Numeric import *
> mat = ones(100,Float64)
> print _mytest.my_func(mat)
>
> When running this I get the output:
>
> mytest_wrap.cpp 1499
> mytest_wrap.cpp 1502 0x402b55e8
> Speicherzugriffsfehler (segmentation fault)
Did you call import_array() in init_mytest()?
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list