summaryrefslogtreecommitdiff
path: root/Modules/pyexpat.c
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 /Modules/pyexpat.c
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 'Modules/pyexpat.c')
-rw-r--r--Modules/pyexpat.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 9267c69e19..c6d35150b3 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1226,12 +1226,8 @@ xmlparse_dealloc(xmlparseobject *self)
self->itself = NULL;
if (self->handlers != NULL) {
- PyObject *temp;
- for (i = 0; handler_info[i].name != NULL; i++) {
- temp = self->handlers[i];
- self->handlers[i] = NULL;
- Py_XDECREF(temp);
- }
+ for (i = 0; handler_info[i].name != NULL; i++)
+ Py_CLEAR(self->handlers[i]);
PyMem_Free(self->handlers);
self->handlers = NULL;
}
@@ -1345,7 +1341,6 @@ sethandler(xmlparseobject *self, PyObject *name, PyObject* v)
int handlernum = handlername2int(name);
if (handlernum >= 0) {
xmlhandler c_handler = NULL;
- PyObject *temp = self->handlers[handlernum];
if (v == Py_None) {
/* If this is the character data handler, and a character
@@ -1367,8 +1362,7 @@ sethandler(xmlparseobject *self, PyObject *name, PyObject* v)
Py_INCREF(v);
c_handler = handler_info[handlernum].handler;
}
- self->handlers[handlernum] = v;
- Py_XDECREF(temp);
+ Py_SETREF(self->handlers[handlernum], v);
handler_info[handlernum].setter(self->itself, c_handler);
return 1;
}
@@ -1898,15 +1892,12 @@ static void
clear_handlers(xmlparseobject *self, int initial)
{
int i = 0;
- PyObject *temp;
for (; handler_info[i].name != NULL; i++) {
if (initial)
self->handlers[i] = NULL;
else {
- temp = self->handlers[i];
- self->handlers[i] = NULL;
- Py_XDECREF(temp);
+ Py_CLEAR(self->handlers[i]);
handler_info[i].setter(self->itself, NULL);
}
}