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:36:18 +02:00
parent a5892abf23
commit 4a1e70fc31
11 changed files with 63 additions and 106 deletions

View File

@ -540,9 +540,8 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
if (d->eof) { if (d->eof) {
d->needs_input = 0; d->needs_input = 0;
if (d->bzs_avail_in_real > 0) { if (d->bzs_avail_in_real > 0) {
Py_CLEAR(d->unused_data); Py_SETREF(d->unused_data,
d->unused_data = PyBytes_FromStringAndSize( PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real));
bzs->next_in, d->bzs_avail_in_real);
if (d->unused_data == NULL) if (d->unused_data == NULL)
goto error; goto error;
} }

View File

@ -1196,8 +1196,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)
@ -1452,9 +1451,8 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
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;
@ -1805,9 +1803,8 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
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;
@ -2309,9 +2306,8 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
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

@ -995,8 +995,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
"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;
} }
} }
@ -1374,8 +1373,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
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;
} }
@ -1523,8 +1521,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
dec_buffer = NULL; /* Reference lost to PyBytes_Concat */ dec_buffer = NULL; /* Reference lost to PyBytes_Concat */
goto fail; goto fail;
} }
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);
@ -1630,8 +1627,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
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);

View File

@ -1011,9 +1011,8 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
if (d->eof) { if (d->eof) {
d->needs_input = 0; d->needs_input = 0;
if (lzs->avail_in > 0) { if (lzs->avail_in > 0) {
Py_CLEAR(d->unused_data); Py_SETREF(d->unused_data,
d->unused_data = PyBytes_FromStringAndSize( PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in));
(char *)lzs->next_in, lzs->avail_in);
if (d->unused_data == NULL) if (d->unused_data == NULL)
goto error; goto error;
} }

View File

@ -846,9 +846,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
static int static int
_Pickler_ClearBuffer(PicklerObject *self) _Pickler_ClearBuffer(PicklerObject *self)
{ {
Py_CLEAR(self->output_buffer); Py_SETREF(self->output_buffer,
self->output_buffer = PyBytes_FromStringAndSize(NULL, self->max_output_len));
PyBytes_FromStringAndSize(NULL, self->max_output_len);
if (self->output_buffer == NULL) if (self->output_buffer == NULL)
return -1; return -1;
self->output_len = 0; self->output_len = 0;
@ -3089,9 +3088,8 @@ fix_imports(PyObject **module_name, PyObject **global_name)
Py_TYPE(item)->tp_name); Py_TYPE(item)->tp_name);
return -1; return -1;
} }
Py_CLEAR(*module_name);
Py_INCREF(item); Py_INCREF(item);
*module_name = item; Py_SETREF(*module_name, item);
} }
else if (PyErr_Occurred()) { else if (PyErr_Occurred()) {
return -1; return -1;

View File

@ -1437,8 +1437,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
return -1; return -1;
} }
Py_CLEAR(soself->s_format); Py_SETREF(soself->s_format, o_format);
soself->s_format = o_format;
ret = prepare_s(soself); ret = prepare_s(soself);
return ret; return ret;

View File

@ -793,8 +793,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0);
if (r == NULL) { if (r == NULL) {
/* recover the original pending buffer */ /* recover the original pending buffer */
Py_CLEAR(ctx->pending); Py_SETREF(ctx->pending, origpending);
ctx->pending = origpending;
origpending = NULL; origpending = NULL;
goto errorexit; goto errorexit;
} }

View File

@ -159,15 +159,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state)
PyObject *currkey, *currvalue, *tgtkey; PyObject *currkey, *currvalue, *tgtkey;
if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey))
return NULL; return NULL;
Py_CLEAR(lz->currkey); Py_INCREF(currkey);
lz->currkey = currkey; Py_SETREF(lz->currkey, currkey);
Py_INCREF(lz->currkey); Py_INCREF(currvalue);
Py_CLEAR(lz->currvalue); Py_SETREF(lz->currvalue, currvalue);
lz->currvalue = currvalue; Py_INCREF(tgtkey);
Py_INCREF(lz->currvalue); Py_SETREF(lz->tgtkey, tgtkey);
Py_CLEAR(lz->tgtkey);
lz->tgtkey = tgtkey;
Py_INCREF(lz->tgtkey);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -747,9 +744,8 @@ tee_setstate(teeobject *to, PyObject *state)
PyErr_SetString(PyExc_ValueError, "Index out of range"); PyErr_SetString(PyExc_ValueError, "Index out of range");
return NULL; return NULL;
} }
Py_CLEAR(to->dataobj); Py_INCREF(tdo);
to->dataobj = tdo; Py_SETREF(to->dataobj, tdo);
Py_INCREF(to->dataobj);
to->index = index; to->index = index;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -974,9 +970,8 @@ cycle_setstate(cycleobject *lz, PyObject *state)
int firstpass; int firstpass;
if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass)) if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass))
return NULL; return NULL;
Py_CLEAR(lz->saved); Py_XINCREF(saved);
lz->saved = saved; Py_SETREF(lz->saved, saved);
Py_XINCREF(lz->saved);
lz->firstpass = firstpass != 0; lz->firstpass = firstpass != 0;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -1901,12 +1896,10 @@ chain_setstate(chainobject *lz, PyObject *state)
if (! PyArg_ParseTuple(state, "O|O", &source, &active)) if (! PyArg_ParseTuple(state, "O|O", &source, &active))
return NULL; return NULL;
Py_CLEAR(lz->source); Py_INCREF(source);
lz->source = source; Py_SETREF(lz->source, source);
Py_INCREF(lz->source); Py_XINCREF(active);
Py_CLEAR(lz->active); Py_SETREF(lz->active, active);
lz->active = active;
Py_XINCREF(lz->active);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -2262,8 +2255,7 @@ product_setstate(productobject *lz, PyObject *state)
Py_INCREF(element); Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element); PyTuple_SET_ITEM(result, i, element);
} }
Py_CLEAR(lz->result); Py_SETREF(lz->result, result);
lz->result = result;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -2585,8 +2577,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
PyTuple_SET_ITEM(result, i, element); PyTuple_SET_ITEM(result, i, element);
} }
Py_CLEAR(lz->result); Py_SETREF(lz->result, result);
lz->result = result;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -2916,8 +2907,7 @@ cwr_setstate(cwrobject *lz, PyObject *state)
Py_INCREF(element); Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element); PyTuple_SET_ITEM(result, i, element);
} }
Py_CLEAR(lz->result); Py_SETREF(lz->result, result);
lz->result = result;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -3310,8 +3300,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
Py_INCREF(element); Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element); PyTuple_SET_ITEM(result, i, element);
} }
Py_CLEAR(po->result); Py_SETREF(po->result, result);
po->result = result;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -3481,9 +3470,8 @@ accumulate_reduce(accumulateobject *lz)
static PyObject * static PyObject *
accumulate_setstate(accumulateobject *lz, PyObject *state) accumulate_setstate(accumulateobject *lz, PyObject *state)
{ {
Py_CLEAR(lz->total); Py_INCREF(state);
lz->total = state; Py_SETREF(lz->total, state);
Py_INCREF(lz->total);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -4464,9 +4452,8 @@ zip_longest_reduce(ziplongestobject *lz)
static PyObject * static PyObject *
zip_longest_setstate(ziplongestobject *lz, PyObject *state) zip_longest_setstate(ziplongestobject *lz, PyObject *state)
{ {
Py_CLEAR(lz->fillvalue); Py_INCREF(state);
lz->fillvalue = state; Py_SETREF(lz->fillvalue, state);
Py_INCREF(lz->fillvalue);
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@ -206,8 +206,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;
} }
@ -646,9 +645,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg)) if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg))
return -1; return -1;
Py_CLEAR(self->msg); /* replacing */ Py_INCREF(msg);
self->msg = msg; Py_SETREF(self->msg, msg);
Py_INCREF(self->msg);
return 0; return 0;
} }
@ -858,8 +856,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
#endif #endif
/* Steals the reference to args */ /* Steals the reference to args */
Py_CLEAR(self->args); Py_SETREF(self->args, args);
self->args = args;
*p_args = args = NULL; *p_args = args = NULL;
return 0; return 0;
@ -1278,9 +1275,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);
@ -1295,21 +1291,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);
@ -1554,8 +1546,7 @@ set_unicodefromstring(PyObject **attr, const char *value)
PyObject *obj = PyUnicode_FromString(value); PyObject *obj = PyUnicode_FromString(value);
if (!obj) if (!obj)
return -1; return -1;
Py_CLEAR(*attr); Py_SETREF(*attr, obj);
*attr = obj;
return 0; return 0;
} }
@ -1961,8 +1952,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
Py_buffer view; Py_buffer view;
if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0) if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0)
goto error; goto error;
Py_CLEAR(ude->object); Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len));
ude->object = PyBytes_FromStringAndSize(view.buf, view.len);
PyBuffer_Release(&view); PyBuffer_Release(&view);
if (!ude->object) if (!ude->object)
goto error; goto error;
@ -2871,9 +2861,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
} }
if (PyUnicode_Tailmatch(self->text, print_prefix, if (PyUnicode_Tailmatch(self->text, print_prefix,
start, text_len, -1)) { start, text_len, -1)) {
Py_CLEAR(self->msg); Py_SETREF(self->msg,
self->msg = PyUnicode_FromString( PyUnicode_FromString("Missing parentheses in call to 'print'"));
"Missing parentheses in call to 'print'");
return 1; return 1;
} }
@ -2886,9 +2875,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
} }
if (PyUnicode_Tailmatch(self->text, exec_prefix, if (PyUnicode_Tailmatch(self->text, exec_prefix,
start, text_len, -1)) { start, text_len, -1)) {
Py_CLEAR(self->msg); Py_SETREF(self->msg,
self->msg = PyUnicode_FromString( PyUnicode_FromString("Missing parentheses in call to 'exec'"));
"Missing parentheses in call to 'exec'");
return 1; return 1;
} }
/* Fall back to the default error message */ /* Fall back to the default error message */

View File

@ -1001,8 +1001,7 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
return NULL; return NULL;
cmp = PyObject_RichCompareBool(state, zero, Py_LT); cmp = PyObject_RichCompareBool(state, zero, Py_LT);
if (cmp > 0) { if (cmp > 0) {
Py_CLEAR(r->index); Py_SETREF(r->index, zero);
r->index = zero;
Py_RETURN_NONE; Py_RETURN_NONE;
} }
Py_DECREF(zero); Py_DECREF(zero);
@ -1015,9 +1014,8 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
if (cmp > 0) if (cmp > 0)
state = r->len; state = r->len;
Py_CLEAR(r->index); Py_INCREF(state);
r->index = state; Py_SETREF(r->index, state);
Py_INCREF(r->index);
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@ -4410,10 +4410,8 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper)
{ {
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
Py_CLEAR(tstate->coroutine_wrapper);
Py_XINCREF(wrapper); Py_XINCREF(wrapper);
tstate->coroutine_wrapper = wrapper; Py_SETREF(tstate->coroutine_wrapper, wrapper);
} }
PyObject * PyObject *