From ed5acf99644bcf1a997e26d92621477922e60f3a Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Tue, 19 Nov 2013 17:22:46 +0100
Subject: [PATCH] Improve capsule importing for random C-API

---
 xbob/io/include/xbob.io/api.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/xbob/io/include/xbob.io/api.h b/xbob/io/include/xbob.io/api.h
index 4b5e5b4..97c43d9 100644
--- a/xbob/io/include/xbob.io/api.h
+++ b/xbob/io/include/xbob.io/api.h
@@ -302,11 +302,23 @@ typedef struct {
     Py_DECREF(c_api_object);
     Py_DECREF(module);
 
+    if (!PyBlitzArray_API) {
+      PyErr_Format(PyExc_ImportError,
+#   if PY_VERSION_HEX >= 0x02070000
+          "cannot find C/C++ API capsule at `%s.%s'",
+#   else
+          "cannot find C/C++ API cobject at `%s.%s'",
+#   endif
+          BOOST_PP_STRINGIZE(XBOB_IO_MODULE_PREFIX),
+          BOOST_PP_STRINGIZE(XBOB_IO_MODULE_NAME));
+      return -1
+    }
+
     /* Checks that the imported version matches the compiled version */
     int imported_version = *(int*)PyXbobIo_API[PyIo_APIVersion_NUM];
 
     if (XBOB_IO_API_VERSION != imported_version) {
-      PyErr_Format(PyExc_RuntimeError, "%s.%s import error: you compiled against API version 0x%04x, but are now importing an API with version 0x%04x which is not compatible - check your Python runtime environment for errors", BOOST_PP_STRINGIZE(XBOB_IO_MODULE_PREFIX), BOOST_PP_STRINGIZE(XBOB_IO_MODULE_NAME), XBOB_IO_API_VERSION, imported_version);
+      PyErr_Format(PyExc_ImportError, "%s.%s import error: you compiled against API version 0x%04x, but are now importing an API with version 0x%04x which is not compatible - check your Python runtime environment for errors", BOOST_PP_STRINGIZE(XBOB_IO_MODULE_PREFIX), BOOST_PP_STRINGIZE(XBOB_IO_MODULE_NAME), XBOB_IO_API_VERSION, imported_version);
       return -1;
     }
 
-- 
GitLab