diff -r 71f071f2e074 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/_datetimemodule.c Mon Dec 28 18:22:31 2015 +0200 @@ -1057,10 +1057,8 @@ format_utcoffset(char *buf, size_t bufle } /* Offset is normalized, so it is negative if days < 0 */ if (GET_TD_DAYS(offset) < 0) { - PyObject *temp = offset; sign = '-'; - offset = delta_negative((PyDateTime_Delta *)offset); - Py_DECREF(temp); + Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset)); if (offset == NULL) return -1; } @@ -3047,10 +3045,8 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, if (dst == Py_None) goto Inconsistent; if (delta_bool((PyDateTime_Delta *)dst) != 0) { - PyObject *temp = result; - result = add_datetime_timedelta((PyDateTime_DateTime *)result, - (PyDateTime_Delta *)dst, 1); - Py_DECREF(temp); + Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, + (PyDateTime_Delta *)dst, 1)); if (result == NULL) goto Fail; } @@ -4157,10 +4153,7 @@ datetime_datetime_now_impl(PyTypeObject tz); if (self != NULL && tz != Py_None) { /* Convert UTC to tzinfo's zone. */ - PyObject *temp = self; - - self = _PyObject_CallMethodId(tz, &PyId_fromutc, "O", self); - Py_DECREF(temp); + self = _PyObject_CallMethodId(tz, &PyId_fromutc, "N", self); } return self; } @@ -4195,10 +4188,7 @@ datetime_fromtimestamp(PyObject *cls, Py tzinfo); if (self != NULL && tzinfo != Py_None) { /* Convert UTC to tzinfo's zone. */ - PyObject *temp = self; - - self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", self); - Py_DECREF(temp); + self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self); } return self; } @@ -4421,9 +4411,7 @@ datetime_subtract(PyObject *left, PyObje return NULL; if (offdiff != NULL) { - PyObject *temp = result; - result = delta_subtract(result, offdiff); - Py_DECREF(temp); + Py_SETREF(result, delta_subtract(result, offdiff)); Py_DECREF(offdiff); } } diff -r 71f071f2e074 Modules/_elementtree.c --- a/Modules/_elementtree.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/_elementtree.c Mon Dec 28 18:22:31 2015 +0200 @@ -396,10 +396,8 @@ element_init(PyObject *self, PyObject *a Py_XDECREF(attrib); /* Replace the objects already pointed to by tag, text and tail. */ - tmp = self_elem->tag; Py_INCREF(tag); - self_elem->tag = tag; - Py_DECREF(tmp); + Py_SETREF(self_elem->tag, tag); tmp = self_elem->text; Py_INCREF(Py_None); diff -r 71f071f2e074 Modules/_lsprof.c --- a/Modules/_lsprof.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/_lsprof.c Mon Dec 28 18:22:31 2015 +0200 @@ -762,7 +762,6 @@ profiler_dealloc(ProfilerObject *op) static int profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw) { - PyObject *o; PyObject *timer = NULL; double timeunit = 0.0; int subcalls = 1; @@ -777,11 +776,9 @@ profiler_init(ProfilerObject *pObj, PyOb if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0) return -1; - o = pObj->externalTimer; - pObj->externalTimer = timer; + pObj->externalTimerUnit = timeunit; Py_XINCREF(timer); - Py_XDECREF(o); - pObj->externalTimerUnit = timeunit; + Py_SETREF(pObj->externalTimer, timer); return 0; } diff -r 71f071f2e074 Modules/_pickle.c --- a/Modules/_pickle.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/_pickle.c Mon Dec 28 18:22:31 2015 +0200 @@ -4494,8 +4494,6 @@ Pickler_get_persid(PicklerObject *self) static int Pickler_set_persid(PicklerObject *self, PyObject *value) { - PyObject *tmp; - if (value == NULL) { PyErr_SetString(PyExc_TypeError, "attribute deletion is not supported"); @@ -4507,10 +4505,8 @@ Pickler_set_persid(PicklerObject *self, return -1; } - tmp = self->pers_func; Py_INCREF(value); - self->pers_func = value; - Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */ + Py_SETREF(self->pers_func, value); return 0; } @@ -6946,8 +6942,6 @@ Unpickler_get_persload(UnpicklerObject * static int Unpickler_set_persload(UnpicklerObject *self, PyObject *value) { - PyObject *tmp; - if (value == NULL) { PyErr_SetString(PyExc_TypeError, "attribute deletion is not supported"); @@ -6960,10 +6954,8 @@ Unpickler_set_persload(UnpicklerObject * return -1; } - tmp = self->pers_func; Py_INCREF(value); - self->pers_func = value; - Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */ + Py_SETREF(self->pers_func, value); return 0; } diff -r 71f071f2e074 Modules/_sqlite/cache.c --- a/Modules/_sqlite/cache.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/_sqlite/cache.c Mon Dec 28 18:22:31 2015 +0200 @@ -89,7 +89,6 @@ int pysqlite_cache_init(pysqlite_Cache* void pysqlite_cache_dealloc(pysqlite_Cache* self) { pysqlite_Node* node; - pysqlite_Node* delete_node; if (!self->factory) { /* constructor failed, just get out of here */ @@ -99,9 +98,7 @@ void pysqlite_cache_dealloc(pysqlite_Cac /* iterate over all nodes and deallocate them */ node = self->first; while (node) { - delete_node = node; - node = node->next; - Py_DECREF(delete_node); + Py_SETREF(node, node->next); } if (self->decref_factory) { diff -r 71f071f2e074 Modules/readline.c --- a/Modules/readline.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Modules/readline.c Mon Dec 28 18:22:31 2015 +0200 @@ -321,10 +321,8 @@ set_hook(const char *funcname, PyObject Py_CLEAR(*hook_var); } else if (PyCallable_Check(function)) { - PyObject *tmp = *hook_var; Py_INCREF(function); - *hook_var = function; - Py_XDECREF(tmp); + Py_SETREF(*hook_var, function); } else { PyErr_Format(PyExc_TypeError, diff -r 71f071f2e074 Objects/dictobject.c --- a/Objects/dictobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/dictobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -1258,7 +1258,7 @@ PyDict_DelItem(PyObject *op, PyObject *k PyDictObject *mp; Py_hash_t hash; PyDictKeyEntry *ep; - PyObject *old_key, *old_value; + PyObject *old_value; PyObject **value_addr; if (!PyDict_Check(op)) { @@ -1285,10 +1285,8 @@ PyDict_DelItem(PyObject *op, PyObject *k mp->ma_used--; if (!_PyDict_HasSplitTable(mp)) { ENSURE_ALLOWS_DELETIONS(mp); - old_key = ep->me_key; Py_INCREF(dummy); - ep->me_key = dummy; - Py_DECREF(old_key); + Py_SETREF(ep->me_key, dummy); } Py_DECREF(old_value); return 0; @@ -1299,7 +1297,7 @@ int { PyDictObject *mp; PyDictKeyEntry *ep; - PyObject *old_key, *old_value; + PyObject *old_value; PyObject **value_addr; if (!PyDict_Check(op)) { @@ -1321,10 +1319,8 @@ int mp->ma_used--; if (!_PyDict_HasSplitTable(mp)) { ENSURE_ALLOWS_DELETIONS(mp); - old_key = ep->me_key; Py_INCREF(dummy); - ep->me_key = dummy; - Py_DECREF(old_key); + Py_SETREF(ep->me_key, dummy); } Py_DECREF(old_value); return 0; @@ -1453,7 +1449,7 @@ PyObject * _PyDict_Pop(PyDictObject *mp, PyObject *key, PyObject *deflt) { Py_hash_t hash; - PyObject *old_value, *old_key; + PyObject *old_value; PyDictKeyEntry *ep; PyObject **value_addr; @@ -1487,10 +1483,8 @@ PyObject * mp->ma_used--; if (!_PyDict_HasSplitTable(mp)) { ENSURE_ALLOWS_DELETIONS(mp); - old_key = ep->me_key; Py_INCREF(dummy); - ep->me_key = dummy; - Py_DECREF(old_key); + Py_SETREF(ep->me_key, dummy); } return old_value; } diff -r 71f071f2e074 Objects/exceptions.c --- a/Objects/exceptions.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/exceptions.c Mon Dec 28 18:22:31 2015 +0200 @@ -59,15 +59,11 @@ BaseException_new(PyTypeObject *type, Py static int BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds) { - PyObject *tmp; - if (!_PyArg_NoKeywords(Py_TYPE(self)->tp_name, kwds)) return -1; - tmp = self->args; - self->args = args; - Py_INCREF(self->args); - Py_XDECREF(tmp); + Py_INCREF(args); + Py_SETREF(self->args, args); return 0; } @@ -328,11 +324,10 @@ PyException_GetCause(PyObject *self) { /* Steals a reference to cause */ void -PyException_SetCause(PyObject *self, PyObject *cause) { - PyObject *old_cause = ((PyBaseExceptionObject *)self)->cause; - ((PyBaseExceptionObject *)self)->cause = cause; +PyException_SetCause(PyObject *self, PyObject *cause) +{ ((PyBaseExceptionObject *)self)->suppress_context = 1; - Py_XDECREF(old_cause); + Py_SETREF(((PyBaseExceptionObject *)self)->cause, cause); } PyObject * @@ -344,10 +339,9 @@ PyException_GetContext(PyObject *self) { /* Steals a reference to context */ void -PyException_SetContext(PyObject *self, PyObject *context) { - PyObject *old_context = ((PyBaseExceptionObject *)self)->context; - ((PyBaseExceptionObject *)self)->context = context; - Py_XDECREF(old_context); +PyException_SetContext(PyObject *self, PyObject *context) +{ + Py_SETREF(((PyBaseExceptionObject *)self)->context, context); } diff -r 71f071f2e074 Objects/frameobject.c --- a/Objects/frameobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/frameobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -349,15 +349,11 @@ frame_gettrace(PyFrameObject *f, void *c static int frame_settrace(PyFrameObject *f, PyObject* v, void *closure) { - PyObject* old_value; - /* We rely on f_lineno being accurate when f_trace is set. */ f->f_lineno = PyFrame_GetLineNumber(f); - old_value = f->f_trace; Py_XINCREF(v); - f->f_trace = v; - Py_XDECREF(old_value); + Py_SETREF(f->f_trace, v); return 0; } diff -r 71f071f2e074 Objects/funcobject.c --- a/Objects/funcobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/funcobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -249,7 +249,6 @@ func_get_code(PyFunctionObject *op) static int func_set_code(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; Py_ssize_t nfree, nclosure; /* Not legal to del f.func_code or to set it to anything @@ -270,10 +269,8 @@ func_set_code(PyFunctionObject *op, PyOb nclosure, nfree); return -1; } - tmp = op->func_code; Py_INCREF(value); - op->func_code = value; - Py_DECREF(tmp); + Py_SETREF(op->func_code, value); return 0; } @@ -287,8 +284,6 @@ func_get_name(PyFunctionObject *op) static int func_set_name(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; - /* Not legal to del f.func_name or to set it to anything * other than a string object. */ if (value == NULL || !PyUnicode_Check(value)) { @@ -296,10 +291,8 @@ func_set_name(PyFunctionObject *op, PyOb "__name__ must be set to a string object"); return -1; } - tmp = op->func_name; Py_INCREF(value); - op->func_name = value; - Py_DECREF(tmp); + Py_SETREF(op->func_name, value); return 0; } @@ -313,8 +306,6 @@ func_get_qualname(PyFunctionObject *op) static int func_set_qualname(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; - /* Not legal to del f.__qualname__ or to set it to anything * other than a string object. */ if (value == NULL || !PyUnicode_Check(value)) { @@ -322,10 +313,8 @@ func_set_qualname(PyFunctionObject *op, "__qualname__ must be set to a string object"); return -1; } - tmp = op->func_qualname; Py_INCREF(value); - op->func_qualname = value; - Py_DECREF(tmp); + Py_SETREF(op->func_qualname, value); return 0; } @@ -343,8 +332,6 @@ func_get_defaults(PyFunctionObject *op) static int func_set_defaults(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; - /* Legal to del f.func_defaults. * Can only set func_defaults to NULL or a tuple. */ if (value == Py_None) @@ -354,10 +341,8 @@ func_set_defaults(PyFunctionObject *op, "__defaults__ must be set to a tuple object"); return -1; } - tmp = op->func_defaults; Py_XINCREF(value); - op->func_defaults = value; - Py_XDECREF(tmp); + Py_SETREF(op->func_defaults, value); return 0; } @@ -375,8 +360,6 @@ func_get_kwdefaults(PyFunctionObject *op static int func_set_kwdefaults(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; - if (value == Py_None) value = NULL; /* Legal to del f.func_kwdefaults. @@ -386,10 +369,8 @@ func_set_kwdefaults(PyFunctionObject *op "__kwdefaults__ must be set to a dict object"); return -1; } - tmp = op->func_kwdefaults; Py_XINCREF(value); - op->func_kwdefaults = value; - Py_XDECREF(tmp); + Py_SETREF(op->func_kwdefaults, value); return 0; } @@ -408,8 +389,6 @@ func_get_annotations(PyFunctionObject *o static int func_set_annotations(PyFunctionObject *op, PyObject *value) { - PyObject *tmp; - if (value == Py_None) value = NULL; /* Legal to del f.func_annotations. @@ -420,10 +399,8 @@ func_set_annotations(PyFunctionObject *o "__annotations__ must be set to a dict object"); return -1; } - tmp = op->func_annotations; Py_XINCREF(value); - op->func_annotations = value; - Py_XDECREF(tmp); + Py_SETREF(op->func_annotations, value); return 0; } diff -r 71f071f2e074 Objects/genobject.c --- a/Objects/genobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/genobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -510,8 +510,6 @@ gen_get_name(PyGenObject *op) static int gen_set_name(PyGenObject *op, PyObject *value) { - PyObject *tmp; - /* Not legal to del gen.gi_name or to set it to anything * other than a string object. */ if (value == NULL || !PyUnicode_Check(value)) { @@ -519,10 +517,8 @@ gen_set_name(PyGenObject *op, PyObject * "__name__ must be set to a string object"); return -1; } - tmp = op->gi_name; Py_INCREF(value); - op->gi_name = value; - Py_DECREF(tmp); + Py_SETREF(op->gi_name, value); return 0; } @@ -536,8 +532,6 @@ gen_get_qualname(PyGenObject *op) static int gen_set_qualname(PyGenObject *op, PyObject *value) { - PyObject *tmp; - /* Not legal to del gen.__qualname__ or to set it to anything * other than a string object. */ if (value == NULL || !PyUnicode_Check(value)) { @@ -545,10 +539,8 @@ gen_set_qualname(PyGenObject *op, PyObje "__qualname__ must be set to a string object"); return -1; } - tmp = op->gi_qualname; Py_INCREF(value); - op->gi_qualname = value; - Py_DECREF(tmp); + Py_SETREF(op->gi_qualname, value); return 0; } diff -r 71f071f2e074 Objects/object.c --- a/Objects/object.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/object.c Mon Dec 28 18:22:31 2015 +0200 @@ -1203,7 +1203,7 @@ PyObject_GenericSetAttr(PyObject *obj, P int PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context) { - PyObject *dict, **dictptr = _PyObject_GetDictPtr(obj); + PyObject **dictptr = _PyObject_GetDictPtr(obj); if (dictptr == NULL) { PyErr_SetString(PyExc_AttributeError, "This object has no __dict__"); @@ -1219,10 +1219,8 @@ PyObject_GenericSetDict(PyObject *obj, P "not a '%.200s'", Py_TYPE(value)->tp_name); return -1; } - dict = *dictptr; Py_XINCREF(value); - *dictptr = value; - Py_XDECREF(dict); + Py_SETREF(*dictptr, value); return 0; } diff -r 71f071f2e074 Objects/setobject.c --- a/Objects/setobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/setobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -400,18 +400,15 @@ static int set_discard_entry(PySetObject *so, PyObject *key, Py_hash_t hash) { setentry *entry; - PyObject *old_key; entry = set_lookkey(so, key, hash); if (entry == NULL) return -1; if (entry->key == NULL) return DISCARD_NOTFOUND; - old_key = entry->key; - entry->key = dummy; + so->used--; entry->hash = -1; - so->used--; - Py_DECREF(old_key); + Py_SETREF(entry->key, dummy); return DISCARD_FOUND; } diff -r 71f071f2e074 Objects/typeobject.c --- a/Objects/typeobject.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Objects/typeobject.c Mon Dec 28 18:22:31 2015 +0200 @@ -2099,7 +2099,7 @@ subtype_dict(PyObject *obj, void *contex static int subtype_setdict(PyObject *obj, PyObject *value, void *context) { - PyObject *dict, **dictptr; + PyObject **dictptr; PyTypeObject *base; base = get_builtin_base_with_dict(Py_TYPE(obj)); @@ -2130,10 +2130,8 @@ subtype_setdict(PyObject *obj, PyObject "not a '%.200s'", Py_TYPE(value)->tp_name); return -1; } - dict = *dictptr; Py_XINCREF(value); - *dictptr = value; - Py_XDECREF(dict); + Py_SETREF(*dictptr, value); return 0; } diff -r 71f071f2e074 Python/import.c --- a/Python/import.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Python/import.c Mon Dec 28 18:22:31 2015 +0200 @@ -879,10 +879,8 @@ update_code_filenames(PyCodeObject *co, if (PyUnicode_Compare(co->co_filename, oldname)) return; - tmp = co->co_filename; - co->co_filename = newname; - Py_INCREF(co->co_filename); - Py_DECREF(tmp); + Py_INCREF(newname); + Py_SETREF(co->co_filename, newname); constants = co->co_consts; n = PyTuple_GET_SIZE(constants); @@ -1327,10 +1325,8 @@ remove_importlib_frames(void) (always_trim || PyUnicode_CompareWithASCIIString(code->co_name, remove_frames) == 0)) { - PyObject *tmp = *outer_link; - *outer_link = next; Py_XINCREF(next); - Py_DECREF(tmp); + Py_SETREF(*outer_link, next); prev_link = outer_link; } else { diff -r 71f071f2e074 Python/peephole.c --- a/Python/peephole.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Python/peephole.c Mon Dec 28 18:22:31 2015 +0200 @@ -118,9 +118,7 @@ tuple_of_constants(unsigned char *codest /* If it's a BUILD_SET, use the PyTuple we just built to create a PyFrozenSet, and use that as the constant instead: */ if (codestr[0] == BUILD_SET) { - PyObject *tuple = newconst; - newconst = PyFrozenSet_New(tuple); - Py_DECREF(tuple); + Py_SETREF(newconst, PyFrozenSet_New(newconst)); if (newconst == NULL) return 0; } diff -r 71f071f2e074 Python/sysmodule.c --- a/Python/sysmodule.c Sun Dec 27 13:17:04 2015 -0800 +++ b/Python/sysmodule.c Mon Dec 28 18:22:31 2015 +0200 @@ -436,10 +436,7 @@ trace_trampoline(PyObject *self, PyFrame return -1; } if (result != Py_None) { - PyObject *temp = frame->f_trace; - frame->f_trace = NULL; - Py_XDECREF(temp); - frame->f_trace = result; + Py_SETREF(frame->f_trace, result); } else { Py_DECREF(result);