From 74f797e540f4a48b5f434bbf4cef31825e96cf6d Mon Sep 17 00:00:00 2001
From: Manuel Gunther <siebenkopf@googlemail.com>
Date: Thu, 3 Dec 2015 12:30:31 -0700
Subject: [PATCH] Corrected error cases in module creation

---
 bob/io/base/main.cpp    | 7 ++++---
 bob/io/base/version.cpp | 8 ++++----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/bob/io/base/main.cpp b/bob/io/base/main.cpp
index c6ae754..01a82d9 100644
--- a/bob/io/base/main.cpp
+++ b/bob/io/base/main.cpp
@@ -84,11 +84,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);
 
   /* register some constants */
   if (!init_File(m)) return 0;
@@ -164,8 +166,7 @@ static PyObject* create_module (void) {
   /* imports dependencies */
   if (import_bob_blitz() < 0) return 0;
 
-  return Py_BuildValue("O", m);
-
+  return Py_BuildValue(ret, m);
 }
 
 PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
diff --git a/bob/io/base/version.cpp b/bob/io/base/version.cpp
index 5ad70c6..91ccc1d 100644
--- a/bob/io/base/version.cpp
+++ b/bob/io/base/version.cpp
@@ -5,7 +5,6 @@
  * @brief Binds configuration information available from bob
  */
 
-
 #define BOB_IMPORT_VERSION
 #include <bob.blitz/config.h>
 #include <bob.blitz/cleanup.h>
@@ -53,11 +52,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); ///< protects against early returns
 
   /* register version numbers and constants */
   if (PyModule_AddIntConstant(m, "api", BOB_IO_BASE_API_VERSION) < 0)
@@ -69,8 +70,7 @@ static PyObject* create_module (void) {
   // call bob_io_base_version once to avoid compiler warning
   auto _ = make_safe(bob_io_base_version());
 
-  return Py_BuildValue("O", m);
-
+  return Py_BuildValue(ret, m);
 }
 
 PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
-- 
GitLab