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 47a7c3b commit fc20aae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions bob/learn/em/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ static PyObject* create_module (void) {

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

if (!init_BobLearnEMGaussian(module)) return 0;
if (!init_BobLearnEMGMMStats(module)) return 0;
Expand Down Expand Up @@ -129,7 +131,7 @@ static PyObject* create_module (void) {
if (import_bob_learn_activation() < 0) return 0;
if (import_bob_learn_linear() < 0) return 0;

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

PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
Expand Down
18 changes: 10 additions & 8 deletions bob/learn/em/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,24 @@ static PyModuleDef module_definition = {
static PyObject* create_module (void) {

# if PY_VERSION_HEX >= 0x03000000
PyObject* m = PyModule_Create(&module_definition);
PyObject* module = PyModule_Create(&module_definition);
auto module_ = make_xsafe(module);
const char* ret = "O";
# else
PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
PyObject* module = 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
if (!module) return 0;

/* register version numbers and constants */
if (PyModule_AddIntConstant(m, "api", BOB_LEARN_EM_API_VERSION) < 0) return 0;
if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;
if (PyModule_AddIntConstant(module, "api", BOB_LEARN_EM_API_VERSION) < 0) return 0;
if (PyModule_AddStringConstant(module, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;

PyObject* externals = build_version_dictionary();
if (!externals) return 0;
if (PyModule_AddObject(m, "externals", externals) < 0) return 0;
if (PyModule_AddObject(module, "externals", externals) < 0) return 0;

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

PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
Expand Down

0 comments on commit fc20aae

Please sign in to comment.