Skip to content

Commit 35bce08

Browse files
authored
Merge pull request numpy#26246 from ngoldbaum/list-getitemref
MNT: migrate PyList_GetItem usages to PyList_GetItemRef
2 parents cad9171 + 21b0d4c commit 35bce08

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

numpy/_core/src/umath/dispatching.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "numpy/ndarraytypes.h"
4646
#include "numpy/npy_3kcompat.h"
4747
#include "common.h"
48+
#include "npy_pycompat.h"
4849

4950
#include "dispatching.h"
5051
#include "dtypemeta.h"
@@ -121,8 +122,9 @@ PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate)
121122
PyObject *loops = ufunc->_loops;
122123
Py_ssize_t length = PyList_Size(loops);
123124
for (Py_ssize_t i = 0; i < length; i++) {
124-
PyObject *item = PyList_GetItem(loops, i);
125+
PyObject *item = PyList_GetItemRef(loops, i);
125126
PyObject *cur_DType_tuple = PyTuple_GetItem(item, 0);
127+
Py_DECREF(item);
126128
int cmp = PyObject_RichCompareBool(cur_DType_tuple, DType_tuple, Py_EQ);
127129
if (cmp < 0) {
128130
return -1;
@@ -1277,8 +1279,9 @@ get_info_no_cast(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtype,
12771279
PyObject *loops = ufunc->_loops;
12781280
Py_ssize_t length = PyList_Size(loops);
12791281
for (Py_ssize_t i = 0; i < length; i++) {
1280-
PyObject *item = PyList_GetItem(loops, i);
1282+
PyObject *item = PyList_GetItemRef(loops, i);
12811283
PyObject *cur_DType_tuple = PyTuple_GetItem(item, 0);
1284+
Py_DECREF(item);
12821285
int cmp = PyObject_RichCompareBool(cur_DType_tuple,
12831286
t_dtypes, Py_EQ);
12841287
if (cmp < 0) {

numpy/_core/src/umath/wrapping_array_method.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "numpy/ndarraytypes.h"
2828

29+
#include "npy_pycompat.h"
2930
#include "common.h"
3031
#include "array_method.h"
3132
#include "legacy_array_method.h"
@@ -250,8 +251,9 @@ PyUFunc_AddWrappingLoop(PyObject *ufunc_obj,
250251
PyObject *loops = ufunc->_loops;
251252
Py_ssize_t length = PyList_Size(loops);
252253
for (Py_ssize_t i = 0; i < length; i++) {
253-
PyObject *item = PyList_GetItem(loops, i);
254+
PyObject *item = PyList_GetItemRef(loops, i);
254255
PyObject *cur_DType_tuple = PyTuple_GetItem(item, 0);
256+
Py_DECREF(item);
255257
int cmp = PyObject_RichCompareBool(cur_DType_tuple, wrapped_dt_tuple, Py_EQ);
256258
if (cmp < 0) {
257259
goto finish;

0 commit comments

Comments
 (0)