diff -r c4e8751ce637 Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_collectionsmodule.c Thu Dec 24 10:58:52 2015 +0200 @@ -1222,7 +1222,6 @@ deque_del_item(dequeobject *deque, Py_ss static int deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v) { - PyObject *old_value; block *b; Py_ssize_t n, len=Py_SIZE(deque), halflen=(len+1)>>1, index=i; @@ -1249,9 +1248,7 @@ deque_ass_item(dequeobject *deque, Py_ss b = b->leftlink; } Py_INCREF(v); - old_value = b->data[i]; - b->data[i] = v; - Py_DECREF(old_value); + Py_SETREF(b->data[i], v); return 0; } diff -r c4e8751ce637 Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_ctypes/_ctypes.c Thu Dec 24 10:58:52 2015 +0200 @@ -2983,10 +2983,9 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject "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; @@ -5124,23 +5123,22 @@ int comerror_init(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *hresult, *text, *details; - PyBaseExceptionObject *bself; PyObject *a; int status; if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) - return -1; + return -1; if (!PyArg_ParseTuple(args, "OOO:COMError", &hresult, &text, &details)) return -1; a = PySequence_GetSlice(args, 1, PySequence_Size(args)); if (!a) - return -1; + return -1; status = PyObject_SetAttrString(self, "args", a); Py_DECREF(a); if (status < 0) - return -1; + return -1; if (PyObject_SetAttrString(self, "hresult", hresult) < 0) return -1; @@ -5151,9 +5149,8 @@ comerror_init(PyObject *self, PyObject * if (PyObject_SetAttrString(self, "details", details) < 0) return -1; - bself = (PyBaseExceptionObject *)self; Py_INCREF(args); - Py_SETREF(bself->args, args); + Py_SETREF((PyBaseExceptionObject *)self->args, args); return 0; } diff -r c4e8751ce637 Modules/_elementtree.c --- a/Modules/_elementtree.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_elementtree.c Thu Dec 24 10:58:52 2015 +0200 @@ -1961,8 +1961,7 @@ element_tag_setter(ElementObject *self, { _VALIDATE_ATTR_VALUE(value); Py_INCREF(value); - Py_DECREF(self->tag); - self->tag = value; + Py_SETREF(self->tag, value); return 0; } @@ -1995,8 +1994,7 @@ element_attrib_setter(ElementObject *sel return -1; } Py_INCREF(value); - Py_DECREF(self->extra->attrib); - self->extra->attrib = value; + Py_SETREF(self->extra->attrib, value); return 0; } @@ -2342,13 +2340,9 @@ static int PyObject *element_factory) /*[clinic end generated code: output=91cfa7558970ee96 input=1b424eeefc35249c]*/ { - PyObject *tmp; - if (element_factory) { Py_INCREF(element_factory); - tmp = self->element_factory; - self->element_factory = element_factory; - Py_XDECREF(tmp); + Py_SETREF(self->element_factory, element_factory); } return 0; @@ -2533,13 +2527,10 @@ treebuilder_handle_start(TreeBuilderObje } self->index++; - Py_DECREF(this); Py_INCREF(node); - self->this = node; - - Py_DECREF(self->last); Py_INCREF(node); - self->last = node; + Py_SETREF(self->this, node); + Py_SETREF(self->last, node); if (treebuilder_append_event(self, self->start_event_obj, node) < 0) goto error; @@ -2617,9 +2608,7 @@ treebuilder_handle_end(TreeBuilderObject item = PyList_GET_ITEM(self->stack, self->index); Py_INCREF(item); - Py_DECREF(self->last); - - self->last = self->this; + Py_SETREF(self->last, self->this); self->this = item; if (treebuilder_append_event(self, self->end_event_obj, self->last) < 0) diff -r c4e8751ce637 Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_io/bytesio.c Thu Dec 24 10:58:52 2015 +0200 @@ -87,7 +87,7 @@ scan_eol(bytesio *self, Py_ssize_t len) static int unshare_buffer(bytesio *self, size_t size) { - PyObject *new_buf, *old_buf; + PyObject *new_buf; assert(SHARED_BUF(self)); assert(self->exports == 0); assert(size >= (size_t)self->string_size); @@ -96,9 +96,7 @@ unshare_buffer(bytesio *self, size_t siz return -1; memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf), self->string_size); - old_buf = self->buf; - self->buf = new_buf; - Py_DECREF(old_buf); + Py_SETREF(self->buf, new_buf); return 0; } diff -r c4e8751ce637 Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_sqlite/connection.c Thu Dec 24 10:58:52 2015 +0200 @@ -204,8 +204,8 @@ void pysqlite_flush_statement_cache(pysq node = node->next; } - Py_SETREF(self->statement_cache, - (pysqlite_Cache *)PyObject_CallFunction((PyObject *)&pysqlite_CacheType, "O", self)); + Py_SETREF(self->statement_cache, (pysqlite_Cache *)PyObject_CallFunction( + (PyObject *)&pysqlite_CacheType, "O", self)); Py_DECREF(self); self->statement_cache->decref_factory = 0; } @@ -319,7 +319,8 @@ PyObject* pysqlite_connection_cursor(pys if (cursor && self->row_factory != Py_None) { Py_INCREF(self->row_factory); - Py_SETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory); + Py_SETREF(((pysqlite_Cursor *)cursor)->row_factory, + self->row_factory); } return cursor; diff -r c4e8751ce637 Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/_sqlite/cursor.c Thu Dec 24 10:58:52 2015 +0200 @@ -524,10 +524,10 @@ PyObject* _pysqlite_query_execute(pysqli 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) { diff -r c4e8751ce637 Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/itertoolsmodule.c Thu Dec 24 10:58:52 2015 +0200 @@ -77,7 +77,7 @@ groupby_traverse(groupbyobject *gbo, vis static PyObject * groupby_next(groupbyobject *gbo) { - PyObject *newvalue, *newkey, *r, *grouper, *tmp; + PyObject *newvalue, *newkey, *r, *grouper; /* skip to next iteration group */ for (;;) { @@ -110,19 +110,12 @@ groupby_next(groupbyobject *gbo) } } - tmp = gbo->currkey; - gbo->currkey = newkey; - Py_XDECREF(tmp); - - tmp = gbo->currvalue; - gbo->currvalue = newvalue; - Py_XDECREF(tmp); + Py_SETREF(gbo->currkey, newkey); + Py_SETREF(gbo->currvalue, newvalue); } Py_INCREF(gbo->currkey); - tmp = gbo->tgtkey; - gbo->tgtkey = gbo->currkey; - Py_XDECREF(tmp); + Py_SETREF(gbo->tgtkey, gbo->currkey); grouper = _grouper_create(gbo, gbo->tgtkey); if (grouper == NULL) @@ -3456,7 +3449,7 @@ accumulate_traverse(accumulateobject *lz static PyObject * accumulate_next(accumulateobject *lz) { - PyObject *val, *oldtotal, *newtotal; + PyObject *val, *newtotal; val = (*Py_TYPE(lz->it)->tp_iternext)(lz->it); if (val == NULL) @@ -3476,11 +3469,8 @@ accumulate_next(accumulateobject *lz) if (newtotal == NULL) return NULL; - oldtotal = lz->total; - lz->total = newtotal; - Py_DECREF(oldtotal); - Py_INCREF(newtotal); + Py_SETREF(lz->total, newtotal); return newtotal; } diff -r c4e8751ce637 Modules/pyexpat.c --- a/Modules/pyexpat.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/pyexpat.c Thu Dec 24 10:58:52 2015 +0200 @@ -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, PyObjec 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, PyObjec 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); } } diff -r c4e8751ce637 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Modules/zlibmodule.c Thu Dec 24 10:58:52 2015 +0200 @@ -961,14 +961,11 @@ zlib_Compress_copy_impl(compobject *self goto error; } Py_INCREF(self->unused_data); + Py_SETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); + Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_XDECREF(retval->unused_data); - 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; + Py_SETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ @@ -1020,14 +1017,11 @@ zlib_Decompress_copy_impl(compobject *se } Py_INCREF(self->unused_data); + Py_SETREF(retval->unused_data, self->unused_data); Py_INCREF(self->unconsumed_tail); + Py_SETREF(retval->unconsumed_tail, self->unconsumed_tail); Py_XINCREF(self->zdict); - Py_XDECREF(retval->unused_data); - 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; + Py_SETREF(retval->zdict, self->zdict); retval->eof = self->eof; /* Mark it as being initialized */ diff -r c4e8751ce637 Objects/listobject.c --- a/Objects/listobject.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Objects/listobject.c Thu Dec 24 10:58:52 2015 +0200 @@ -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 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, 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_ 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 -r c4e8751ce637 Objects/tupleobject.c --- a/Objects/tupleobject.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Objects/tupleobject.c Thu Dec 24 10:58:52 2015 +0200 @@ -149,7 +149,6 @@ PyTuple_GetItem(PyObject *op, Py_ssize_t 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 return -1; } p = ((PyTupleObject *)op) -> ob_item + i; - olditem = *p; - *p = newitem; - Py_XDECREF(olditem); + Py_SETREF(*p, newitem); return 0; } diff -r c4e8751ce637 Objects/typeobject.c --- a/Objects/typeobject.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Objects/typeobject.c Thu Dec 24 10:58:52 2015 +0200 @@ -401,7 +401,6 @@ type_qualname(PyTypeObject *type, void * static int type_set_name(PyTypeObject *type, PyObject *value, void *context) { - PyHeapTypeObject* et; char *tp_name; PyObject *tmp; @@ -430,17 +429,12 @@ type_set_name(PyTypeObject *type, PyObje 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; - + Py_SETREF(((PyHeapTypeObject*)type)->ht_name, value); type->tp_name = tp_name; - Py_DECREF(tmp); return 0; } diff -r c4e8751ce637 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Objects/unicodeobject.c Thu Dec 24 10:58:52 2015 +0200 @@ -14443,8 +14443,8 @@ unicode_format_arg_parse(struct unicode_ if (key == NULL) return -1; if (ctx->args_owned) { + ctx->args_owned = 0; Py_DECREF(ctx->args); - ctx->args_owned = 0; } ctx->args = PyObject_GetItem(ctx->dict, key); Py_DECREF(key); diff -r c4e8751ce637 Python/ast.c --- a/Python/ast.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Python/ast.c Thu Dec 24 10:58:52 2015 +0200 @@ -4692,11 +4692,8 @@ FstringParser_ConcatAndDel(FstringParser state->last_str = str; } else { /* Concatenate this with the previous string. */ - PyObject *temp = PyUnicode_Concat(state->last_str, str); - Py_DECREF(state->last_str); - Py_DECREF(str); - state->last_str = temp; - if (!temp) + PyUnicode_AppendAndDel(&state->last_str, str); + if (!state->last_str) return -1; } FstringParser_check_invariants(state); diff -r c4e8751ce637 Python/errors.c --- a/Python/errors.c Thu Dec 24 10:39:57 2015 +0200 +++ b/Python/errors.c Thu Dec 24 10:58:52 2015 +0200 @@ -315,14 +315,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_RecursionError; - *val = PyExc_RecursionErrorInst; - Py_INCREF(*exc); - Py_INCREF(*val); + /* throw away the old exception and use the recursion error instead */ + Py_INCREF(PyExc_RecursionError); + Py_SETREF(*exc, PyExc_RecursionError); + Py_INCREF(PyExc_RecursionErrorInst); + Py_SETREF(*val, PyExc_RecursionErrorInst); /* just keeping the old traceback */ return; }