diff --git a/shared_modules/m1.cpp b/shared_modules/m1.cpp index ce3a43e1..a752a128 100644 --- a/shared_modules/m1.cpp +++ b/shared_modules/m1.cpp @@ -17,12 +17,25 @@ char const * test(Shared const & m) extern "C" void initm1() { - py::module_builder m1("m1"); - + try { + py::module_builder m1("m1"); - py::class_builder m1_class(m1, "M1"); - m1_class.def(py::constructor<>()); - m1_class.declare_base(py::type()); - - m1.def(&test, "test"); + + py::class_builder m1_class(m1, "M1"); + m1_class.def(py::constructor<>()); + + try { + m1_class.declare_base(py::type()); + } + catch(std::runtime_error & ) + { + throw std::runtime_error("You must load module `shared' before module `m1'"); + } + + m1.def(&test, "test"); + } + catch(...) + { + py::handle_exception(); + } } diff --git a/shared_modules/m2.cpp b/shared_modules/m2.cpp index be881fd1..693dfd7b 100644 --- a/shared_modules/m2.cpp +++ b/shared_modules/m2.cpp @@ -11,9 +11,21 @@ namespace py = boost::python; extern "C" void initm2() { - py::module_builder m2("m2"); - - py::class_builder m2_class(m2, "M2"); - m2_class.def(py::constructor<>()); - m2_class.declare_base(py::type()); + try { + py::module_builder m2("m2"); + + py::class_builder m2_class(m2, "M2"); + m2_class.def(py::constructor<>()); + try { + m2_class.declare_base(py::type()); + } + catch(std::runtime_error & ) + { + throw std::runtime_error("You must load module `shared' before module `m2'"); + } + } + catch(...) + { + py::handle_exception(); + } } diff --git a/shared_modules/shared.cpp b/shared_modules/shared.cpp index 02b045da..9f01f777 100644 --- a/shared_modules/shared.cpp +++ b/shared_modules/shared.cpp @@ -11,9 +11,15 @@ char const * test(Shared const & m) extern "C" void initshared() { - py::module_builder shared("shared"); - py::class_builder shared_class(shared, "Shared"); - shared_class.def(py::constructor<>()); - shared_class.def(&Shared::name, "name"); - shared.def(&test, "test"); + try { + py::module_builder shared("shared"); + py::class_builder shared_class(shared, "Shared"); + shared_class.def(py::constructor<>()); + shared_class.def(&Shared::name, "name"); + shared.def(&test, "test"); + } + catch(...) + { + py::handle_exception(); + } } diff --git a/shared_modules/shared_modules.py b/shared_modules/shared_modules.py index 3f9d0a51..da17e4ba 100644 --- a/shared_modules/shared_modules.py +++ b/shared_modules/shared_modules.py @@ -1,7 +1,7 @@ r''' >>> import shared - >>> import m2 >>> import m1 + >>> import m2 >>> ls = shared.Shared() >>> ls.name() 'Shared'