File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -976,18 +976,19 @@ class module_ : public object {
976
976
/* m_free */ nullptr
977
977
};
978
978
auto m = PyModule_Create (def);
979
- if (m == nullptr )
980
- pybind11_fail (" Internal error in module_::create_extension_module()" );
981
- // TODO: Should be reinterpret_steal, but Python also steals it again when returned from PyInit_...
982
- return reinterpret_borrow<module_>(m);
983
979
#else
984
980
// Ignore module_def *def; only necessary for Python 3
985
981
(void ) def;
986
982
auto m = Py_InitModule3 (name, nullptr , options::show_user_defined_docstrings () ? doc : nullptr );
987
- if (m == nullptr )
983
+ #endif
984
+ if (m == nullptr ) {
985
+ if (PyErr_Occurred ())
986
+ throw error_already_set ();
988
987
pybind11_fail (" Internal error in module_::create_extension_module()" );
988
+ }
989
+ // TODO: Sould be reinterpret_steal for Python 3, but Python also steals it again when returned from PyInit_...
990
+ // For Python 2, reinterpret_borrow is correct.
989
991
return reinterpret_borrow<module_>(m);
990
- #endif
991
992
}
992
993
};
993
994
You can’t perform that action at this time.
0 commit comments