From b28818d6bf055a0e443e6a2f89583f884f0a6cf5 Mon Sep 17 00:00:00 2001 From: Dmitry Bely Date: Wed, 3 Feb 2021 13:49:32 +0300 Subject: [PATCH 1/2] Add a test case for issue #280 --- test/fabscript | 1 + test/module_init_exception.cpp | 14 ++++++++++++++ test/module_init_exception.py | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/module_init_exception.cpp create mode 100644 test/module_init_exception.py diff --git a/test/fabscript b/test/fabscript index 03e4c6f919..eb9379e0ac 100644 --- a/test/fabscript +++ b/test/fabscript @@ -67,6 +67,7 @@ for t in [('injected',), ('args',), ('raw_ctor',), ('exception_translator',), + ('module_init_exception',), ('test_enum', ['enum_ext']), ('test_cltree', ['cltree']), ('newtest', ['m1', 'm2']), diff --git a/test/module_init_exception.cpp b/test/module_init_exception.cpp new file mode 100644 index 0000000000..d8cec57d3a --- /dev/null +++ b/test/module_init_exception.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2003 Rational Discovery LLC +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +using namespace boost::python; + +BOOST_PYTHON_MODULE(module_init_exception_ext) +{ + throw std::runtime_error("Module init failed"); +} diff --git a/test/module_init_exception.py b/test/module_init_exception.py new file mode 100644 index 0000000000..3da53e1956 --- /dev/null +++ b/test/module_init_exception.py @@ -0,0 +1,12 @@ +# Copyright (C) 2003 Rational Discovery LLC. Distributed under the Boost +# Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy +# at http://www.boost.org/LICENSE_1_0.txt) + +print("running...") + +try: + import module_init_exception_ext +except RuntimeError as e: + print(e) + +print("Done.") From 44470963961567d1e37ba573caa65487ace8b6f4 Mon Sep 17 00:00:00 2001 From: Dmitry Bely Date: Wed, 3 Feb 2021 13:52:14 +0300 Subject: [PATCH 2/2] Fix issue #280 --- src/module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module.cpp b/src/module.cpp index 9628481996..57675fa2df 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -21,7 +21,7 @@ namespace object m_obj(((borrowed_reference_t*)m)); scope current_module(m_obj); - handle_exception(init_function); + if (handle_exception(init_function)) return NULL; } return m;