summaryrefslogtreecommitdiff
path: root/Modules/_heapqmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-14 13:08:15 +0100
committerGitHub <noreply@github.com>2022-11-14 13:08:15 +0100
commit3817607b8a345851e4fa436747a346890ced33f1 (patch)
treebe135083ae53cef88b2187a5470cff46c68110ef /Modules/_heapqmodule.c
parentdb115682bd639a2642c617f0b7d5b30cd7d7f472 (diff)
downloadcpython-git-3817607b8a345851e4fa436747a346890ced33f1.tar.gz
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.
Diffstat (limited to 'Modules/_heapqmodule.c')
-rw-r--r--Modules/_heapqmodule.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 3dbaaa0a0d..07ddc7b085 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -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);