Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 10 Apr 2016 15:12:01 +0000 (18:12 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 10 Apr 2016 15:12:01 +0000 (18:12 +0300)
in places where Py_DECREF was used.

19 files changed:
1  2 
Include/object.h
Modules/_ctypes/_ctypes.c
Modules/_curses_panel.c
Modules/_datetimemodule.c
Modules/_elementtree.c
Modules/_io/bytesio.c
Modules/_sqlite/connection.c
Modules/_sqlite/cursor.c
Modules/_sre.c
Modules/_ssl.c
Modules/itertoolsmodule.c
Modules/zlibmodule.c
Objects/bytesobject.c
Objects/funcobject.c
Objects/listobject.c
Objects/typeobject.c
Objects/unicodeobject.c
Python/_warnings.c
Python/ceval.c

Simple merge
index 2bf088a13044b706539307f7c50d262da0cb9d20,7e20301ec1b649e58c5861320949b9699a6876bd..060dca577c387c0a8fc4d921b5f5fdeec57c8935
@@@ -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_XSETREF(((PyBaseExceptionObject *)self)->args, args);
 -    Py_SETREF(bself->args, args);
++    Py_SETREF(((PyBaseExceptionObject *)self)->args, args);
  
      return 0;
  }
Simple merge
index e5191a0f167262bca2497975a6aa0eb0643252c4,0e50023eead3e6f224e2e67061e1b5dfc424a170..261c4bc6e707ae7265c1c25ba21738639da02a67
@@@ -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_XSETREF(offset, delta_negative((PyDateTime_Delta *)offset));
 -        offset = delta_negative((PyDateTime_Delta *)offset);
 -        Py_DECREF(temp);
++        Py_SETREF(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_XSETREF(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_SETREF(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_XSETREF(result, delta_subtract(result, offdiff));
 -                PyObject *temp = result;
 -                result = delta_subtract(result, offdiff);
 -                Py_DECREF(temp);
++                Py_SETREF(result, delta_subtract(result, offdiff));
                  Py_DECREF(offdiff);
              }
          }
index 5c49c151c1cb00651f045961fc01ae19ea002b9e,0f1d6a1faa40c89e607c5c3dac0b44158677f0f0..63639c72e7e1b812b297113dc46629cda4a1d39f
@@@ -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_XSETREF(self->tag, value);
++    Py_SETREF(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_SETREF(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_SETREF(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_XSETREF(self->extra->attrib, value);
++    Py_SETREF(self->extra->attrib, value);
      return 0;
  }
  
index 84d2c5d813d8e3a03295164560d25aaa7c4121c2,49174b449e2693d3fce9aa357cb5d9a237ff5e51..ca3a639cd0d9e42d551eea8ba8cbe5b6265a17dd
@@@ -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_XSETREF(self->buf, new_buf);
 -    old_buf = self->buf;
 -    self->buf = new_buf;
 -    Py_DECREF(old_buf);
++    Py_SETREF(self->buf, new_buf);
      return 0;
  }
  
Simple merge
Simple merge
diff --cc Modules/_sre.c
Simple merge
diff --cc Modules/_ssl.c
Simple merge
index 532ce012b0136730a27d7e2d42045a6aa70f9a86,781fbcdf1a5f6191c8110f05a5ef3b0eb33a2646..1d550fadad4c4952e6002241feed54252aa971a0
@@@ -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_XSETREF(lz->total, newtotal);
++    Py_SETREF(lz->total, newtotal);
      return newtotal;
  }
  
Simple merge
Simple merge
Simple merge
index 7c02be7276f128642ce5dc7e6835eb69c3164eb1,d688179d6b4d12340f8b6155c3c123409ee0cb7d..6e2d026e957105ca1243d1ba4e967d5554586615
@@@ -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_XSETREF(a->ob_item[i], 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;
  }
  
Simple merge
Simple merge
Simple merge
diff --cc Python/ceval.c
Simple merge