summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-27 13:51:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-27 13:51:32 (GMT)
commit1ed017ae92b32b27186d5793f6e58c526f350a2b (patch)
tree05fec1ee9e107911f46d85f86efcabce50ff5680 /Objects/listobject.c
parent726fc139a5f40d81a0013c856be1283da08de4a0 (diff)
downloadcpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.zip
cpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.tar.gz
cpython-1ed017ae92b32b27186d5793f6e58c526f350a2b.tar.bz2
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.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index eee7c68..fcc21cb 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -216,7 +216,6 @@ int
PyList_SetItem(PyObject *op, Py_ssize_t i,
PyObject *newitem)
{
- PyObject *olditem;
PyObject **p;
if (!PyList_Check(op)) {
Py_XDECREF(newitem);
@@ -230,9 +229,7 @@ PyList_SetItem(PyObject *op, Py_ssize_t i,
return -1;
}
p = ((PyListObject *)op) -> ob_item + i;
- olditem = *p;
- *p = newitem;
- Py_XDECREF(olditem);
+ Py_SETREF(*p, newitem);
return 0;
}
@@ -730,7 +727,6 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
static int
list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
{
- PyObject *old_value;
if (i < 0 || i >= Py_SIZE(a)) {
PyErr_SetString(PyExc_IndexError,
"list assignment index out of range");
@@ -739,9 +735,7 @@ list_ass_item(PyListObject *a, Py_ssize_t i, PyObject *v)
if (v == NULL)
return list_ass_slice(a, i, i+1, v);
Py_INCREF(v);
- old_value = a->ob_item[i];
- a->ob_item[i] = v;
- Py_DECREF(old_value);
+ Py_SETREF(a->ob_item[i], v);
return 0;
}