From 8bec9ac902bc381ce39e9fba916bcfbbecf50247 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 21 Oct 2009 18:30:48 +0100 Subject: [PATCH] Bug 450255: Invalid 'cannot generate a constructor' case --- pybindgen/cppmethod.py | 8 ++++---- tests/foo.h | 12 ++++++++++++ tests/foomodulegen.py | 11 ++++++++--- tests/footest.py | 3 +++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pybindgen/cppmethod.py b/pybindgen/cppmethod.py index ae37d0c..a5d92cf 100644 --- a/pybindgen/cppmethod.py +++ b/pybindgen/cppmethod.py @@ -553,12 +553,12 @@ class CppConstructor(ForwardWrapperBase): Returns the wrapper function name. """ if self.visibility == 'private': - raise CodeGenerationError("Class %r has a private constructor ->" - " cannot generate a constructor for it" % self._class.full_name) + raise utils.SkipWrapper("Class %r has a private constructor ->" + " cannot generate a constructor for it" % self._class.full_name) elif self.visibility == 'protected': if self._class.helper_class is None: - raise CodeGenerationError("Class %r has a protected constructor and no helper class" - " -> cannot generate a constructor for it" % self._class.full_name) + raise utils.SkipWrapper("Class %r has a protected constructor and no helper class" + " -> cannot generate a constructor for it" % self._class.full_name) #assert isinstance(class_, CppClass) tmp_sink = codesink.MemoryCodeSink() diff --git a/tests/foo.h b/tests/foo.h index b378b7a..b1e0c1f 100644 --- a/tests/foo.h +++ b/tests/foo.h @@ -1066,4 +1066,16 @@ public: }; +// https://bugs.launchpad.net/pybindgen/+bug/450255 +class ProtectedConstructor +{ +public: + ProtectedConstructor() {} +protected: + // Not to be implemented + ProtectedConstructor(ProtectedConstructor&); + void operator=(ProtectedConstructor&); +}; + + #endif /* !FOO_H_ */ diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index d6c84d4..9cd96ca 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -516,17 +516,22 @@ int %s::custom_method_added_by_a_hook(int x) ClassThatThrows.add_method('my_inverse_method2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) - - + # https://bugs.launchpad.net/pybindgen/+bug/450255 + ProtectedConstructor = mod.add_class('ProtectedConstructor') + ProtectedConstructor.add_constructor([]) + ProtectedConstructor.add_constructor([Parameter.new('ProtectedConstructor&', 'c')], visibility='protected') #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler): def __init__(self): super(MyErrorHandler, self).__init__() self.num_errors = 0 - def handle_error(self, wrapper, exception, dummy_traceback_): + def handle_error(self, wrapper, exception, traceback_): print >> sys.stderr, "exception %s in wrapper %s" % (exception, wrapper) self.num_errors += 1 + if 0: # verbose? + import traceback + traceback.print_tb(traceback_) return True pybindgen.settings.error_handler = MyErrorHandler() diff --git a/tests/footest.py b/tests/footest.py index fa6b8b2..05e0590 100644 --- a/tests/footest.py +++ b/tests/footest.py @@ -1202,5 +1202,8 @@ class TestFoo(unittest.TestCase): r = foo.Foo.add_sub(1, 2) self.assertEqual(r, 3) + def test_bug450255(self): + c = foo.ProtectedConstructor() + if __name__ == '__main__': unittest.main()