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 2 3244
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 rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Robert Kern wrote:
Did you call import_array() in init_mytest()?
No I didn't. Thank you very much for your help. Now it works.
With kind regards
Rolf Wester This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: satish |
last post by:
Hello all,
I have a shared object executable viz. *cable* which I execute as follows :
$ ansyscust71 -custom cable -p ANSYSRF
**ansyscust71 is a shell script and is a part of a software...
|
by: Shi Mu |
last post by:
Got confused by the following code:
>>> a
>>> b
>>> c
{1: , ], 2: ]}
>>> c.append(b.sort())
>>> c
{1: , ], 2: , None]}
|
by: robert |
last post by:
When employing complex UI libs (wx, win32ui, ..) and other extension
libs, nice "only Python stack traces" remain a myth.
Currently I'm hunting again a rare C-level crash bug of a Python based...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 375 open ( -3) / 3264 closed (+26) / 3639 total (+23)
Bugs : 910 open ( +3) / 5851 closed (+20) / 6761 total (+23)
RFE : 217 open...
|
by: saintlyav |
last post by:
I recently made a python module which calls functions from a c program. I used SWIG to generate the wrapper code from an interface file, and compiled the module into a dll which i can import in...
|
by: nimitsis |
last post by:
Hello everyone
I try to extend Python using a simple C wrapped module . This module includes embedded python code and it is product of Swig . The corresponding files follows :
//main.c
#include...
|
by: Tim Spens |
last post by:
The following is a simple complete example using the c python api to generate callbacks from c to python. But when I run the c code I get a segfault in PyInt_FromLong () (see below). Most of this...
|
by: RLC |
last post by:
Hello
I am new to python SWIG. Recently I wrote a small program trying to
import collada files(using colladadom) into python so I could use
python cgkit to render them. However, during the...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |