summaryrefslogtreecommitdiff
path: root/numpy/linalg
diff options
context:
space:
mode:
authorMichael Droettboom <mdboom@gmail.com>2018-03-20 22:07:08 -0400
committerMichael Droettboom <mdboom@gmail.com>2018-03-30 11:42:56 -0400
commit2a6565c6432c682c2798e75d48adc587da661822 (patch)
tree535f247d0b0f00c8b61db6e42ec5fc4768d7cc15 /numpy/linalg
parent517f4c0749f83488d25493ccea62b91caa03c2d6 (diff)
downloadnumpy-2a6565c6432c682c2798e75d48adc587da661822.tar.gz
Return NULL from PyInit_* when exception is raised
I don't think this is documented anywhere, but I'm pretty sure module init functions should return NULL in order to communicate that an exception occurred during initialization (as is the standard Python/C API convention). It's clear from the CPython code [here](https://github.com/python/cpython/blob/master/Python/importdl.c#L162) that if you don't return NULL, the exception is swallowed and replaced with the message "initialization of %s raised unreported exception". Admittedly, this is only useful for people porting Numpy to new platforms where it is helpful to know where module initialization is failing, but it can't hurt.
Diffstat (limited to 'numpy/linalg')
-rw-r--r--numpy/linalg/lapack_litemodule.c8
-rw-r--r--numpy/linalg/umath_linalg.c.src9
2 files changed, 9 insertions, 8 deletions
diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c
index bdde2e22d..696a6d874 100644
--- a/numpy/linalg/lapack_litemodule.c
+++ b/numpy/linalg/lapack_litemodule.c
@@ -331,10 +331,10 @@ static struct PyModuleDef moduledef = {
/* Initialization function for the module */
#if PY_MAJOR_VERSION >= 3
-#define RETVAL m
+#define RETVAL(x) x
PyMODINIT_FUNC PyInit_lapack_lite(void)
#else
-#define RETVAL
+#define RETVAL(x)
PyMODINIT_FUNC
initlapack_lite(void)
#endif
@@ -347,12 +347,12 @@ initlapack_lite(void)
"", (PyObject*)NULL,PYTHON_API_VERSION);
#endif
if (m == NULL) {
- return RETVAL;
+ return RETVAL(NULL);
}
import_array();
d = PyModule_GetDict(m);
LapackError = PyErr_NewException("lapack_lite.LapackError", NULL, NULL);
PyDict_SetItemString(d, "LapackError", LapackError);
- return RETVAL;
+ return RETVAL(m);
}
diff --git a/numpy/linalg/umath_linalg.c.src b/numpy/linalg/umath_linalg.c.src
index 0248518ac..5fd4dcc29 100644
--- a/numpy/linalg/umath_linalg.c.src
+++ b/numpy/linalg/umath_linalg.c.src
@@ -3251,10 +3251,10 @@ static struct PyModuleDef moduledef = {
#endif
#if defined(NPY_PY3K)
-#define RETVAL m
+#define RETVAL(x) x
PyObject *PyInit__umath_linalg(void)
#else
-#define RETVAL
+#define RETVAL(x)
PyMODINIT_FUNC
init_umath_linalg(void)
#endif
@@ -3270,7 +3270,7 @@ init_umath_linalg(void)
m = Py_InitModule(UMATH_LINALG_MODULE_NAME, UMath_LinAlgMethods);
#endif
if (m == NULL) {
- return RETVAL;
+ return RETVAL(NULL);
}
import_array();
@@ -3288,7 +3288,8 @@ init_umath_linalg(void)
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"cannot load _umath_linalg module.");
+ return RETVAL(NULL);
}
- return RETVAL;
+ return RETVAL(m);
}