]> granicus.if.org Git - python/commitdiff
Issue #22570: Renamed Py_SETREF to Py_XSETREF.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 6 Apr 2016 06:50:03 +0000 (09:50 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 6 Apr 2016 06:50:03 +0000 (09:50 +0300)
41 files changed:
1  2 
Include/object.h
Modules/_csv.c
Modules/_ctypes/_ctypes.c
Modules/_curses_panel.c
Modules/_datetimemodule.c
Modules/_decimal/_decimal.c
Modules/_elementtree.c
Modules/_io/bufferedio.c
Modules/_io/bytesio.c
Modules/_io/textio.c
Modules/_lsprof.c
Modules/_pickle.c
Modules/_sqlite/connection.c
Modules/_sqlite/cursor.c
Modules/_sre.c
Modules/_ssl.c
Modules/_struct.c
Modules/faulthandler.c
Modules/itertoolsmodule.c
Modules/pyexpat.c
Modules/readline.c
Modules/zlibmodule.c
Objects/bytesobject.c
Objects/descrobject.c
Objects/exceptions.c
Objects/floatobject.c
Objects/frameobject.c
Objects/funcobject.c
Objects/genobject.c
Objects/listobject.c
Objects/object.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Parser/tokenizer.c
Python/_warnings.c
Python/ceval.c
Python/compile.c
Python/import.c
Python/peephole.c
Python/sysmodule.c

Simple merge
diff --cc Modules/_csv.c
Simple merge
index 9f7bcf807c19df79d7f85d7bdf08e07042c6ba8c,1b804ae1b581727ada0ccf67002feafc393750e7..2bf088a13044b706539307f7c50d262da0cb9d20
@@@ -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;
  }
Simple merge
index 261c4bc6e707ae7265c1c25ba21738639da02a67,0e50023eead3e6f224e2e67061e1b5dfc424a170..e5191a0f167262bca2497975a6aa0eb0643252c4
@@@ -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);
              }
          }
index 3c2ad851baf3adbfa724db88f39c6023c7b392fe,112b44fda7b5846428e11ce54c35697869ad726d..0c02d28db77d3609bbd093f8b2106cad735f1499
@@@ -3380,106 -3380,6 +3380,106 @@@ dec_as_long(PyObject *dec, PyObject *co
      return (PyObject *) pylong;
  }
  
-     Py_SETREF(exponent, long_methods->nb_power(tmp, exponent, Py_None));
 +/* 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(numerator, long_methods->nb_multiply(numerator, exponent));
++    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_floor_divide(numerator, tmp));
-         Py_SETREF(denominator, long_methods->nb_floor_divide(denominator, tmp));
++        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_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)
  {
index 0effc3f32a7530029795da7a9de40fe607b175dd,6619048e27896269f68623d1372adc230b489d83..5c49c151c1cb00651f045961fc01ae19ea002b9e
@@@ -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);
Simple merge
index 6333e46438fc0e402adb1c7cffb6d590d351e3e6,49174b449e2693d3fce9aa357cb5d9a237ff5e51..84d2c5d813d8e3a03295164560d25aaa7c4121c2
@@@ -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;
  }
  
Simple merge
index d3ed758e8a1ef685adb8bd21f646da9bf4f389b1,66e534f2a843b4f9cd8c7d83e42aa5966704f38a..ccfb513038c80ddcae706e0a4280a9d4709093a6
@@@ -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_SETREF(pObj->externalTimer, timer);
 +    Py_XINCREF(timer);
++    Py_XSETREF(pObj->externalTimer, timer);
      return 0;
  }
  
index 5c3530b96265ea70fe7e214049e9fd7df86d6111,1acf14ade870e0b6c121f35b26e5ecdb6980ab56..049b737ad417c1177d4c3b83c627d0fe0c726819
@@@ -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;
  }
Simple merge
Simple merge
diff --cc Modules/_sre.c
Simple merge
diff --cc Modules/_ssl.c
Simple merge
Simple merge
Simple merge
index 9fb9d7487cdc90a2c7f5082a4f80935fd4010201,a7f1111777ca1ae49eee8f64722b91deeee323ab..532ce012b0136730a27d7e2d42045a6aa70f9a86
@@@ -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;
  }
  
index c6d35150b3dd9ee6401b10fab95c65e0bf4971fd,9a6da737fb361f4ef50c43f0e49b029a7fec120e..2dafbb03a5475ad62e88dd6707096bb91fcb840f
@@@ -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;
      }
index 27459d0dfb2890b373100b9c761849158f566f1d,63be9b487e2223cc9733adbd6aa76705d1dcd560..a323b696228a801164759f1399efbc851f8e77a5
@@@ -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,
Simple merge
Simple merge
Simple merge
index 73743681645b749edb4307a78e8f00c0bc0b654b,d03aadac790819827ba40b8c2e9c522551ab9191..2c7688ca6249bb64b57ca052d59552544fe735c9
@@@ -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);
  }
  
  
index eb60659615fbec5f08436e61388bfa5342580151,d92bec35b5f8819270bd9152ad11cbd8bdc1b6dd..32a0de1f3bbf36d8c4ba0d37dd46e151aeb08ba3
@@@ -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);
index da2d2ed2154d95a8212a079075fb8179684f085f,bdf06db33540101576111ebe1f956ba70078d61f..a4a862a4b28603d81a90e756faf3700ce6a97ae2
@@@ -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;
  }
index 29676346c437d0f1bb2bc9c81eeb2378a04ae0cc,4252e930bd516372d40078eacf82d3b18ef62c36..c5f1a0a11ea6a60dfd53281ed3a8dbd82286467f
@@@ -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;
  }
  
index fdb3c031d3f002ec06ddfdd39f26a4ac6e4a4c10,f74d044dcf7a96bde132a64e97de15886fe44a25..c94a6ed53a0d08f32196fa2bf8e02ecf254808b7
@@@ -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;
  }
  
index 81b40ae355b2051cfa6425a733f2260f84ba7fae,d688179d6b4d12340f8b6155c3c123409ee0cb7d..7c02be7276f128642ce5dc7e6835eb69c3164eb1
@@@ -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;
  }
  
index 8072dbced204567d769c29b0fda5fdc056ed2cea,6fc4df16397aac74ce02b440425c844e7130ab3c..0817311d53d1476a577af53fbaaf0dd96f722fe8
@@@ -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;
  }
  
index 5020aff3f4b67c4bd3eeb413489f3e9ff4c45a68,7920fec2bd86e8854f110afe8818e85737a66fc6..a7774e2fd1a27a84271aedfcf7163f3c506631bf
@@@ -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;
  }
  
index 46fb27e3397c2aa95ca1c06b49edf35e4b0299cd,7628ce7413b482c910e15f422d597dd50df6d3f4..a01862d3d9e51ce40e0ace4c5ae88db31f9dca4a
@@@ -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;
  }
  
Simple merge
Simple merge
Simple merge
diff --cc Python/ceval.c
Simple merge
Simple merge
diff --cc Python/import.c
index 22f94f5f182fdd169f4346f677e92be781bf4319,0b843dafd3df21d2d04877e77d0b9de0025931b3..0608924e4333238200fcc7c3342d720d1d14d346
@@@ -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 {
index c33bf1a7e1438d60ac0cc1d5ccced7e6f5c0d350,59ad3b762f8bf6eacd301159591198cf45d0b133..2b2e4c420ad7a3642920548491d4dbe13b964555
@@@ -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;
      }
index c5b4ac1ae9b5deaa4a873ff1f8cd2512bf60f23b,8d7e05a465a1569f7e875d665eed01a37c5b9797..0c68c544b0435912804f614a58db7d4765d238b1
@@@ -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);