Skip to content

Fix error handling inside BOOST_PYTHON_MODULE() #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/fabscript
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
14 changes: 14 additions & 0 deletions test/module_init_exception.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/python/module.hpp>
#include <stdexcept>

using namespace boost::python;

BOOST_PYTHON_MODULE(module_init_exception_ext)
{
throw std::runtime_error("Module init failed");
}
12 changes: 12 additions & 0 deletions test/module_init_exception.py
Original file line number Diff line number Diff line change
@@ -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.")