On Mar 25, 2009, at 11:17 AM, Simone Bisogni wrote: > Hi guys, > > I have a problem building a python c++ extension and, in > particular, the > problem occurs when I try to map C++ exceptions to python exceptions. > Here is a simple example:
[...] > The errors occur because the the inclusion of the stdexcept header is > missing. > > Is it a cython bug or it is up to the user to add the inclusion? http://trac.cython.org/cython_trac/ticket/265 > Actually, I have solved the problem adding the following rows to my > Cpp_Rectangle.pxd file, but I don't know if it is the right way to > procede: > > cdef extern from "stdexcept": > pass Yes, that should work well for now. > ====================================================================== > ==== > > Another error happens when I change my Cpp_Rectangle.pxd like this: > > ====================================================================== > ==== > > ### Cpp_Rectangle.pxd > > cdef extern from "stdexcept": > pass > > cdef extern from "Rectangle.h": > ctypedef struct cpp_Rectangle "Rectangle": > > int raiseException() except +MemoryError > > cpp_Rectangle* new_Rectangle "new Rectangle"( int x0, int y0, int > x1, > int y1 ) > void delete_Rectangle "delete"( cpp_Rectangle* rect ) > > ====================================================================== > === > > Basically I am trying now to map each exception thrown by the > raiseException to a python MemoryError exception. > > The cython compilation runs fine again, but when I try to compile the > .cpp file I got the errors: > > ====================================================================== > === > > [sim...@spider Cython_Test]$ g++ -shared -fPIC -I/usr/include/ > python2.5 > -o PyRectangle.so PyRectangle.cpp -L /usr/lib64 -L. -lRectangle - > lpython2.5 > PyRectangle.cpp: In function 'PyObject* > __pyx_pf_11PyRectangle_9Rectangle_raiseException(PyObject*, > PyObject*)': > PyRectangle.cpp:454: error: '__pyx_builtin_MemoryError' was not > declared > in this scope > > ====================================================================== > ==== > > The accused piece of code is the following: > > ====================================================================== > ==== > > /* __pyx_t_1 allocated */ > try { > __pyx_t_1 = > ((struct__pyx_obj_11PyRectangle_Rectangle*)__pyx_v_self)->thisptr- > >raiseException();} > > > catch(...) {PyErr_SetString(__pyx_builtin_MemoryError, ""); > {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = > __LINE__; goto __pyx_L1_error;}} > > ====================================================================== > ======= > > The variable __pyx_builtin_MemoryError is not declared anywhere. > Should the __pyx_builtin_MemoryError be substituted with > PyExc_MemoryError? http://trac.cython.org/cython_trac/ticket/266 Perhaps writing foo = MemoryError somewhere in your file will be a temporary fix. > The version of cython I am using is the 0.11 > > Thanks in advance and sorry for my long email. Thanks for the bug reports. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
