diff options
| author | mattip <matti.picus@gmail.com> | 2022-03-03 11:43:42 +0200 |
|---|---|---|
| committer | mattip <matti.picus@gmail.com> | 2022-03-03 11:43:42 +0200 |
| commit | 36d99af6770d3c12d6e489fb2435053b5f1b461f (patch) | |
| tree | 0a0bf421cb65373a01cd9deb29be9ee09ea28453 | |
| parent | b7529e6bac6e7b8a785aa0e1612aa54927adac41 (diff) | |
| download | numpy-36d99af6770d3c12d6e489fb2435053b5f1b461f.tar.gz | |
BUG: assign all tuple items before using it for PyPy
| -rw-r--r-- | numpy/core/src/multiarray/dtypemeta.c | 16 |
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); |
