diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-04-19 23:31:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 23:31:35 -0700 |
commit | f6c4dacc3b8f6dda3920a5ae6ebe48758a47e00d (patch) | |
tree | 774eb39cc43658725fa7a4c35d6fb4678449d811 /numpy | |
parent | a9e9343ecf5a6564eb09f1d7078c407db2ff7d9e (diff) | |
parent | 2a6565c6432c682c2798e75d48adc587da661822 (diff) | |
download | numpy-f6c4dacc3b8f6dda3920a5ae6ebe48758a47e00d.tar.gz |
Merge pull request #10775 from mdboom/return-errors-from-init
BUG: Return NULL from PyInit_* when exception is raised
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 31 | ||||
-rw-r--r-- | numpy/core/src/umath/umathmodule.c | 14 | ||||
-rw-r--r-- | numpy/fft/fftpack_litemodule.c | 9 | ||||
-rw-r--r-- | numpy/linalg/lapack_litemodule.c | 8 | ||||
-rw-r--r-- | numpy/linalg/umath_linalg.c.src | 9 |
5 files changed, 40 insertions, 31 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 0008cb04b..7eccb4a4b 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4732,10 +4732,10 @@ static struct PyModuleDef moduledef = { /* Initialization function for the module */ #if defined(NPY_PY3K) -#define RETVAL m +#define RETVAL(x) x PyMODINIT_FUNC PyInit_multiarray(void) { #else -#define RETVAL +#define RETVAL(x) PyMODINIT_FUNC initmultiarray(void) { #endif PyObject *m, *d, *s; @@ -4763,6 +4763,10 @@ PyMODINIT_FUNC initmultiarray(void) { /* Initialize access to the PyDateTime API */ numpy_pydatetime_import(); + if (PyErr_Occurred()) { + goto err; + } + /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); if (!d) { @@ -4776,7 +4780,7 @@ PyMODINIT_FUNC initmultiarray(void) { */ PyArray_Type.tp_hash = PyObject_HashNotImplemented; if (PyType_Ready(&PyArray_Type) < 0) { - return RETVAL; + goto err; } if (setup_scalartypes(d) < 0) { goto err; @@ -4786,32 +4790,32 @@ PyMODINIT_FUNC initmultiarray(void) { PyArrayMultiIter_Type.tp_iter = PyObject_SelfIter; PyArrayMultiIter_Type.tp_free = PyArray_free; if (PyType_Ready(&PyArrayIter_Type) < 0) { - return RETVAL; + goto err; } if (PyType_Ready(&PyArrayMapIter_Type) < 0) { - return RETVAL; + goto err; } if (PyType_Ready(&PyArrayMultiIter_Type) < 0) { - return RETVAL; + goto err; } PyArrayNeighborhoodIter_Type.tp_new = PyType_GenericNew; if (PyType_Ready(&PyArrayNeighborhoodIter_Type) < 0) { - return RETVAL; + goto err; } if (PyType_Ready(&NpyIter_Type) < 0) { - return RETVAL; + goto err; } PyArrayDescr_Type.tp_hash = PyArray_DescrHash; if (PyType_Ready(&PyArrayDescr_Type) < 0) { - return RETVAL; + goto err; } if (PyType_Ready(&PyArrayFlags_Type) < 0) { - return RETVAL; + goto err; } NpyBusDayCalendar_Type.tp_new = PyType_GenericNew; if (PyType_Ready(&NpyBusDayCalendar_Type) < 0) { - return RETVAL; + goto err; } c_api = NpyCapsule_FromVoidPtr((void *)PyArray_API, NULL); @@ -4897,12 +4901,13 @@ PyMODINIT_FUNC initmultiarray(void) { if (set_typeinfo(d) != 0) { goto err; } - return RETVAL; + + return RETVAL(m); err: if (!PyErr_Occurred()) { PyErr_SetString(PyExc_RuntimeError, "cannot load multiarray module."); } - return RETVAL; + return RETVAL(NULL); } diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c index 03bf5bfd8..15da831b2 100644 --- a/numpy/core/src/umath/umathmodule.c +++ b/numpy/core/src/umath/umathmodule.c @@ -310,10 +310,10 @@ static struct PyModuleDef moduledef = { #include <stdio.h> #if defined(NPY_PY3K) -#define RETVAL m +#define RETVAL(x) x PyMODINIT_FUNC PyInit_umath(void) #else -#define RETVAL +#define RETVAL(x) PyMODINIT_FUNC initumath(void) #endif { @@ -330,7 +330,7 @@ PyMODINIT_FUNC initumath(void) m = Py_InitModule("umath", methods); #endif if (!m) { - return RETVAL; + goto err; } /* Import the array */ @@ -339,12 +339,12 @@ PyMODINIT_FUNC initumath(void) PyErr_SetString(PyExc_ImportError, "umath failed: Could not import array core."); } - return RETVAL; + goto err; } /* Initialize the types */ if (PyType_Ready(&PyUFunc_Type) < 0) - return RETVAL; + goto err; /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); @@ -426,7 +426,7 @@ PyMODINIT_FUNC initumath(void) goto err; } - return RETVAL; + return RETVAL(m); err: /* Check for errors */ @@ -434,5 +434,5 @@ PyMODINIT_FUNC initumath(void) PyErr_SetString(PyExc_RuntimeError, "cannot load umath module."); } - return RETVAL; + return RETVAL(NULL); } diff --git a/numpy/fft/fftpack_litemodule.c b/numpy/fft/fftpack_litemodule.c index dfa0d211b..bd6cfc120 100644 --- a/numpy/fft/fftpack_litemodule.c +++ b/numpy/fft/fftpack_litemodule.c @@ -330,10 +330,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_fftpack_lite(void) #else -#define RETVAL +#define RETVAL(x) PyMODINIT_FUNC initfftpack_lite(void) #endif @@ -348,6 +348,9 @@ initfftpack_lite(void) fftpack_module_documentation, (PyObject*)NULL,PYTHON_API_VERSION); #endif + if (m == NULL) { + return RETVAL(NULL); + } /* Import the array object */ import_array(); @@ -359,5 +362,5 @@ initfftpack_lite(void) /* XXXX Add constants here */ - return RETVAL; + return RETVAL(m); } 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 d8cfdf6ac..c43a4a48e 100644 --- a/numpy/linalg/umath_linalg.c.src +++ b/numpy/linalg/umath_linalg.c.src @@ -3659,10 +3659,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 @@ -3678,7 +3678,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(); @@ -3696,7 +3696,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); } |