[Python-checkins] cpython (2.7): Issue #20440: Applied yet one patch for using Py_SETREF.
serhiy.storchaka
python-checkins at python.org
Sun Dec 27 05:44:04 EST 2015
https://hg.python.org/cpython/rev/e6502bf289ab
changeset: 99686:e6502bf289ab
branch: 2.7
parent: 99678:512a628c683e
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Dec 27 12:38:48 2015 +0200
summary:
Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
files:
Modules/_io/bufferedio.c | 12 +---
Modules/_io/textio.c | 15 ++----
Modules/_struct.c | 6 +-
Objects/exceptions.c | 57 ++++++++++-----------------
4 files changed, 33 insertions(+), 57 deletions(-)
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1028,8 +1028,7 @@
Py_CLEAR(res);
goto end;
}
- Py_CLEAR(res);
- res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
+ Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks));
end:
LEAVE_BUFFERED(self)
@@ -1264,9 +1263,8 @@
if (_PyIOBase_check_readable(raw, Py_True) == NULL)
return -1;
- Py_CLEAR(self->raw);
Py_INCREF(raw);
- self->raw = raw;
+ Py_SETREF(self->raw, raw);
self->buffer_size = buffer_size;
self->readable = 1;
self->writable = 0;
@@ -1687,9 +1685,8 @@
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
return -1;
- Py_CLEAR(self->raw);
Py_INCREF(raw);
- self->raw = raw;
+ Py_SETREF(self->raw, raw);
self->readable = 0;
self->writable = 1;
@@ -2344,9 +2341,8 @@
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
return -1;
- Py_CLEAR(self->raw);
Py_INCREF(raw);
- self->raw = raw;
+ Py_SETREF(self->raw, raw);
self->buffer_size = buffer_size;
self->readable = 1;
self->writable = 1;
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -966,8 +966,7 @@
"Oi", self->decoder, (int)self->readtranslate);
if (incrementalDecoder == NULL)
goto error;
- Py_CLEAR(self->decoder);
- self->decoder = incrementalDecoder;
+ Py_SETREF(self->decoder, incrementalDecoder);
}
}
@@ -1347,8 +1346,7 @@
static void
textiowrapper_set_decoded_chars(textio *self, PyObject *chars)
{
- Py_CLEAR(self->decoded_chars);
- self->decoded_chars = chars;
+ Py_SETREF(self->decoded_chars, chars);
self->decoded_chars_used = 0;
}
@@ -1477,8 +1475,7 @@
goto fail;
}
Py_DECREF(dec_buffer);
- Py_CLEAR(self->snapshot);
- self->snapshot = Py_BuildValue("NN", dec_flags, next_input);
+ Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input));
}
Py_DECREF(input_chunk);
@@ -1578,8 +1575,7 @@
if (chunks != NULL) {
if (result != NULL && PyList_Append(chunks, result) < 0)
goto fail;
- Py_CLEAR(result);
- result = PyUnicode_Join(_PyIO_empty_str, chunks);
+ Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks));
if (result == NULL)
goto fail;
Py_CLEAR(chunks);
@@ -1836,8 +1832,7 @@
if (chunks != NULL) {
if (line != NULL && PyList_Append(chunks, line) < 0)
goto error;
- Py_CLEAR(line);
- line = PyUnicode_Join(_PyIO_empty_str, chunks);
+ Py_SETREF(line, PyUnicode_Join(_PyIO_empty_str, chunks));
if (line == NULL)
goto error;
Py_DECREF(chunks);
diff --git a/Modules/_struct.c b/Modules/_struct.c
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1377,15 +1377,13 @@
if (PyString_Check(o_format)) {
Py_INCREF(o_format);
- Py_CLEAR(soself->s_format);
- soself->s_format = o_format;
+ Py_SETREF(soself->s_format, o_format);
}
else if (PyUnicode_Check(o_format)) {
PyObject *str = PyUnicode_AsEncodedString(o_format, "ascii", NULL);
if (str == NULL)
return -1;
- Py_CLEAR(soself->s_format);
- soself->s_format = str;
+ Py_SETREF(soself->s_format, str);
}
else {
PyErr_Format(PyExc_TypeError,
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -62,9 +62,8 @@
Py_SETREF(self->args, args);
if (PyTuple_GET_SIZE(self->args) == 1) {
- Py_CLEAR(self->message);
- self->message = PyTuple_GET_ITEM(self->args, 0);
- Py_INCREF(self->message);
+ Py_INCREF(PyTuple_GET_ITEM(self->args, 0));
+ Py_SETREF(self->message, PyTuple_GET_ITEM(self->args, 0));
}
return 0;
}
@@ -279,9 +278,8 @@
PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary");
return -1;
}
- Py_CLEAR(self->dict);
Py_INCREF(val);
- self->dict = val;
+ Py_SETREF(self->dict, val);
return 0;
}
@@ -307,8 +305,7 @@
seq = PySequence_Tuple(val);
if (!seq)
return -1;
- Py_CLEAR(self->args);
- self->args = seq;
+ Py_SETREF(self->args, seq);
return 0;
}
@@ -608,19 +605,16 @@
&myerrno, &strerror, &filename)) {
return -1;
}
- Py_CLEAR(self->myerrno); /* replacing */
- self->myerrno = myerrno;
- Py_INCREF(self->myerrno);
+ Py_INCREF(myerrno);
+ Py_SETREF(self->myerrno, myerrno);
- Py_CLEAR(self->strerror); /* replacing */
- self->strerror = strerror;
- Py_INCREF(self->strerror);
+ Py_INCREF(strerror);
+ Py_SETREF(self->strerror, strerror);
/* self->filename will remain Py_None otherwise */
if (filename != NULL) {
- Py_CLEAR(self->filename); /* replacing */
- self->filename = filename;
- Py_INCREF(self->filename);
+ Py_INCREF(filename);
+ Py_SETREF(self->filename, filename);
subslice = PyTuple_GetSlice(args, 0, 2);
if (!subslice)
@@ -877,8 +871,7 @@
return -1;
posix_errno = winerror_to_errno(errcode);
- Py_CLEAR(self->winerror);
- self->winerror = self->myerrno;
+ Py_SETREF(self->winerror, self->myerrno);
o_errcode = PyInt_FromLong(posix_errno);
if (!o_errcode)
@@ -1063,9 +1056,8 @@
return -1;
if (lenargs >= 1) {
- Py_CLEAR(self->msg);
- self->msg = PyTuple_GET_ITEM(args, 0);
- Py_INCREF(self->msg);
+ Py_INCREF(PyTuple_GET_ITEM(args, 0));
+ Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0));
}
if (lenargs == 2) {
info = PyTuple_GET_ITEM(args, 1);
@@ -1080,21 +1072,17 @@
return -1;
}
- Py_CLEAR(self->filename);
- self->filename = PyTuple_GET_ITEM(info, 0);
- Py_INCREF(self->filename);
+ Py_INCREF(PyTuple_GET_ITEM(info, 0));
+ Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0));
- Py_CLEAR(self->lineno);
- self->lineno = PyTuple_GET_ITEM(info, 1);
- Py_INCREF(self->lineno);
+ Py_INCREF(PyTuple_GET_ITEM(info, 1));
+ Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1));
- Py_CLEAR(self->offset);
- self->offset = PyTuple_GET_ITEM(info, 2);
- Py_INCREF(self->offset);
+ Py_INCREF(PyTuple_GET_ITEM(info, 2));
+ Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2));
- Py_CLEAR(self->text);
- self->text = PyTuple_GET_ITEM(info, 3);
- Py_INCREF(self->text);
+ Py_INCREF(PyTuple_GET_ITEM(info, 3));
+ Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3));
Py_DECREF(info);
}
@@ -1327,8 +1315,7 @@
PyObject *obj = PyString_FromString(value);
if (!obj)
return -1;
- Py_CLEAR(*attr);
- *attr = obj;
+ Py_SETREF(*attr, obj);
return 0;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list