Ticket #261 (closed defect: fixed)
Cython emits references to std::exception without #include-ing it
| Reported by: | dagss | Owned by: | somebody |
|---|---|---|---|
| Priority: | minor | Milestone: | Dupe/Invalid |
| Component: | C++ | Keywords: | |
| Cc: |
Description
Stephane Drouard:
lib.h
=====
void foo();
good.pyx
========
cdef extern from "lib.h":
void foo()
foo()
Everything's OK.
But with:
bad.pyx
=======
cdef extern from "lib.h":
void foo() except +
foo()
g++ reports:
bad.c: In function `void __Pyx_CppExn2PyErr()':
bad.c:189: error: expected unqualified-id before '&' token
bad.c:189: error: ISO C++ forbids declaration of `type name' with no type
bad.c:189: error: expected `)' before '&' token
bad.c:189: error: expected `{' before '&' token
bad.c:189: error: `exn' was not declared in this scope
bad.c:189: error: expected `;' before ')' token
bad.c:192: error: expected primary-expression before "catch"
bad.c:192: error: expected `;' before "catch"
bad.c:195: error: expected primary-expression before "catch"
bad.c:195: error: expected `;' before "catch"
bad.c:189: warning: unused variable 'exn'
Here is bad.c extract:
182 #ifndef __Pyx_CppExn2PyErr
183 static void __Pyx_CppExn2PyErr() {
184 try {
185 if (PyErr_Occurred())
186 ; // let the latest Python exn pass through and ignore the current one
187 else
188 throw;
189 } catch (const std::out_of_range& exn) {
190 // catch out_of_range explicitly so the proper Python exn may be raised
191 PyErr_SetString(PyExc_IndexError, exn.what());
192 } catch (const std::exception& exn) {
193 PyErr_SetString(PyExc_RuntimeError, exn.what());
194 }
195 catch (...)
196 {
197 PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
198 }
199 }
200 #endif
To fix that I need to add in bad.pyx:
cdef extern from "stdexcept":
pass
Change History
Note: See
TracTickets for help on using
tickets.
