Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython emits references to std::exception without #include-ing it #821

Closed
robertwb opened this issue Mar 27, 2009 · 1 comment
Closed

Cython emits references to std::exception without #include-ing it #821

robertwb opened this issue Mar 27, 2009 · 1 comment

Comments

@robertwb
Copy link
Contributor

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

Migrated from http://trac.cython.org/ticket/261

@robertwb
Copy link
Contributor Author

robertwb commented Mar 27, 2009

@robertwb changed milestone from wishlist to Dupe/Invalid
resolution to fixed
status from new to closed
commented

Fixed at http://trac.cython.org/ticket/265.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant