8000 BUG: reference count exposed by better testing · r-devulap/numpy@787baad · GitHub
[go: up one dir, main page]

Skip to content

Commit 787baad

Browse files
mhvkcharris
authored andcommitted
BUG: reference count exposed by better testing
Also for __array_ufunc__ overrides, sig and signature cannot be passed in both. This was incorrectly coded and slipped through as it was not tested.
1 parent c49b7e3 commit 787baad

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

numpy/core/src/umath/override.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ normalize_signature_keyword(PyObject *normal_kwds)
2929
"cannot specify both 'sig' and 'signature'");
3030
return -1;
3131
}
32-
Py_INCREF(obj);
32+
/*
33+
* No INCREF or DECREF needed: got a borrowed reference above,
34+
* and, unlike e.g. PyList_SetItem, PyDict_SetItem INCREF's it.
35+
*/
3336
PyDict_SetItemString(normal_kwds, "signature", obj);
3437
PyDict_DelItemString(normal_kwds, "sig");
3538
}
@@ -282,7 +285,6 @@ normalize_outer_args(PyUFuncObject *ufunc, PyObject *args,
282285
if (*normal_args == NULL) {
283286
return -1;
284287
}
285-
286288
/* ufuncs accept 'sig' or 'signature' normalize to 'signature' */
287289
return normalize_signature_keyword(*normal_kwds);
288290
}

numpy/core/tests/test_umath.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
18761876
# outer, wrong args
18771877
assert_raises(TypeError, np.multiply.outer, a)
18781878
assert_raises(TypeError, np.multiply.outer, a, a, a, a)
1879+
assert_raises(TypeError, np.multiply.outer, a, a, sig='a', signature='a')
18791880

18801881
# at
18811882
res = np.multiply.at(a, [4, 2], 'b0')

0 commit comments

Comments
 (0)
0