Issue #20440: Cleaning up the code by using Py_SETREF and Py_CLEAR.
Old code is correct, but with Py_SETREF and Py_CLEAR it can be cleaner.
This patch doesn't fix bugs and hence there is no need to backport it.
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 7efa1a6..8e1b00b 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -149,7 +149,6 @@
int
PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem)
{
- PyObject *olditem;
PyObject **p;
if (!PyTuple_Check(op) || op->ob_refcnt != 1) {
Py_XDECREF(newitem);
@@ -163,9 +162,7 @@
return -1;
}
p = ((PyTupleObject *)op) -> ob_item + i;
- olditem = *p;
- *p = newitem;
- Py_XDECREF(olditem);
+ Py_SETREF(*p, newitem);
return 0;
}