Commit f7ca244c authored by Manuel Günther's avatar Manuel Günther
Browse files

Corrected error cases in module creation

parent 237e1a93
......@@ -247,37 +247,39 @@ static PyObject* create_module (void) {
if (PyType_Ready(&PyBobLearnMLPRProp_Type) < 0) return 0;
# 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);
if (!module) return 0;
/* register the types to python */
Py_INCREF(&PyBobLearnMLPMachine_Type);
if (PyModule_AddObject(m, "Machine", (PyObject *)&PyBobLearnMLPMachine_Type) < 0) return 0;
if (PyModule_AddObject(module, "Machine", (PyObject *)&PyBobLearnMLPMachine_Type) < 0) return 0;
Py_INCREF(&PyBobLearnCost_Type);
if (PyModule_AddObject(m, "Cost", (PyObject *)&PyBobLearnCost_Type) < 0) return 0;
if (PyModule_AddObject(module, "Cost", (PyObject *)&PyBobLearnCost_Type) < 0) return 0;
Py_INCREF(&PyBobLearnSquareError_Type);
if (PyModule_AddObject(m, "SquareError", (PyObject *)&PyBobLearnSquareError_Type) < 0) return 0;
if (PyModule_AddObject(module, "SquareError", (PyObject *)&PyBobLearnSquareError_Type) < 0) return 0;
Py_INCREF(&PyBobLearnCrossEntropyLoss_Type);
if (PyModule_AddObject(m, "CrossEntropyLoss", (PyObject *)&PyBobLearnCrossEntropyLoss_Type) < 0) return 0;
if (PyModule_AddObject(module, "CrossEntropyLoss", (PyObject *)&PyBobLearnCrossEntropyLoss_Type) < 0) return 0;
Py_INCREF(&PyBobLearnDataShuffler_Type);
if (PyModule_AddObject(m, "DataShuffler", (PyObject *)&PyBobLearnDataShuffler_Type) < 0) return 0;
if (PyModule_AddObject(module, "DataShuffler", (PyObject *)&PyBobLearnDataShuffler_Type) < 0) return 0;
Py_INCREF(&PyBobLearnMLPTrainer_Type);
if (PyModule_AddObject(m, "Trainer", (PyObject *)&PyBobLearnMLPTrainer_Type) < 0) return 0;
if (PyModule_AddObject(module, "Trainer", (PyObject *)&PyBobLearnMLPTrainer_Type) < 0) return 0;
Py_INCREF(&PyBobLearnMLPBackProp_Type);
if (PyModule_AddObject(m, "BackProp", (PyObject *)&PyBobLearnMLPBackProp_Type) < 0) return 0;
if (PyModule_AddObject(module, "BackProp", (PyObject *)&PyBobLearnMLPBackProp_Type) < 0) return 0;
Py_INCREF(&PyBobLearnMLPRProp_Type);
if (PyModule_AddObject(m, "RProp", (PyObject *)&PyBobLearnMLPRProp_Type) < 0) return 0;
if (PyModule_AddObject(module, "RProp", (PyObject *)&PyBobLearnMLPRProp_Type) < 0) return 0;
static void* PyBobLearnMLP_API[PyBobLearnMLP_API_pointers];
......@@ -348,7 +350,7 @@ static PyObject* create_module (void) {
#endif
if (c_api_object) PyModule_AddObject(m, "_C_API", c_api_object);
if (c_api_object) PyModule_AddObject(module, "_C_API", c_api_object);
/* imports dependencies */
if (import_bob_blitz() < 0) return 0;
......@@ -357,7 +359,7 @@ static PyObject* create_module (void) {
if (import_bob_io_base() < 0) return 0;
if (import_bob_learn_activation() < 0) return 0;
return Py_BuildValue("O", m);
return Py_BuildValue(ret, module);
}
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
......
......@@ -59,22 +59,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_MLP_API_VERSION) < 0) return 0;
if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;
if (PyModule_AddIntConstant(module, "api", BOB_LEARN_MLP_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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment