From efabce0ab940d77fcba5aebb1b8a8051773cfc54 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Sat, 8 May 2010 19:24:53 -0300 Subject: [PATCH] fix except+ for cppclass methods (with Denys Duchier) --- Cython/Compiler/Symtab.py | 4 ++- tests/run/cpp_exceptions.pyx | 48 +++++++++++++++++++++++++++++++ tests/run/cpp_exceptions_helper.h | 10 +++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 5b74ebc1..426151b7 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1615,7 +1615,9 @@ class CppClassScope(Scope): e.pos, e.cname) return scope - + + def add_include_file(self, filename): + self.outer_scope.add_include_file(filename) class PropertyScope(Scope): # Scope holding the __get__, __set__ and __del__ methods for diff --git a/tests/run/cpp_exceptions.pyx b/tests/run/cpp_exceptions.pyx index e7707a7a..7d1f16b8 100644 --- a/tests/run/cpp_exceptions.pyx +++ b/tests/run/cpp_exceptions.pyx @@ -10,6 +10,12 @@ cdef extern from "cpp_exceptions_helper.h": cdef int raise_index_value "raise_index"(bint fire) except +ValueError cdef int raise_index_custom "raise_index"(bint fire) except +raise_py_error + cdef cppclass Foo: + int bar_raw "bar"(bint fire) except + + int bar_value "bar"(bint fire) except +ValueError + int bar_custom "bar"(bint fire) except +raise_py_error + + def test_int_raw(bint fire): """ >>> test_int_raw(False) @@ -69,3 +75,45 @@ def test_index_custom(bint fire): TypeError: custom """ raise_index_custom(fire) + +def test_cppclass_method_raw(bint fire): + """ + >>> test_cppclass_method_raw(False) + >>> test_cppclass_method_raw(True) + Traceback (most recent call last): + ... + RuntimeError: Unknown exception + """ + foo = new Foo() + try: + foo.bar_raw(fire) + finally: + del foo + +def test_cppclass_method_value(bint fire): + """ + >>> test_cppclass_method_value(False) + >>> test_cppclass_method_value(True) + Traceback (most recent call last): + ... + ValueError + """ + foo = new Foo() + try: + foo.bar_value(fire) + finally: + del foo + +def test_cppclass_method_custom(bint fire): + """ + >>> test_cppclass_method_custom(False) + >>> test_cppclass_method_custom(True) + Traceback (most recent call last): + ... + TypeError: custom + """ + foo = new Foo() + try: + foo.bar_custom(fire) + finally: + del foo diff --git a/tests/run/cpp_exceptions_helper.h b/tests/run/cpp_exceptions_helper.h index 7640f531..e0ff3e94 100644 --- a/tests/run/cpp_exceptions_helper.h +++ b/tests/run/cpp_exceptions_helper.h @@ -13,3 +13,13 @@ int raise_index(int fire) { } return 0; } + +class Foo { + public: + int bar(int fire) { + if (fire) { + throw 1; + } + return 0; + } +}; -- 2.26.2