8000 BUG: fix choose refcount leak by charris · Pull Request #24328 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: Remove unnecessary (and now also segfaulting) iterator creation
Also hoist the `dtype` definition up and use it.
  • Loading branch information
seberg authored and charris committed Aug 3, 2023
commit 1c22bf76e6926d2ce84fba4a3241f6de5d64b76e
9 changes: 4 additions & 5 deletions numpy/core/src/multiarray/item_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,10 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
if (multi == NULL) {
goto fail;
}
dtype = PyArray_DESCR(mps[0]);

/* Set-up return array */
if (out == NULL) {
dtype = PyArray_DESCR(mps[0]);
Py_INCREF(dtype);
obj = (PyArrayObject *)PyArray_NewFromDescr(Py_TYPE(ap),
dtype,
Expand Down Expand Up @@ -1032,23 +1033,21 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *out,
*/
flags |= NPY_ARRAY_ENSURECOPY;
}
dtype = PyArray_DESCR(mps[0]);
Py_INCREF(dtype);
obj = (PyArrayObject *)PyArray_FromArray(out, dtype, flags);
}

if (obj == NULL) {
goto fail;
}
elsize = PyArray_DESCR(obj)->elsize;
elsize = dtype->elsize;
ret_data = PyArray_DATA(obj);
npy_intp transfer_strides[2] = {elsize, elsize};
npy_intp one = 1;
NPY_ARRAYMETHOD_FLAGS transfer_flags = 0;
NPY_cast_info cast_info = {.func = NULL};
if (PyDataType_REFCHK(dtype)) {
PyArrayIterObject *ind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);
int is_aligned = IsUintAligned(ind_it->ao);
int is_aligned = IsUintAligned(obj);
PyArray_GetDTypeTransferFunction(
is_aligned,
dtype->elsize,
Expand Down
0