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) I also ran this with valgrind. Part of valgrinds output is: ==15792== Reading syms from /mnt/pubdsk/A31/2003/DOKUMENTATION/WESTER/pr3/OPT/opt2.0/test/_mytest.so (0x1BE7E000) ==15792== Reading syms from /usr/local/lib/python2.4/site-packages/Numeric/multiarray.so (0x1B90F000) ==15792== Reading syms from /usr/local/lib/python2.4/site-packages/Numeric/_numpy.so (0x1BFDB000) ==15792== Reading syms from /usr/local/lib/python2.4/site-packages/Numeric/umath.so (0x1BFF1000) ==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/strop.so (0x1B91A000) ==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/math.so (0x1C103000) ==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/struct.so (0x1C209000) ==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/binascii.so (0x1C210000) ==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/cStringIO.so (0x1C216000) mytest_wrap.cpp 1499 mytest_wrap.cpp 1502 0x1bca7610 ==15792== Invalid read of size 4 ==15792== at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503) ==15792== by 0x811E685: PyCFunction_Call (methodobject.c:93) ==15792== by 0x80C708F: PyEval_EvalFrame (ceval.c:1499) ==15792== by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736) ==15792== by 0x80C8B64: PyEval_EvalCode (ceval.c:484) ==15792== by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265) ==15792== by 0x80558D6: Py_Main (main.c:484) ==15792== by 0x8054F86: main (python.c:23) ==15792== Address 0x38 is not stack'd, malloc'd or (recently) free'd ==15792== ==15792== Process terminating with default action of signal 11 (SIGSEGV) ==15792== Access not within mapped region at address 0x38 ==15792== at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503) ==15792== by 0x811E685: PyCFunction_Call (methodobject.c:93) ==15792== by 0x80C708F: PyEval_EvalFrame (ceval.c:1499) ==15792== by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736) ==15792== by 0x80C8B64: PyEval_EvalCode (ceval.c:484) ==15792== by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265) ==15792== by 0x80558D6: Py_Main (main.c:484) ==15792== by 0x8054F86: main (python.c:23) ==15792== ==15792== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 8093 from 7) ==15792== I would be very appreciative for any help. With kind regards Rolf Wester -- http://mail.python.org/mailman/listinfo/python-list