Issue #20440: Applied yet one patch for using Py_SETREF.

The patch is automatically generated, it replaces the code that uses Py_CLEAR.
This commit is contained in:
Serhiy Storchaka 2015-12-27 12:38:48 +02:00
parent 82ea0f9517
commit 8688acaf2e
4 changed files with 33 additions and 57 deletions

View File

@ -1028,8 +1028,7 @@ found:
Py_CLEAR(res); Py_CLEAR(res);
goto end; goto end;
} }
Py_CLEAR(res); Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks));
res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
end: end:
LEAVE_BUFFERED(self) LEAVE_BUFFERED(self)
@ -1264,9 +1263,8 @@ bufferedreader_init(buffered *self, PyObject *args, PyObject *kwds)
if (_PyIOBase_check_readable(raw, Py_True) == NULL) if (_PyIOBase_check_readable(raw, Py_True) == NULL)
return -1; return -1;
Py_CLEAR(self->raw);
Py_INCREF(raw); Py_INCREF(raw);
self->raw = raw; Py_SETREF(self->raw, raw);
self->buffer_size = buffer_size; self->buffer_size = buffer_size;
self->readable = 1; self->readable = 1;
self->writable = 0; self->writable = 0;
@ -1687,9 +1685,8 @@ bufferedwriter_init(buffered *self, PyObject *args, PyObject *kwds)
if (_PyIOBase_check_writable(raw, Py_True) == NULL) if (_PyIOBase_check_writable(raw, Py_True) == NULL)
return -1; return -1;
Py_CLEAR(self->raw);
Py_INCREF(raw); Py_INCREF(raw);
self->raw = raw; Py_SETREF(self->raw, raw);
self->readable = 0; self->readable = 0;
self->writable = 1; self->writable = 1;
@ -2344,9 +2341,8 @@ bufferedrandom_init(buffered *self, PyObject *args, PyObject *kwds)
if (_PyIOBase_check_writable(raw, Py_True) == NULL) if (_PyIOBase_check_writable(raw, Py_True) == NULL)
return -1; return -1;
Py_CLEAR(self->raw);
Py_INCREF(raw); Py_INCREF(raw);
self->raw = raw; Py_SETREF(self->raw, raw);
self->buffer_size = buffer_size; self->buffer_size = buffer_size;
self->readable = 1; self->readable = 1;
self->writable = 1; self->writable = 1;

View File

@ -966,8 +966,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
"Oi", self->decoder, (int)self->readtranslate); "Oi", self->decoder, (int)self->readtranslate);
if (incrementalDecoder == NULL) if (incrementalDecoder == NULL)
goto error; goto error;
Py_CLEAR(self->decoder); Py_SETREF(self->decoder, incrementalDecoder);
self->decoder = incrementalDecoder;
} }
} }
@ -1347,8 +1346,7 @@ textiowrapper_write(textio *self, PyObject *args)
static void static void
textiowrapper_set_decoded_chars(textio *self, PyObject *chars) textiowrapper_set_decoded_chars(textio *self, PyObject *chars)
{ {
Py_CLEAR(self->decoded_chars); Py_SETREF(self->decoded_chars, chars);
self->decoded_chars = chars;
self->decoded_chars_used = 0; self->decoded_chars_used = 0;
} }
@ -1477,8 +1475,7 @@ textiowrapper_read_chunk(textio *self)
goto fail; goto fail;
} }
Py_DECREF(dec_buffer); Py_DECREF(dec_buffer);
Py_CLEAR(self->snapshot); Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input));
self->snapshot = Py_BuildValue("NN", dec_flags, next_input);
} }
Py_DECREF(input_chunk); Py_DECREF(input_chunk);
@ -1578,8 +1575,7 @@ textiowrapper_read(textio *self, PyObject *args)
if (chunks != NULL) { if (chunks != NULL) {
if (result != NULL && PyList_Append(chunks, result) < 0) if (result != NULL && PyList_Append(chunks, result) < 0)
goto fail; goto fail;
Py_CLEAR(result); Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks));
result = PyUnicode_Join(_PyIO_empty_str, chunks);
if (result == NULL) if (result == NULL)
goto fail; goto fail;
Py_CLEAR(chunks); Py_CLEAR(chunks);
@ -1836,8 +1832,7 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
if (chunks != NULL) { if (chunks != NULL) {
if (line != NULL && PyList_Append(chunks, line) < 0) if (line != NULL && PyList_Append(chunks, line) < 0)
goto error; goto error;
Py_CLEAR(line); Py_SETREF(line, PyUnicode_Join(_PyIO_empty_str, chunks));
line = PyUnicode_Join(_PyIO_empty_str, chunks);
if (line == NULL) if (line == NULL)
goto error; goto error;
Py_DECREF(chunks); Py_DECREF(chunks);

View File

@ -1377,15 +1377,13 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
if (PyString_Check(o_format)) { if (PyString_Check(o_format)) {
Py_INCREF(o_format); Py_INCREF(o_format);
Py_CLEAR(soself->s_format); Py_SETREF(soself->s_format, o_format);
soself->s_format = o_format;
} }
else if (PyUnicode_Check(o_format)) { else if (PyUnicode_Check(o_format)) {
PyObject *str = PyUnicode_AsEncodedString(o_format, "ascii", NULL); PyObject *str = PyUnicode_AsEncodedString(o_format, "ascii", NULL);
if (str == NULL) if (str == NULL)
return -1; return -1;
Py_CLEAR(soself->s_format); Py_SETREF(soself->s_format, str);
soself->s_format = str;
} }
else { else {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,

View File

@ -62,9 +62,8 @@ BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
Py_SETREF(self->args, args); Py_SETREF(self->args, args);
if (PyTuple_GET_SIZE(self->args) == 1) { if (PyTuple_GET_SIZE(self->args) == 1) {
Py_CLEAR(self->message); Py_INCREF(PyTuple_GET_ITEM(self->args, 0));
self->message = PyTuple_GET_ITEM(self->args, 0); Py_SETREF(self->message, PyTuple_GET_ITEM(self->args, 0));
Py_INCREF(self->message);
} }
return 0; return 0;
} }
@ -279,9 +278,8 @@ BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val)
PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary"); PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary");
return -1; return -1;
} }
Py_CLEAR(self->dict);
Py_INCREF(val); Py_INCREF(val);
self->dict = val; Py_SETREF(self->dict, val);
return 0; return 0;
} }
@ -307,8 +305,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
seq = PySequence_Tuple(val); seq = PySequence_Tuple(val);
if (!seq) if (!seq)
return -1; return -1;
Py_CLEAR(self->args); Py_SETREF(self->args, seq);
self->args = seq;
return 0; return 0;
} }
@ -608,19 +605,16 @@ EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args,
&myerrno, &strerror, &filename)) { &myerrno, &strerror, &filename)) {
return -1; return -1;
} }
Py_CLEAR(self->myerrno); /* replacing */ Py_INCREF(myerrno);
self->myerrno = myerrno; Py_SETREF(self->myerrno, myerrno);
Py_INCREF(self->myerrno);
Py_CLEAR(self->strerror); /* replacing */ Py_INCREF(strerror);
self->strerror = strerror; Py_SETREF(self->strerror, strerror);
Py_INCREF(self->strerror);
/* self->filename will remain Py_None otherwise */ /* self->filename will remain Py_None otherwise */
if (filename != NULL) { if (filename != NULL) {
Py_CLEAR(self->filename); /* replacing */ Py_INCREF(filename);
self->filename = filename; Py_SETREF(self->filename, filename);
Py_INCREF(self->filename);
subslice = PyTuple_GetSlice(args, 0, 2); subslice = PyTuple_GetSlice(args, 0, 2);
if (!subslice) if (!subslice)
@ -877,8 +871,7 @@ WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds)
return -1; return -1;
posix_errno = winerror_to_errno(errcode); posix_errno = winerror_to_errno(errcode);
Py_CLEAR(self->winerror); Py_SETREF(self->winerror, self->myerrno);
self->winerror = self->myerrno;
o_errcode = PyInt_FromLong(posix_errno); o_errcode = PyInt_FromLong(posix_errno);
if (!o_errcode) if (!o_errcode)
@ -1063,9 +1056,8 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
return -1; return -1;
if (lenargs >= 1) { if (lenargs >= 1) {
Py_CLEAR(self->msg); Py_INCREF(PyTuple_GET_ITEM(args, 0));
self->msg = PyTuple_GET_ITEM(args, 0); Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0));
Py_INCREF(self->msg);
} }
if (lenargs == 2) { if (lenargs == 2) {
info = PyTuple_GET_ITEM(args, 1); info = PyTuple_GET_ITEM(args, 1);
@ -1080,21 +1072,17 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
return -1; return -1;
} }
Py_CLEAR(self->filename); Py_INCREF(PyTuple_GET_ITEM(info, 0));
self->filename = PyTuple_GET_ITEM(info, 0); Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0));
Py_INCREF(self->filename);
Py_CLEAR(self->lineno); Py_INCREF(PyTuple_GET_ITEM(info, 1));
self->lineno = PyTuple_GET_ITEM(info, 1); Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1));
Py_INCREF(self->lineno);
Py_CLEAR(self->offset); Py_INCREF(PyTuple_GET_ITEM(info, 2));
self->offset = PyTuple_GET_ITEM(info, 2); Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2));
Py_INCREF(self->offset);
Py_CLEAR(self->text); Py_INCREF(PyTuple_GET_ITEM(info, 3));
self->text = PyTuple_GET_ITEM(info, 3); Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3));
Py_INCREF(self->text);
Py_DECREF(info); Py_DECREF(info);
} }
@ -1327,8 +1315,7 @@ set_string(PyObject **attr, const char *value)
PyObject *obj = PyString_FromString(value); PyObject *obj = PyString_FromString(value);
if (!obj) if (!obj)
return -1; return -1;
Py_CLEAR(*attr); Py_SETREF(*attr, obj);
*attr = obj;
return 0; return 0;
} }