Commit 191321d1 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 4a1e70fc
...@@ -2983,10 +2983,9 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob) ...@@ -2983,10 +2983,9 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
"restype must be a type, a callable, or None"); "restype must be a type, a callable, or None");
return -1; return -1;
} }
Py_XDECREF(self->checker);
Py_INCREF(ob); Py_INCREF(ob);
Py_SETREF(self->restype, 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) if (self->checker == NULL)
PyErr_Clear(); PyErr_Clear();
return 0; return 0;
......
...@@ -935,9 +935,8 @@ element_setstate_from_attributes(ElementObject *self, ...@@ -935,9 +935,8 @@ element_setstate_from_attributes(ElementObject *self,
return NULL; return NULL;
} }
Py_CLEAR(self->tag); Py_INCREF(tag);
self->tag = tag; Py_SETREF(self->tag, tag);
Py_INCREF(self->tag);
_clear_joined_ptr(&self->text); _clear_joined_ptr(&self->text);
self->text = text ? JOIN_SET(text, PyList_CheckExact(text)) : Py_None; self->text = text ? JOIN_SET(text, PyList_CheckExact(text)) : Py_None;
...@@ -980,9 +979,8 @@ element_setstate_from_attributes(ElementObject *self, ...@@ -980,9 +979,8 @@ element_setstate_from_attributes(ElementObject *self,
/* Stash attrib. */ /* Stash attrib. */
if (attrib) { if (attrib) {
Py_CLEAR(self->extra->attrib);
self->extra->attrib = attrib;
Py_INCREF(attrib); Py_INCREF(attrib);
Py_SETREF(self->extra->attrib, attrib);
} }
Py_RETURN_NONE; Py_RETURN_NONE;
...@@ -1944,9 +1942,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value) ...@@ -1944,9 +1942,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
return -1; return -1;
if (strcmp(name, "tag") == 0) { if (strcmp(name, "tag") == 0) {
Py_DECREF(self->tag); Py_INCREF(value);
self->tag = value; Py_SETREF(self->tag, value);
Py_INCREF(self->tag);
} else if (strcmp(name, "text") == 0) { } else if (strcmp(name, "text") == 0) {
Py_DECREF(JOIN_OBJ(self->text)); Py_DECREF(JOIN_OBJ(self->text));
self->text = value; self->text = value;
...@@ -1960,9 +1957,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value) ...@@ -1960,9 +1957,8 @@ element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value)
if (create_extra(self, NULL) < 0) if (create_extra(self, NULL) < 0)
return -1; return -1;
} }
Py_DECREF(self->extra->attrib); Py_INCREF(value);
self->extra->attrib = value; Py_SETREF(self->extra->attrib, value);
Py_INCREF(self->extra->attrib);
} else { } else {
PyErr_SetString(PyExc_AttributeError, PyErr_SetString(PyExc_AttributeError,
"Can't set arbitrary attributes on Element"); "Can't set arbitrary attributes on Element");
...@@ -2554,13 +2550,10 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag, ...@@ -2554,13 +2550,10 @@ treebuilder_handle_start(TreeBuilderObject* self, PyObject* tag,
} }
self->index++; self->index++;
Py_DECREF(this);
Py_INCREF(node); Py_INCREF(node);
self->this = node; Py_SETREF(self->this, node);
Py_DECREF(self->last);
Py_INCREF(node); Py_INCREF(node);
self->last = node; Py_SETREF(self->last, node);
if (treebuilder_append_event(self, self->start_event_obj, node) < 0) if (treebuilder_append_event(self, self->start_event_obj, node) < 0)
goto error; goto error;
...@@ -2633,15 +2626,12 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag) ...@@ -2633,15 +2626,12 @@ treebuilder_handle_end(TreeBuilderObject* self, PyObject* tag)
return NULL; return NULL;
} }
self->index--; item = self->last;
item = PyList_GET_ITEM(self->stack, self->index);
Py_INCREF(item);
Py_DECREF(self->last);
self->last = self->this; self->last = self->this;
self->this = item; self->index--;
self->this = PyList_GET_ITEM(self->stack, self->index);
Py_INCREF(self->this);
Py_DECREF(item);
if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0) if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0)
return NULL; return NULL;
......
...@@ -524,10 +524,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* ...@@ -524,10 +524,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
if (self->statement) { if (self->statement) {
(void)pysqlite_statement_reset(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); Py_DECREF(func_args);
if (!self->statement) { if (!self->statement) {
......
...@@ -961,14 +961,11 @@ zlib_Compress_copy_impl(compobject *self) ...@@ -961,14 +961,11 @@ zlib_Compress_copy_impl(compobject *self)
goto error; goto error;
} }
Py_INCREF(self->unused_data); Py_INCREF(self->unused_data);
Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail); Py_INCREF(self->unconsumed_tail);
Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
Py_XINCREF(self->zdict); Py_XINCREF(self->zdict);
Py_XDECREF(retval->unused_data); Py_SETREF(retval->zdict, self->zdict);
Py_XDECREF(retval->unconsumed_tail);
Py_XDECREF(retval->zdict);
retval->unused_data = self->unused_data;
retval->unconsumed_tail = self->unconsumed_tail;
retval->zdict = self->zdict;
retval->eof = self->eof; retval->eof = self->eof;
/* Mark it as being initialized */ /* Mark it as being initialized */
...@@ -1020,14 +1017,11 @@ zlib_Decompress_copy_impl(compobject *self) ...@@ -1020,14 +1017,11 @@ zlib_Decompress_copy_impl(compobject *self)
} }
Py_INCREF(self->unused_data); Py_INCREF(self->unused_data);
Py_SETREF(retval->unused_data, self->unused_data);
Py_INCREF(self->unconsumed_tail); Py_INCREF(self->unconsumed_tail);
Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail);
Py_XINCREF(self->zdict); Py_XINCREF(self->zdict);
Py_XDECREF(retval->unused_data); Py_SETREF(retval->zdict, self->zdict);
Py_XDECREF(retval->unconsumed_tail);
Py_XDECREF(retval->zdict);
retval->unused_data = self->unused_data;
retval->unconsumed_tail = self->unconsumed_tail;
retval->zdict = self->zdict;
retval->eof = self->eof; retval->eof = self->eof;
/* Mark it as being initialized */ /* Mark it as being initialized */
......
...@@ -561,12 +561,14 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds) ...@@ -561,12 +561,14 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
if (size == 0) if (size == 0)
return 0; return 0;
Py_CLEAR(self->code); if (size == 1) {
if (size == 1) Py_INCREF(PyTuple_GET_ITEM(args, 0));
self->code = PyTuple_GET_ITEM(args, 0); Py_SETREF(self->code, PyTuple_GET_ITEM(args, 0));
else /* size > 1 */ }
self->code = args; else { /* size > 1 */
Py_INCREF(self->code); Py_INCREF(args);
Py_SETREF(self->code, args);
}
return 0; return 0;
} }
...@@ -625,9 +627,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) ...@@ -625,9 +627,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
#define GET_KWD(kwd) { \ #define GET_KWD(kwd) { \
kwd = PyDict_GetItemString(kwds, #kwd); \ kwd = PyDict_GetItemString(kwds, #kwd); \
if (kwd) { \ if (kwd) { \
Py_CLEAR(self->kwd); \ Py_INCREF(kwd); \
self->kwd = kwd; \ Py_SETREF(self->kwd, kwd); \
Py_INCREF(self->kwd);\
if (PyDict_DelItemString(kwds, #kwd)) \ if (PyDict_DelItemString(kwds, #kwd)) \
return -1; \ return -1; \
} \ } \
......
...@@ -14191,8 +14191,8 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx, ...@@ -14191,8 +14191,8 @@ unicode_format_arg_parse(struct unicode_formatter_t *ctx,
if (key == NULL) if (key == NULL)
return -1; return -1;
if (ctx->args_owned) { if (ctx->args_owned) {
Py_DECREF(ctx->args);
ctx->args_owned = 0; ctx->args_owned = 0;
Py_DECREF(ctx->args);
} }
ctx->args = PyObject_GetItem(ctx->dict, key); ctx->args = PyObject_GetItem(ctx->dict, key);
Py_DECREF(key); Py_DECREF(key);
......
...@@ -315,14 +315,11 @@ finally: ...@@ -315,14 +315,11 @@ finally:
tstate = PyThreadState_GET(); tstate = PyThreadState_GET();
if (++tstate->recursion_depth > Py_GetRecursionLimit()) { if (++tstate->recursion_depth > Py_GetRecursionLimit()) {
--tstate->recursion_depth; --tstate->recursion_depth;
/* throw away the old exception... */ /* throw away the old exception and use the recursion error instead */
Py_DECREF(*exc); Py_INCREF(PyExc_RecursionError);
Py_DECREF(*val); Py_SETREF(*exc, PyExc_RecursionError);
/* ... and use the recursion error instead */ Py_INCREF(PyExc_RecursionErrorInst);
*exc = PyExc_RecursionError; Py_SETREF(*val, PyExc_RecursionErrorInst);
*val = PyExc_RecursionErrorInst;
Py_INCREF(*exc);
Py_INCREF(*val);
/* just keeping the old traceback */ /* just keeping the old traceback */
return; 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