diff options
-rw-r--r-- | numpy/core/code_generators/generate_numpy_api.py | 10 | ||||
-rw-r--r-- | numpy/core/code_generators/generate_ufunc_api.py | 9 |
2 files changed, 5 insertions, 14 deletions
diff --git a/numpy/core/code_generators/generate_numpy_api.py b/numpy/core/code_generators/generate_numpy_api.py index 2997647ac..962007afc 100644 --- a/numpy/core/code_generators/generate_numpy_api.py +++ b/numpy/core/code_generators/generate_numpy_api.py @@ -57,12 +57,11 @@ _import_array(void) return -1; } c_api = PyObject_GetAttrString(numpy, "_ARRAY_API"); + Py_DECREF(numpy); if (c_api == NULL) { PyErr_SetString(PyExc_AttributeError, "_ARRAY_API not found"); - Py_DECREF(numpy); return -1; } - Py_DECREF(numpy); #if PY_VERSION_HEX >= 0x02070000 if (!PyCapsule_CheckExact(c_api)) { @@ -71,10 +70,6 @@ _import_array(void) return -1; } PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL); - Py_DECREF(c_api); - if (PyArray_API == NULL) { - return -1; - } #else if (!PyCObject_Check(c_api)) { PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCObject object"); @@ -82,12 +77,13 @@ _import_array(void) return -1; } PyArray_API = (void **)PyCObject_AsVoidPtr(c_api); +#endif Py_DECREF(c_api); if (PyArray_API == NULL) { PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer"); return -1; } -#endif + /* Perform runtime check of C API version */ if (NPY_VERSION != PyArray_GetNDArrayCVersion()) { PyErr_Format(PyExc_RuntimeError, "module compiled against "\ diff --git a/numpy/core/code_generators/generate_ufunc_api.py b/numpy/core/code_generators/generate_ufunc_api.py index 0ea502ddf..2559ff774 100644 --- a/numpy/core/code_generators/generate_ufunc_api.py +++ b/numpy/core/code_generators/generate_ufunc_api.py @@ -46,12 +46,11 @@ _import_umath(void) return -1; } c_api = PyObject_GetAttrString(numpy, "_UFUNC_API"); + Py_DECREF(numpy); if (c_api == NULL) { PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found"); - Py_DECREF(numpy); return -1; } - Py_DECREF(numpy); #if PY_VERSION_HEX >= 0x02070000 if (!PyCapsule_CheckExact(c_api)) { @@ -60,10 +59,6 @@ _import_umath(void) return -1; } PyUFunc_API = (void **)PyCapsule_GetPointer(c_api, NULL); - Py_DECREF(c_api); - if (PyUFunc_API == NULL) { - return -1; - } #else if (!PyCObject_Check(c_api)) { PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is not PyCObject object"); @@ -71,12 +66,12 @@ _import_umath(void) return -1; } PyUFunc_API = (void **)PyCObject_AsVoidPtr(c_api); +#endif Py_DECREF(c_api); if (PyUFunc_API == NULL) { PyErr_SetString(PyExc_RuntimeError, "_UFUNC_API is NULL pointer"); return -1; } -#endif return 0; } |