summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2022-03-03 11:43:42 +0200
committermattip <matti.picus@gmail.com>2022-03-03 11:43:42 +0200
commit36d99af6770d3c12d6e489fb2435053b5f1b461f (patch)
tree0a0bf421cb65373a01cd9deb29be9ee09ea28453
parentb7529e6bac6e7b8a785aa0e1612aa54927adac41 (diff)
downloadnumpy-36d99af6770d3c12d6e489fb2435053b5f1b461f.tar.gz
BUG: assign all tuple items before using it for PyPy
-rw-r--r--numpy/core/src/multiarray/dtypemeta.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/dtypemeta.c b/numpy/core/src/multiarray/dtypemeta.c
index 519b998d7..bee8e8cdf 100644
--- a/numpy/core/src/multiarray/dtypemeta.c
+++ b/numpy/core/src/multiarray/dtypemeta.c
@@ -366,21 +366,23 @@ void_ensure_canonical(PyArray_Descr *self)
return NULL;
}
PyTuple_SET_ITEM(new_tuple, 1, (PyObject *)offset_obj);
- if (PyDict_SetItem(new->fields, name, new_tuple) < 0) {
- Py_DECREF(new_tuple);
- Py_DECREF(new);
- return NULL;
- }
- Py_DECREF(new_tuple); /* Reference now owned by new->fields */
- if (PyTuple_GET_SIZE(new_tuple) == 3) {
+ if (PyTuple_GET_SIZE(tuple) == 3) {
+ /* Be sure to set all items in the tuple before using it */
PyObject *title = PyTuple_GET_ITEM(tuple, 2);
Py_INCREF(title);
PyTuple_SET_ITEM(new_tuple, 2, title);
if (PyDict_SetItem(new->fields, title, new_tuple) < 0) {
+ Py_DECREF(new_tuple);
Py_DECREF(new);
return NULL;
}
}
+ if (PyDict_SetItem(new->fields, name, new_tuple) < 0) {
+ Py_DECREF(new_tuple);
+ Py_DECREF(new);
+ return NULL;
+ }
+ Py_DECREF(new_tuple); /* Reference now owned by new->fields */
totalsize += field_descr->elsize;
}
totalsize = NPY_NEXT_ALIGNED_OFFSET(totalsize, maxalign);