summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-27 15:51:32 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-27 15:51:32 +0200
commit1ed017ae92b32b27186d5793f6e58c526f350a2b (patch)
tree05fec1ee9e107911f46d85f86efcabce50ff5680 /Objects
parent726fc139a5f40d81a0013c856be1283da08de4a0 (diff)
downloadcpython-git-1ed017ae92b32b27186d5793f6e58c526f350a2b.tar.gz
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')
-rw-r--r--Objects/listobject.c10
-rw-r--r--Objects/tupleobject.c5
-rw-r--r--Objects/typeobject.c13
3 files changed, 5 insertions, 23 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index eee7c68e9e..fcc21cbebe 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;
}
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 7efa1a6776..8e1b00b63d 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -149,7 +149,6 @@ PyTuple_GetItem(PyObject *op, Py_ssize_t i)
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 @@ PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem)
return -1;
}
p = ((PyTupleObject *)op) -> ob_item + i;
- olditem = *p;
- *p = newitem;
- Py_XDECREF(olditem);
+ Py_SETREF(*p, newitem);
return 0;
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 4fac9e889b..78ef6acb13 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -401,7 +401,6 @@ type_qualname(PyTypeObject *type, void *context)
static int
type_set_name(PyTypeObject *type, PyObject *value, void *context)
{
- PyHeapTypeObject* et;
char *tp_name;
PyObject *tmp;
@@ -430,17 +429,9 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
if (tp_name == NULL)
return -1;
- et = (PyHeapTypeObject*)type;
-
- Py_INCREF(value);
-
- /* Wait until et is a sane state before Py_DECREF'ing the old et->ht_name
- value. (Bug #16447.) */
- tmp = et->ht_name;
- et->ht_name = value;
-
type->tp_name = tp_name;
- Py_DECREF(tmp);
+ Py_INCREF(value);
+ Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value);
return 0;
}