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/Modules/pyexpat.c b/Modules/pyexpat.c
index 9267c69..c6d3515 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1226,12 +1226,8 @@
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 @@
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 @@
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 @@
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);
}
}