Hello,

Cython does not include stdexcept when we ask it to catch exceptions.

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

Cheers,
Stephane

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to