Skip to content

Commit c9fc389

Browse files
authored
Merge pull request numpy#26119 from ngoldbaum/refcnt-fix
BUG: fix reference counting error in stringdtype setup
2 parents 70d8d7e + dcdc91f commit c9fc389

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

numpy/_core/src/umath/stringdtype_ufuncs.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,16 +2102,16 @@ add_promoter(PyObject *numpy, const char *ufunc_name,
21022102

21032103
PyObject *DType_tuple = PyTuple_New(n_dtypes);
21042104

2105-
for (size_t i=0; i<n_dtypes; i++) {
2106-
PyTuple_SET_ITEM(DType_tuple, i, (PyObject *)dtypes[i]);
2107-
}
2108-
2109-
21102105
if (DType_tuple == NULL) {
21112106
Py_DECREF(ufunc);
21122107
return -1;
21132108
}
21142109

2110+
for (size_t i=0; i<n_dtypes; i++) {
2111+
Py_INCREF((PyObject *)dtypes[i]);
2112+
PyTuple_SET_ITEM(DType_tuple, i, (PyObject *)dtypes[i]);
2113+
}
2114+
21152115
PyObject *promoter_capsule = PyCapsule_New((void *)promoter_impl,
21162116
"numpy._ufunc_promoter", NULL);
21172117

0 commit comments

Comments
 (0)