From: Serhiy Storchaka Date: Wed, 6 Apr 2016 06:50:03 +0000 (+0300) Subject: Issue #22570: Renamed Py_SETREF to Py_XSETREF. X-Git-Tag: v3.6.0a1~267 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec39756960def5fdd8cb0ae191429f2f8e229f55;p=python Issue #22570: Renamed Py_SETREF to Py_XSETREF. --- ec39756960def5fdd8cb0ae191429f2f8e229f55 diff --cc Modules/_ctypes/_ctypes.c index 9f7bcf807c,1b804ae1b5..2bf088a130 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@@ -5149,8 -5150,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(((PyBaseExceptionObject *)self)->args, args); - Py_XSETREF(bself->args, args); ++ Py_XSETREF(((PyBaseExceptionObject *)self)->args, args); return 0; } diff --cc Modules/_datetimemodule.c index 261c4bc6e7,0e50023eea..e5191a0f16 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@@ -1057,8 -1057,10 +1057,8 @@@ format_utcoffset(char *buf, size_t bufl } /* Offset is normalized, so it is negative if days < 0 */ if (GET_TD_DAYS(offset) < 0) { - PyObject *temp = offset; sign = '-'; - Py_SETREF(offset, delta_negative((PyDateTime_Delta *)offset)); - offset = delta_negative((PyDateTime_Delta *)offset); - Py_DECREF(temp); ++ Py_XSETREF(offset, delta_negative((PyDateTime_Delta *)offset)); if (offset == NULL) return -1; } @@@ -3045,8 -3047,10 +3045,8 @@@ tzinfo_fromutc(PyDateTime_TZInfo *self if (dst == Py_None) goto Inconsistent; if (delta_bool((PyDateTime_Delta *)dst) != 0) { - Py_SETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, - PyObject *temp = result; - result = add_datetime_timedelta((PyDateTime_DateTime *)result, - (PyDateTime_Delta *)dst, 1); - Py_DECREF(temp); ++ Py_XSETREF(result, add_datetime_timedelta((PyDateTime_DateTime *)result, + (PyDateTime_Delta *)dst, 1)); if (result == NULL) goto Fail; } @@@ -4445,7 -4469,9 +4445,7 @@@ datetime_subtract(PyObject *left, PyObj return NULL; if (offdiff != NULL) { - Py_SETREF(result, delta_subtract(result, offdiff)); - PyObject *temp = result; - result = delta_subtract(result, offdiff); - Py_DECREF(temp); ++ Py_XSETREF(result, delta_subtract(result, offdiff)); Py_DECREF(offdiff); } } diff --cc Modules/_decimal/_decimal.c index 3c2ad851ba,112b44fda7..0c02d28db7 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@@ -3380,106 -3380,6 +3380,106 @@@ dec_as_long(PyObject *dec, PyObject *co return (PyObject *) pylong; } +/* Convert a Decimal to its exact integer ratio representation. */ +static PyObject * +dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED) +{ + PyObject *numerator = NULL; + PyObject *denominator = NULL; + PyObject *exponent = NULL; + PyObject *result = NULL; + PyObject *tmp; + mpd_ssize_t exp; + PyObject *context; + uint32_t status = 0; + PyNumberMethods *long_methods = PyLong_Type.tp_as_number; + + if (mpd_isspecial(MPD(self))) { + if (mpd_isnan(MPD(self))) { + PyErr_SetString(PyExc_ValueError, + "cannot convert NaN to integer ratio"); + } + else { + PyErr_SetString(PyExc_OverflowError, + "cannot convert Infinity to integer ratio"); + } + return NULL; + } + + CURRENT_CONTEXT(context); + + tmp = dec_alloc(); + if (tmp == NULL) { + return NULL; + } + + if (!mpd_qcopy(MPD(tmp), MPD(self), &status)) { + Py_DECREF(tmp); + PyErr_NoMemory(); + return NULL; + } + + exp = mpd_iszero(MPD(tmp)) ? 0 : MPD(tmp)->exp; + MPD(tmp)->exp = 0; + + /* context and rounding are unused here: the conversion is exact */ + numerator = dec_as_long(tmp, context, MPD_ROUND_FLOOR); + Py_DECREF(tmp); + if (numerator == NULL) { + goto error; + } + + exponent = PyLong_FromSsize_t(exp < 0 ? -exp : exp); + if (exponent == NULL) { + goto error; + } + + tmp = PyLong_FromLong(10); + if (tmp == NULL) { + goto error; + } + - Py_SETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); ++ Py_XSETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None)); + Py_DECREF(tmp); + if (exponent == NULL) { + goto error; + } + + if (exp >= 0) { - Py_SETREF(numerator, long_methods->nb_multiply(numerator, exponent)); ++ Py_XSETREF(numerator, long_methods->nb_multiply(numerator, exponent)); + if (numerator == NULL) { + goto error; + } + denominator = PyLong_FromLong(1); + if (denominator == NULL) { + goto error; + } + } + else { + denominator = exponent; + exponent = NULL; + tmp = _PyLong_GCD(numerator, denominator); + if (tmp == NULL) { + goto error; + } - Py_SETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); - Py_SETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); ++ Py_XSETREF(numerator, long_methods->nb_floor_divide(numerator, tmp)); ++ Py_XSETREF(denominator, long_methods->nb_floor_divide(denominator, tmp)); + Py_DECREF(tmp); + if (numerator == NULL || denominator == NULL) { + goto error; + } + } + + result = PyTuple_Pack(2, numerator, denominator); + + +error: + Py_XDECREF(exponent); + Py_XDECREF(denominator); + Py_XDECREF(numerator); + return result; +} + static PyObject * PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds) { diff --cc Modules/_elementtree.c index 0effc3f32a,6619048e27..5c49c151c1 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@@ -396,8 -420,10 +396,8 @@@ element_init(PyObject *self, PyObject * Py_XDECREF(attrib); /* Replace the objects already pointed to by tag, text and tail. */ - tmp = self_elem->tag; Py_INCREF(tag); - Py_SETREF(self_elem->tag, tag); - self_elem->tag = tag; - Py_DECREF(tmp); ++ Py_XSETREF(self_elem->tag, tag); tmp = self_elem->text; Py_INCREF(Py_None); @@@ -1907,90 -1879,92 +1907,90 @@@ element_ass_subscr(PyObject* self_, PyO } static PyObject* -element_getattro(ElementObject* self, PyObject* nameobj) +element_tag_getter(ElementObject *self, void *closure) { - PyObject* res; - char *name = ""; + PyObject *res = self->tag; + Py_INCREF(res); + return res; +} - if (PyUnicode_Check(nameobj)) - name = _PyUnicode_AsString(nameobj); +static PyObject* +element_text_getter(ElementObject *self, void *closure) +{ + PyObject *res = element_get_text(self); + Py_XINCREF(res); + return res; +} - if (name == NULL) - return NULL; +static PyObject* +element_tail_getter(ElementObject *self, void *closure) +{ + PyObject *res = element_get_tail(self); + Py_XINCREF(res); + return res; +} - /* handle common attributes first */ - if (strcmp(name, "tag") == 0) { - res = self->tag; - Py_INCREF(res); - return res; - } else if (strcmp(name, "text") == 0) { - res = element_get_text(self); - Py_XINCREF(res); - return res; +static PyObject* +element_attrib_getter(ElementObject *self, void *closure) +{ + PyObject *res; + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return NULL; } + res = element_get_attrib(self); + Py_XINCREF(res); + return res; +} - /* methods */ - res = PyObject_GenericGetAttr((PyObject*) self, nameobj); - if (res) - return res; - - /* less common attributes */ - if (strcmp(name, "tail") == 0) { - PyErr_Clear(); - res = element_get_tail(self); - } else if (strcmp(name, "attrib") == 0) { - PyErr_Clear(); - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return NULL; - } - res = element_get_attrib(self); +/* macro for setter validation */ +#define _VALIDATE_ATTR_VALUE(V) \ + if ((V) == NULL) { \ + PyErr_SetString( \ + PyExc_AttributeError, \ + "can't delete element attribute"); \ + return -1; \ } - if (!res) - return NULL; - - Py_INCREF(res); - return res; +static int +element_tag_setter(ElementObject *self, PyObject *value, void *closure) +{ + _VALIDATE_ATTR_VALUE(value); + Py_INCREF(value); - Py_SETREF(self->tag, value); ++ Py_XSETREF(self->tag, value); + return 0; } static int -element_setattro(ElementObject* self, PyObject* nameobj, PyObject* value) +element_text_setter(ElementObject *self, PyObject *value, void *closure) { - char *name = ""; + _VALIDATE_ATTR_VALUE(value); + Py_INCREF(value); + Py_DECREF(JOIN_OBJ(self->text)); + self->text = value; + return 0; +} - if (value == NULL) { - PyErr_SetString(PyExc_AttributeError, - "can't delete attribute"); - return -1; - } - if (PyUnicode_Check(nameobj)) - name = _PyUnicode_AsString(nameobj); - if (name == NULL) - return -1; +static int +element_tail_setter(ElementObject *self, PyObject *value, void *closure) +{ + _VALIDATE_ATTR_VALUE(value); + Py_INCREF(value); + Py_DECREF(JOIN_OBJ(self->tail)); + self->tail = value; + return 0; +} - if (strcmp(name, "tag") == 0) { - Py_INCREF(value); - Py_XSETREF(self->tag, value); - } else if (strcmp(name, "text") == 0) { - Py_DECREF(JOIN_OBJ(self->text)); - self->text = value; - Py_INCREF(self->text); - } else if (strcmp(name, "tail") == 0) { - Py_DECREF(JOIN_OBJ(self->tail)); - self->tail = value; - Py_INCREF(self->tail); - } else if (strcmp(name, "attrib") == 0) { - if (!self->extra) { - if (create_extra(self, NULL) < 0) - return -1; - } - Py_INCREF(value); - Py_XSETREF(self->extra->attrib, value); - } else { - PyErr_SetString(PyExc_AttributeError, - "Can't set arbitrary attributes on Element"); - return -1; +static int +element_attrib_setter(ElementObject *self, PyObject *value, void *closure) +{ + _VALIDATE_ATTR_VALUE(value); + if (!self->extra) { + if (create_extra(self, NULL) < 0) + return -1; } - + Py_INCREF(value); - Py_SETREF(self->extra->attrib, value); ++ Py_XSETREF(self->extra->attrib, value); return 0; } @@@ -2336,9 -2367,13 +2336,9 @@@ _elementtree_TreeBuilder___init___impl( PyObject *element_factory) /*[clinic end generated code: output=91cfa7558970ee96 input=1b424eeefc35249c]*/ { - PyObject *tmp; - if (element_factory) { Py_INCREF(element_factory); - Py_SETREF(self->element_factory, element_factory); - tmp = self->element_factory; - self->element_factory = element_factory; - Py_XDECREF(tmp); ++ Py_XSETREF(self->element_factory, element_factory); } return 0; @@@ -3580,10 -3603,8 +3580,10 @@@ _elementtree_XMLParser__setevents_impl( target = (TreeBuilderObject*) self->target; - Py_INCREF(events_queue); - Py_XSETREF(target->events, events_queue); + events_append = PyObject_GetAttrString(events_queue, "append"); + if (events_append == NULL) + return NULL; - Py_SETREF(target->events_append, events_append); ++ Py_XSETREF(target->events_append, events_append); /* clear out existing events */ Py_CLEAR(target->start_event_obj); diff --cc Modules/_io/bytesio.c index 6333e46438,49174b449e..84d2c5d813 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@@ -96,7 -96,9 +96,7 @@@ unshare_buffer(bytesio *self, size_t si return -1; memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf), self->string_size); - Py_SETREF(self->buf, new_buf); - old_buf = self->buf; - self->buf = new_buf; - Py_DECREF(old_buf); ++ Py_XSETREF(self->buf, new_buf); return 0; } diff --cc Modules/_lsprof.c index d3ed758e8a,66e534f2a8..ccfb513038 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@@ -776,9 -777,11 +776,9 @@@ profiler_init(ProfilerObject *pObj, PyO if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0) return -1; - o = pObj->externalTimer; - pObj->externalTimer = timer; - Py_XINCREF(timer); - Py_XDECREF(o); pObj->externalTimerUnit = timeunit; + Py_XINCREF(timer); - Py_SETREF(pObj->externalTimer, timer); ++ Py_XSETREF(pObj->externalTimer, timer); return 0; } diff --cc Modules/_pickle.c index 5c3530b962,1acf14ade8..049b737ad4 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@@ -4505,8 -4435,10 +4505,8 @@@ Pickler_set_persid(PicklerObject *self return -1; } - tmp = self->pers_func; Py_INCREF(value); - Py_SETREF(self->pers_func, value); - self->pers_func = value; - Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */ ++ Py_XSETREF(self->pers_func, value); return 0; } @@@ -6954,8 -6869,10 +6954,8 @@@ Unpickler_set_persload(UnpicklerObject return -1; } - tmp = self->pers_func; Py_INCREF(value); - Py_SETREF(self->pers_func, value); - self->pers_func = value; - Py_XDECREF(tmp); /* self->pers_func can be NULL, so be careful. */ ++ Py_XSETREF(self->pers_func, value); return 0; } diff --cc Modules/itertoolsmodule.c index 9fb9d7487c,a7f1111777..532ce012b0 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@@ -108,12 -109,19 +108,12 @@@ groupby_next(groupbyobject *gbo } } - Py_SETREF(gbo->currkey, newkey); - Py_SETREF(gbo->currvalue, newvalue); - tmp = gbo->currkey; - gbo->currkey = newkey; - Py_XDECREF(tmp); - - tmp = gbo->currvalue; - gbo->currvalue = newvalue; - Py_XDECREF(tmp); ++ Py_XSETREF(gbo->currkey, newkey); ++ Py_XSETREF(gbo->currvalue, newvalue); } Py_INCREF(gbo->currkey); - Py_SETREF(gbo->tgtkey, gbo->currkey); - tmp = gbo->tgtkey; - gbo->tgtkey = gbo->currkey; - Py_XDECREF(tmp); ++ Py_XSETREF(gbo->tgtkey, gbo->currkey); grouper = _grouper_create(gbo, gbo->tgtkey); if (grouper == NULL) @@@ -971,13 -966,11 +971,13 @@@ cycle_setstate(cycleobject *lz, PyObjec { PyObject *saved=NULL; int firstpass; - if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass)) + + if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass)) return NULL; - Py_XINCREF(saved); + Py_INCREF(saved); - Py_SETREF(lz->saved, saved); + Py_XSETREF(lz->saved, saved); lz->firstpass = firstpass != 0; + lz->index = 0; Py_RETURN_NONE; } @@@ -3456,8 -3449,11 +3456,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); ++ Py_XSETREF(lz->total, newtotal); return newtotal; } diff --cc Modules/pyexpat.c index c6d35150b3,9a6da737fb..2dafbb03a5 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@@ -1362,7 -1366,8 +1362,7 @@@ sethandler(xmlparseobject *self, PyObje Py_INCREF(v); c_handler = handler_info[handlernum].handler; } - Py_SETREF(self->handlers[handlernum], v); - self->handlers[handlernum] = v; - Py_XDECREF(temp); ++ Py_XSETREF(self->handlers[handlernum], v); handler_info[handlernum].setter(self->itself, c_handler); return 1; } diff --cc Modules/readline.c index 27459d0dfb,63be9b487e..a323b69622 --- a/Modules/readline.c +++ b/Modules/readline.c @@@ -323,8 -323,10 +323,8 @@@ set_hook(const char *funcname, PyObjec Py_CLEAR(*hook_var); } else if (PyCallable_Check(function)) { - PyObject *tmp = *hook_var; Py_INCREF(function); - Py_SETREF(*hook_var, function); - *hook_var = function; - Py_XDECREF(tmp); ++ Py_XSETREF(*hook_var, function); } else { PyErr_Format(PyExc_TypeError, diff --cc Objects/exceptions.c index 7374368164,d03aadac79..2c7688ca62 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@@ -62,8 -62,12 +62,8 @@@ BaseException_init(PyBaseExceptionObjec 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); ++ Py_XSETREF(self->args, args); return 0; } @@@ -324,10 -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_SETREF(((PyBaseExceptionObject *)self)->cause, cause); - Py_XDECREF(old_cause); ++ Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause); } PyObject * @@@ -339,9 -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); ++ Py_XSETREF(((PyBaseExceptionObject *)self)->context, context); } diff --cc Objects/floatobject.c index eb60659615,d92bec35b5..32a0de1f3b --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@@ -1483,27 -1489,24 +1483,27 @@@ float_as_integer_ratio(PyObject *v, PyO to be truncated by PyLong_FromDouble(). */ numerator = PyLong_FromDouble(float_part); - if (numerator == NULL) goto error; + if (numerator == NULL) + goto error; + denominator = PyLong_FromLong(1); + if (denominator == NULL) + goto error; + py_exponent = PyLong_FromLong(Py_ABS(exponent)); + if (py_exponent == NULL) + goto error; /* fold in 2**exponent */ - denominator = PyLong_FromLong(1); - py_exponent = PyLong_FromLong(labs((long)exponent)); - if (py_exponent == NULL) goto error; - INPLACE_UPDATE(py_exponent, - long_methods->nb_lshift(denominator, py_exponent)); - if (py_exponent == NULL) goto error; if (exponent > 0) { - Py_SETREF(numerator, - INPLACE_UPDATE(numerator, - long_methods->nb_multiply(numerator, py_exponent)); - if (numerator == NULL) goto error; ++ Py_XSETREF(numerator, + long_methods->nb_lshift(numerator, py_exponent)); + if (numerator == NULL) + goto error; } else { - Py_SETREF(denominator, - Py_DECREF(denominator); - denominator = py_exponent; - py_exponent = NULL; ++ Py_XSETREF(denominator, + long_methods->nb_lshift(denominator, py_exponent)); + if (denominator == NULL) + goto error; } result_pair = PyTuple_Pack(2, numerator, denominator); diff --cc Objects/frameobject.c index da2d2ed215,bdf06db335..a4a862a4b2 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@@ -352,8 -352,12 +352,8 @@@ frame_settrace(PyFrameObject *f, PyObje /* 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); - Py_SETREF(f->f_trace, v); - f->f_trace = v; - Py_XDECREF(old_value); ++ Py_XSETREF(f->f_trace, v); return 0; } diff --cc Objects/funcobject.c index 29676346c4,4252e930bd..c5f1a0a11e --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@@ -269,8 -270,10 +269,8 @@@ func_set_code(PyFunctionObject *op, PyO nclosure, nfree); return -1; } - tmp = op->func_code; Py_INCREF(value); - Py_SETREF(op->func_code, value); - op->func_code = value; - Py_DECREF(tmp); ++ Py_XSETREF(op->func_code, value); return 0; } @@@ -291,8 -296,10 +291,8 @@@ func_set_name(PyFunctionObject *op, PyO "__name__ must be set to a string object"); return -1; } - tmp = op->func_name; Py_INCREF(value); - Py_SETREF(op->func_name, value); - op->func_name = value; - Py_DECREF(tmp); ++ Py_XSETREF(op->func_name, value); return 0; } @@@ -313,8 -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); - Py_SETREF(op->func_qualname, value); - op->func_qualname = value; - Py_DECREF(tmp); ++ Py_XSETREF(op->func_qualname, value); return 0; } @@@ -341,8 -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); - Py_SETREF(op->func_defaults, value); - op->func_defaults = value; - Py_XDECREF(tmp); ++ Py_XSETREF(op->func_defaults, value); return 0; } @@@ -369,8 -386,10 +369,8 @@@ func_set_kwdefaults(PyFunctionObject *o "__kwdefaults__ must be set to a dict object"); return -1; } - tmp = op->func_kwdefaults; Py_XINCREF(value); - Py_SETREF(op->func_kwdefaults, value); - op->func_kwdefaults = value; - Py_XDECREF(tmp); ++ Py_XSETREF(op->func_kwdefaults, value); return 0; } @@@ -399,8 -420,10 +399,8 @@@ func_set_annotations(PyFunctionObject * "__annotations__ must be set to a dict object"); return -1; } - tmp = op->func_annotations; Py_XINCREF(value); - Py_SETREF(op->func_annotations, value); - op->func_annotations = value; - Py_XDECREF(tmp); ++ Py_XSETREF(op->func_annotations, value); return 0; } diff --cc Objects/genobject.c index fdb3c031d3,f74d044dcf..c94a6ed53a --- a/Objects/genobject.c +++ b/Objects/genobject.c @@@ -526,8 -528,10 +526,8 @@@ gen_set_name(PyGenObject *op, PyObject "__name__ must be set to a string object"); return -1; } - tmp = op->gi_name; Py_INCREF(value); - Py_SETREF(op->gi_name, value); - op->gi_name = value; - Py_DECREF(tmp); ++ Py_XSETREF(op->gi_name, value); return 0; } @@@ -548,8 -554,10 +548,8 @@@ gen_set_qualname(PyGenObject *op, PyObj "__qualname__ must be set to a string object"); return -1; } - tmp = op->gi_qualname; Py_INCREF(value); - Py_SETREF(op->gi_qualname, value); - op->gi_qualname = value; - Py_DECREF(tmp); ++ Py_XSETREF(op->gi_qualname, value); return 0; } diff --cc Objects/listobject.c index 81b40ae355,d688179d6b..7c02be7276 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@@ -229,7 -230,9 +229,7 @@@ PyList_SetItem(PyObject *op, Py_ssize_ return -1; } p = ((PyListObject *)op) -> ob_item + i; - Py_SETREF(*p, newitem); - olditem = *p; - *p = newitem; - Py_XDECREF(olditem); ++ Py_XSETREF(*p, newitem); return 0; } @@@ -735,7 -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); - Py_SETREF(a->ob_item[i], v); - old_value = a->ob_item[i]; - a->ob_item[i] = v; - Py_DECREF(old_value); ++ Py_XSETREF(a->ob_item[i], v); return 0; } diff --cc Objects/object.c index 8072dbced2,6fc4df1639..0817311d53 --- a/Objects/object.c +++ b/Objects/object.c @@@ -1219,8 -1220,10 +1219,8 @@@ PyObject_GenericSetDict(PyObject *obj, "not a '%.200s'", Py_TYPE(value)->tp_name); return -1; } - dict = *dictptr; - Py_XINCREF(value); - *dictptr = value; - Py_XDECREF(dict); + Py_INCREF(value); - Py_SETREF(*dictptr, value); ++ Py_XSETREF(*dictptr, value); return 0; } diff --cc Objects/tupleobject.c index 5020aff3f4,7920fec2bd..a7774e2fd1 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@@ -162,7 -163,9 +162,7 @@@ PyTuple_SetItem(PyObject *op, Py_ssize_ return -1; } p = ((PyTupleObject *)op) -> ob_item + i; - Py_SETREF(*p, newitem); - olditem = *p; - *p = newitem; - Py_XDECREF(olditem); ++ Py_XSETREF(*p, newitem); return 0; } diff --cc Objects/typeobject.c index 46fb27e339,7628ce7413..a01862d3d9 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@@ -2123,8 -2115,10 +2123,8 @@@ subtype_setdict(PyObject *obj, PyObjec "not a '%.200s'", Py_TYPE(value)->tp_name); return -1; } - dict = *dictptr; Py_XINCREF(value); - Py_SETREF(*dictptr, value); - *dictptr = value; - Py_XDECREF(dict); ++ Py_XSETREF(*dictptr, value); return 0; } diff --cc Python/import.c index 22f94f5f18,0b843dafd3..0608924e43 --- a/Python/import.c +++ b/Python/import.c @@@ -883,8 -883,10 +883,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); ++ Py_XSETREF(co->co_filename, newname); constants = co->co_consts; n = PyTuple_GET_SIZE(constants); @@@ -1329,8 -1331,10 +1329,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_SETREF(*outer_link, next); - Py_DECREF(tmp); ++ Py_XSETREF(*outer_link, next); prev_link = outer_link; } else { diff --cc Python/peephole.c index c33bf1a7e1,59ad3b762f..2b2e4c420a --- a/Python/peephole.c +++ b/Python/peephole.c @@@ -118,7 -118,9 +118,7 @@@ tuple_of_constants(unsigned char *codes /* 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) { - Py_SETREF(newconst, PyFrozenSet_New(newconst)); - PyObject *tuple = newconst; - newconst = PyFrozenSet_New(tuple); - Py_DECREF(tuple); ++ Py_XSETREF(newconst, PyFrozenSet_New(newconst)); if (newconst == NULL) return 0; } diff --cc Python/sysmodule.c index c5b4ac1ae9,8d7e05a465..0c68c544b0 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@@ -436,7 -434,10 +436,7 @@@ trace_trampoline(PyObject *self, PyFram return -1; } if (result != Py_None) { - Py_SETREF(frame->f_trace, result); - PyObject *temp = frame->f_trace; - frame->f_trace = NULL; - Py_XDECREF(temp); - frame->f_trace = result; ++ Py_XSETREF(frame->f_trace, result); } else { Py_DECREF(result);