From 39db96d5b21217a535fc7f4402093bfbc3305a63 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 14 Feb 2010 11:57:12 +0000 Subject: [PATCH] Add missing 'throw' modifiers as needed to method signatures in helper classes --- pybindgen/cppmethod.py | 6 ++++++ tests/foo.cc | 6 ++++++ tests/foo.h | 2 ++ tests/foomodulegen.py | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index e37d3aa..43793c8 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -973,6 +973,9 @@ class CppVirtualMethodProxy(ReverseWrapperBase): else: decl_post_modifiers = '' + if self.method.throw: + decl_post_modifiers += " throw (%s)" % (', '.join([ex.full_name for ex in self.method.throw]),) + params_list = ', '.join([join_ctype_and_name(param.ctype, param.name) for param in self.parameters]) code_sink.writeln("virtual %s %s(%s)%s;" % @@ -987,6 +990,9 @@ class CppVirtualMethodProxy(ReverseWrapperBase): else: decl_post_modifiers = [] + if self.method.throw: + decl_post_modifiers.append("throw (%s)" % (', '.join([ex.full_name for ex in self.method.throw]),)) + ## if the python subclass doesn't define a virtual method, ## just chain to parent class and don't do anything else call_params = ', '.join([param.name for param in self.parameters]) diff --git a/tests/foo.cc b/tests/foo.cc index 42087ac..1994e49 100644 --- a/tests/foo.cc +++ b/tests/foo.cc @@ -490,6 +490,12 @@ ClassThatThrows::ClassThatThrows (double x) throw (DomainError) } } +int +ClassThatThrows::throw_error () const throw (std::exception) +{ + throw std::runtime_error ("an error"); +} + double my_inverse_func2 (double x) throw (std::exception) diff --git a/tests/foo.h b/tests/foo.h index abc7901..113e778 100644 --- a/tests/foo.h +++ b/tests/foo.h @@ -1083,6 +1083,8 @@ public: // returns 1/x, raises DomainError if x == 0 double my_inverse_method (double x) throw (DomainError); double my_inverse_method2 (double x) throw (std::exception); + + virtual int throw_error () const throw (std::exception); }; diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index a6c31fa..649ce3c 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -516,7 +516,7 @@ int %s::custom_method_added_by_a_hook(int x) mod.add_function('my_inverse_func', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) - ClassThatThrows = mod.add_class('ClassThatThrows') + ClassThatThrows = mod.add_class('ClassThatThrows', allow_subclassing=True) ClassThatThrows.add_constructor([Parameter.new('double', 'x')], throw=[DomainError]) ClassThatThrows.add_method('my_inverse_method', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) @@ -527,6 +527,8 @@ int %s::custom_method_added_by_a_hook(int x) ClassThatThrows.add_method('my_inverse_method2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) + ClassThatThrows.add_method('throw_error', 'int', [], throw=[std_exception], is_const=True, is_virtual=True) + # https://bugs.launchpad.net/pybindgen/+bug/450255 ProtectedConstructor = mod.add_class('ProtectedConstructor') ProtectedConstructor.add_constructor([])