summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-01-08 01:40:17 +0000
committerEric Wieser <wieser.eric@gmail.com>2020-01-08 01:44:34 +0000
commit9ec102e51388a431263ffc858f941992c50395b4 (patch)
treec5f92bd0b8666bdca2147943a9b1d74d683ae200 /numpy
parent7d159b48a1c98159ff1623b33abbd408a11df1f6 (diff)
downloadnumpy-9ec102e51388a431263ffc858f941992c50395b4.tar.gz
MAINT: Push down declarations in _convert_from_array_descr
This makes it easier to reason about which variables contain mutable state. C99 makes some of this possible, while other parts were already possible.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/descriptor.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 9a242033d..43ac25a19 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -422,29 +422,24 @@ _convert_from_tuple(PyObject *obj, int align)
static PyArray_Descr *
_convert_from_array_descr(PyObject *obj, int align)
{
- int n, i, totalsize;
- PyObject *fields, *item, *newobj;
- PyObject *name, *tup, *title;
- PyObject *nameslist;
- PyArray_Descr *new;
- PyArray_Descr *conv;
- /* Types with fields need the Python C API for field access */
- char dtypeflags = NPY_NEEDS_PYAPI;
- int maxalign = 0;
-
- n = PyList_GET_SIZE(obj);
- nameslist = PyTuple_New(n);
+ int n = PyList_GET_SIZE(obj);
+ PyObject *nameslist = PyTuple_New(n);
if (!nameslist) {
return NULL;
}
- totalsize = 0;
- fields = PyDict_New();
- for (i = 0; i < n; i++) {
- item = PyList_GET_ITEM(obj, i);
+
+ /* Types with fields need the Python C API for field access */
+ char dtypeflags = NPY_NEEDS_PYAPI;
+ int maxalign = 0;
+ int totalsize = 0;
+ PyObject *fields = PyDict_New();
+ for (int i = 0; i < n; i++) {
+ PyObject *item = PyList_GET_ITEM(obj, i);
if (!PyTuple_Check(item) || (PyTuple_GET_SIZE(item) < 2)) {
goto fail;
}
- name = PyTuple_GET_ITEM(item, 0);
+ PyObject *name = PyTuple_GET_ITEM(item, 0);
+ PyObject *title;
if (PyBaseString_Check(name)) {
title = NULL;
}
@@ -500,7 +495,7 @@ _convert_from_array_descr(PyObject *obj, int align)
PyTuple_SET_ITEM(nameslist, i, name);
/* Process rest */
-
+ PyArray_Descr *conv;
if (PyTuple_GET_SIZE(item) == 2) {
conv = _arraydescr_run_converter(PyTuple_GET_ITEM(item, 1), align);
if (conv == NULL) {
@@ -508,7 +503,7 @@ _convert_from_array_descr(PyObject *obj, int align)
}
}
else if (PyTuple_GET_SIZE(item) == 3) {
- newobj = PyTuple_GetSlice(item, 1, 3);
+ PyObject *newobj = PyTuple_GetSlice(item, 1, 3);
conv = _arraydescr_run_converter(newobj, align);
Py_DECREF(newobj);
if (conv == NULL) {
@@ -543,7 +538,7 @@ _convert_from_array_descr(PyObject *obj, int align)
}
maxalign = PyArray_MAX(maxalign, _align);
}
- tup = PyTuple_New((title == NULL ? 2 : 3));
+ PyObject *tup = PyTuple_New((title == NULL ? 2 : 3));
PyTuple_SET_ITEM(tup, 0, (PyObject *)conv);
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));
@@ -578,7 +573,7 @@ _convert_from_array_descr(PyObject *obj, int align)
totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, maxalign);
}
- new = PyArray_DescrNewFromType(NPY_VOID);
+ PyArray_Descr *new = PyArray_DescrNewFromType(NPY_VOID);
if (new == NULL) {
Py_XDECREF(fields);
Py_XDECREF(nameslist);