summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-05-13 10:54:57 +0000
committerPauli Virtanen <pav@iki.fi>2010-05-13 10:54:57 +0000
commit1ecf17b3d2399647c25746568981b44f1af4b039 (patch)
treef42d060ae7168e6066206b6c6abd88d871b5c52c
parent5b4964b395f7c7c032a1d87f98b3f82c6ff8510c (diff)
downloadnumpy-1ecf17b3d2399647c25746568981b44f1af4b039.tar.gz
STY: core: reduce code duplication in _import_umath and _import_array
-rw-r--r--numpy/core/code_generators/generate_numpy_api.py10
-rw-r--r--numpy/core/code_generators/generate_ufunc_api.py9
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;
}