gh-99300: Use Py_NewRef() in Modules/ directory (#99466)

Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in test C files of the Modules/ directory.
This commit is contained in:
Victor Stinner 2022-11-14 13:08:15 +01:00 committed by GitHub
parent db115682bd
commit 3817607b8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 214 deletions

View file

@ -197,8 +197,7 @@ heapreplace_internal(PyObject *heap, PyObject *item, int siftup_func(PyListObjec
}
returnitem = PyList_GET_ITEM(heap, 0);
Py_INCREF(item);
PyList_SET_ITEM(heap, 0, item);
PyList_SET_ITEM(heap, 0, Py_NewRef(item));
if (siftup_func((PyListObject *)heap, 0)) {
Py_DECREF(returnitem);
return NULL;
@ -253,8 +252,7 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
int cmp;
if (PyList_GET_SIZE(heap) == 0) {
Py_INCREF(item);
return item;
return Py_NewRef(item);
}
PyObject* top = PyList_GET_ITEM(heap, 0);
@ -264,8 +262,7 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
if (cmp < 0)
return NULL;
if (cmp == 0) {
Py_INCREF(item);
return item;
return Py_NewRef(item);
}
if (PyList_GET_SIZE(heap) == 0) {
@ -274,8 +271,7 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
}
returnitem = PyList_GET_ITEM(heap, 0);
Py_INCREF(item);
PyList_SET_ITEM(heap, 0, item);
PyList_SET_ITEM(heap, 0, Py_NewRef(item));
if (siftup((PyListObject *)heap, 0)) {
Py_DECREF(returnitem);
return NULL;
@ -410,8 +406,7 @@ siftdown_max(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
newitem = arr[pos];
while (pos > startpos) {
parentpos = (pos - 1) >> 1;
parent = arr[parentpos];
Py_INCREF(parent);
parent = Py_NewRef(arr[parentpos]);
Py_INCREF(newitem);
cmp = PyObject_RichCompareBool(parent, newitem, Py_LT);
Py_DECREF(parent);