Skip to content

Commit

Permalink
Corrected error cases in module creation
Browse files Browse the repository at this point in the history
  • Loading branch information
siebenkopf committed Dec 3, 2015
1 parent c421bdb commit 853ddde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions bob/io/matlab/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ static PyObject* create_module (void) {

# if PY_VERSION_HEX >= 0x03000000
PyObject* m = PyModule_Create(&module_definition);
auto m_ = make_xsafe(m);
const char* ret = "O";
# else
PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
const char* ret = "N";
# endif
if (!m) return 0;
auto m_ = make_safe(m);

/* imports dependencies */
if (import_bob_blitz() < 0) return 0;
Expand All @@ -185,7 +187,7 @@ static PyObject* create_module (void) {
//do not return 0, or we may crash badly
}

return Py_BuildValue("O", m);
return Py_BuildValue(ret, m);
}

PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
Expand Down
6 changes: 4 additions & 2 deletions bob/io/matlab/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ static PyObject* create_module (void) {

# if PY_VERSION_HEX >= 0x03000000
PyObject* m = PyModule_Create(&module_definition);
auto m_ = make_xsafe(m);
const char* ret = "O";
# else
PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
const char* ret = "N";
# endif
if (!m) return 0;
auto m_ = make_safe(m); ///< protects against early returns

/* register version numbers and constants */
if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;
if (PyModule_AddObject(m, "externals", build_version_dictionary()) < 0) return 0;

return Py_BuildValue("O", m);
return Py_BuildValue(ret, m);
}

PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
Expand Down

0 comments on commit 853ddde

Please sign in to comment.