Commit 2e6c8296 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #20440: More use of Py_SETREF.

This patch is manually crafted and contains changes that couldn't be handled
automatically.
parent 8688acaf
......@@ -3081,10 +3081,9 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
"restype must be a type, a callable, or None");
return -1;
}
Py_XDECREF(self->checker);
Py_INCREF(ob);
Py_SETREF(self->restype, ob);
self->checker = PyObject_GetAttrString(ob, "_check_retval_");
Py_SETREF(self->checker, PyObject_GetAttrString(ob, "_check_retval_"));
if (self->checker == NULL)
PyErr_Clear();
return 0;
......
......@@ -1573,9 +1573,8 @@ element_setattr(ElementObject* self, const char* name, PyObject* value)
}
if (strcmp(name, "tag") == 0) {
Py_DECREF(self->tag);
self->tag = value;
Py_INCREF(self->tag);
Py_INCREF(value);
Py_SETREF(self->tag, value);
} else if (strcmp(name, "text") == 0) {
Py_DECREF(JOIN_OBJ(self->text));
self->text = value;
......@@ -1587,9 +1586,8 @@ element_setattr(ElementObject* self, const char* name, PyObject* value)
} else if (strcmp(name, "attrib") == 0) {
if (!self->extra)
element_new_extra(self, NULL);
Py_DECREF(self->extra->attrib);
self->extra->attrib = value;
Py_INCREF(self->extra->attrib);
Py_INCREF(value);
Py_SETREF(self->extra->attrib, value);
} else {
PyErr_SetString(PyExc_AttributeError, name);
return -1;
......@@ -1800,13 +1798,11 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
}
self->index++;
Py_DECREF(this);
Py_INCREF(node);
self->this = (ElementObject*) node;
Py_SETREF(self->this, (ElementObject*) node);
Py_DECREF(self->last);
Py_INCREF(node);
self->last = (ElementObject*) node;
Py_SETREF(self->last, (ElementObject*) node);
if (treebuilder_append_event(self, self->start_event_obj, node) < 0)
goto error;
......@@ -1857,7 +1853,7 @@ treebuilder_handle_data(TreeBuilderObject* self, PyObject* data)
LOCAL(PyObject*)
treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
{
PyObject* item;
ElementObject *item;
if (self->data) {
if (self->this == self->last) {
......@@ -1882,15 +1878,12 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
return NULL;
}
item = self->last;
self->last = self->this;
self->index--;
item = PyList_GET_ITEM(self->stack, self->index);
Py_INCREF(item);
Py_DECREF(self->last);
self->last = (ElementObject*) self->this;
self->this = (ElementObject*) item;
self->this = (ElementObject *) PyList_GET_ITEM(self->stack, self->index);
Py_INCREF(self->this);
Py_DECREF(item);
if (treebuilder_append_event(self, self->end_event_obj, (PyObject*)self->last) < 0)
return NULL;
......
......@@ -558,10 +558,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
Py_DECREF(self->statement);
}
self->statement = (pysqlite_Statement*)pysqlite_cache_get(self->connection->statement_cache, func_args);
Py_SETREF(self->statement,
(pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args));
Py_DECREF(func_args);
if (!self->statement) {
......
......@@ -731,11 +731,9 @@ PyZlib_copy(compobject *self)
}
Py_INCREF(self->unused_data);
Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail);
Py_XDECREF(retval->unused_data);
Py_XDECREF(retval->unconsumed_tail);
retval->unused_data = self->unused_data;
retval->unconsumed_tail = self->unconsumed_tail;
Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
/* Mark it as being initialized */
retval->is_initialised = 1;
......@@ -782,11 +780,9 @@ PyZlib_uncopy(compobject *self)
}
Py_INCREF(self->unused_data);
Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail);
Py_XDECREF(retval->unused_data);
Py_XDECREF(retval->unconsumed_tail);
retval->unused_data = self->unused_data;
retval->unconsumed_tail = self->unconsumed_tail;
Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
/* Mark it as being initialized */
retval->is_initialised = 1;
......
......@@ -517,12 +517,14 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
if (size == 0)
return 0;
Py_CLEAR(self->code);
if (size == 1)
self->code = PyTuple_GET_ITEM(args, 0);
else if (size > 1)
self->code = args;
Py_INCREF(self->code);
if (size == 1) {
Py_INCREF(PyTuple_GET_ITEM(args, 0));
Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0));
}
else { /* size > 1 */
Py_INCREF(args);
Py_SETREF(self->code, args);
}
return 0;
}
......
......@@ -227,14 +227,11 @@ finally:
tstate = PyThreadState_GET();
if (++tstate->recursion_depth > Py_GetRecursionLimit()) {
--tstate->recursion_depth;
/* throw away the old exception... */
Py_DECREF(*exc);
Py_DECREF(*val);
/* ... and use the recursion error instead */
*exc = PyExc_RuntimeError;
*val = PyExc_RecursionErrorInst;
Py_INCREF(*exc);
Py_INCREF(*val);
/* throw away the old exception and use the recursion error instead */
Py_INCREF(PyExc_RuntimeError);
Py_SETREF(*exc, PyExc_RuntimeError);
Py_INCREF(PyExc_RecursionErrorInst);
Py_SETREF(*val, PyExc_RecursionErrorInst);
/* just keeping the old traceback */
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment