From 3ac1a30e355223c49df794829667624626d3c13a Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 11 May 2011 16:14:39 +0100 Subject: [PATCH] Bug #780945: Exception translation generates invalid code if return value is wrapped (i.e. not primitive) --- pybindgen/cppmethod.py | 6 ++++++ pybindgen/function.py | 5 +++++ tests/foo.cc | 9 +++++++++ tests/foo.h | 2 ++ tests/foomodulegen.py | 4 ++++ 5 files changed, 26 insertions(+) diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index 81384d7..6f9772e 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -365,6 +365,11 @@ class CppMethod(ForwardWrapperBase): Returns the corresponding PyMethodDef entry string. """ + + if self.throw: # Bug #780945 + self.return_value.REQUIRES_ASSIGNMENT_CONSTRUCTOR = False + self.reset_code_generation_state() + class_ = self.class_ #assert isinstance(class_, CppClass) tmp_sink = codesink.MemoryCodeSink() @@ -681,6 +686,7 @@ class CppConstructor(ForwardWrapperBase): :returns: the wrapper function name. """ + if self.visibility == 'private': raise utils.SkipWrapper("Class %r has a private constructor ->" " cannot generate a constructor for it" % self._class.full_name) diff --git a/pybindgen/function.py b/pybindgen/function.py index dc61192..4e7d656 100644 --- a/pybindgen/function.py +++ b/pybindgen/function.py @@ -212,6 +212,11 @@ class Function(ForwardWrapperBase): :param code_sink: a CodeSink instance that will receive the generated code :param wrapper_name: name of wrapper function """ + + if self.throw: # Bug #780945 + self.return_value.REQUIRES_ASSIGNMENT_CONSTRUCTOR = False + self.reset_code_generation_state() + if wrapper_name is None: self.wrapper_actual_name = self.wrapper_base_name else: diff --git a/tests/foo.cc b/tests/foo.cc index 1073e94..f746c1d 100644 --- a/tests/foo.cc +++ b/tests/foo.cc @@ -536,3 +536,12 @@ ClassThatThrows::my_inverse_method3 (double x) } return 1/x; } + + +Tupl +my_throwing_func () throw (std::exception) +{ + Tupl retval; + return retval; +} + diff --git a/tests/foo.h b/tests/foo.h index c91adce..21c4633 100644 --- a/tests/foo.h +++ b/tests/foo.h @@ -1208,5 +1208,7 @@ public: }; +Tupl my_throwing_func () throw (std::exception); + #endif /* !FOO_H_ */ diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index 11e7d9a..9c458e3 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -575,6 +575,10 @@ int %s::custom_method_added_by_a_hook(int x) MIMixed.add_constructor([]) MIMixed.add_method('mixed_method', 'int', [], is_const=True) + + mod.add_function('my_throwing_func', 'Tupl', [], throw=[std_exception]) + + #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler):