[Python-checkins] cpython (merge 3.5 -> default): 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/bc7c56a225de
changeset: 99685:bc7c56a225de
parent: 99683:ba1e102c3320
parent: 99684:9fb57c0209ea
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Dec 27 12:38:28 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/_bz2module.c | 5 +-
Modules/_io/bufferedio.c | 12 +--
Modules/_io/textio.c | 12 +--
Modules/_lzmamodule.c | 5 +-
Modules/_pickle.c | 8 +-
Modules/_struct.c | 3 +-
Modules/cjkcodecs/multibytecodec.c | 3 +-
Modules/itertoolsmodule.c | 55 ++++++----------
Objects/exceptions.c | 58 +++++++----------
Objects/rangeobject.c | 8 +-
Python/ceval.c | 4 +-
11 files changed, 65 insertions(+), 108 deletions(-)
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -540,9 +540,8 @@
if (d->eof) {
d->needs_input = 0;
if (d->bzs_avail_in_real > 0) {
- Py_CLEAR(d->unused_data);
- d->unused_data = PyBytes_FromStringAndSize(
- bzs->next_in, d->bzs_avail_in_real);
+ Py_SETREF(d->unused_data,
+ PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real));
if (d->unused_data == NULL)
goto error;
}
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1196,8 +1196,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)
@@ -1452,9 +1451,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;
@@ -1805,9 +1803,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;
@@ -2309,9 +2306,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
@@ -995,8 +995,7 @@
"Oi", self->decoder, (int)self->readtranslate);
if (incrementalDecoder == NULL)
goto error;
- Py_CLEAR(self->decoder);
- self->decoder = incrementalDecoder;
+ Py_SETREF(self->decoder, incrementalDecoder);
}
}
@@ -1374,8 +1373,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;
}
@@ -1523,8 +1521,7 @@
dec_buffer = NULL; /* Reference lost to PyBytes_Concat */
goto fail;
}
- 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);
@@ -1630,8 +1627,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);
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -1011,9 +1011,8 @@
if (d->eof) {
d->needs_input = 0;
if (lzs->avail_in > 0) {
- Py_CLEAR(d->unused_data);
- d->unused_data = PyBytes_FromStringAndSize(
- (char *)lzs->next_in, lzs->avail_in);
+ Py_SETREF(d->unused_data,
+ PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in));
if (d->unused_data == NULL)
goto error;
}
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -869,9 +869,8 @@
static int
_Pickler_ClearBuffer(PicklerObject *self)
{
- Py_CLEAR(self->output_buffer);
- self->output_buffer =
- PyBytes_FromStringAndSize(NULL, self->max_output_len);
+ Py_SETREF(self->output_buffer,
+ PyBytes_FromStringAndSize(NULL, self->max_output_len));
if (self->output_buffer == NULL)
return -1;
self->output_len = 0;
@@ -3116,9 +3115,8 @@
Py_TYPE(item)->tp_name);
return -1;
}
- Py_CLEAR(*module_name);
Py_INCREF(item);
- *module_name = item;
+ Py_SETREF(*module_name, item);
}
else if (PyErr_Occurred()) {
return -1;
diff --git a/Modules/_struct.c b/Modules/_struct.c
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1437,8 +1437,7 @@
return -1;
}
- Py_CLEAR(soself->s_format);
- soself->s_format = o_format;
+ Py_SETREF(soself->s_format, o_format);
ret = prepare_s(soself);
return ret;
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -793,8 +793,7 @@
ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0);
if (r == NULL) {
/* recover the original pending buffer */
- Py_CLEAR(ctx->pending);
- ctx->pending = origpending;
+ Py_SETREF(ctx->pending, origpending);
origpending = NULL;
goto errorexit;
}
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -158,15 +158,12 @@
PyObject *currkey, *currvalue, *tgtkey;
if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey))
return NULL;
- Py_CLEAR(lz->currkey);
- lz->currkey = currkey;
- Py_INCREF(lz->currkey);
- Py_CLEAR(lz->currvalue);
- lz->currvalue = currvalue;
- Py_INCREF(lz->currvalue);
- Py_CLEAR(lz->tgtkey);
- lz->tgtkey = tgtkey;
- Py_INCREF(lz->tgtkey);
+ Py_INCREF(currkey);
+ Py_SETREF(lz->currkey, currkey);
+ Py_INCREF(currvalue);
+ Py_SETREF(lz->currvalue, currvalue);
+ Py_INCREF(tgtkey);
+ Py_SETREF(lz->tgtkey, tgtkey);
Py_RETURN_NONE;
}
@@ -745,9 +742,8 @@
PyErr_SetString(PyExc_ValueError, "Index out of range");
return NULL;
}
- Py_CLEAR(to->dataobj);
- to->dataobj = tdo;
- Py_INCREF(to->dataobj);
+ Py_INCREF(tdo);
+ Py_SETREF(to->dataobj, tdo);
to->index = index;
Py_RETURN_NONE;
}
@@ -988,8 +984,7 @@
if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass))
return NULL;
Py_INCREF(saved);
- Py_CLEAR(lz->saved);
- lz->saved = saved;
+ Py_SETREF(lz->saved, saved);
lz->firstpass = firstpass != 0;
lz->index = 0;
Py_RETURN_NONE;
@@ -1920,12 +1915,10 @@
if (! PyArg_ParseTuple(state, "O|O", &source, &active))
return NULL;
- Py_CLEAR(lz->source);
- lz->source = source;
- Py_INCREF(lz->source);
- Py_CLEAR(lz->active);
- lz->active = active;
- Py_XINCREF(lz->active);
+ Py_INCREF(source);
+ Py_SETREF(lz->source, source);
+ Py_XINCREF(active);
+ Py_SETREF(lz->active, active);
Py_RETURN_NONE;
}
@@ -2282,8 +2275,7 @@
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -2604,8 +2596,7 @@
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -2935,8 +2926,7 @@
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -3324,8 +3314,7 @@
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(po->result);
- po->result = result;
+ Py_SETREF(po->result, result);
Py_RETURN_NONE;
}
@@ -3495,9 +3484,8 @@
static PyObject *
accumulate_setstate(accumulateobject *lz, PyObject *state)
{
- Py_CLEAR(lz->total);
- lz->total = state;
- Py_INCREF(lz->total);
+ Py_INCREF(state);
+ Py_SETREF(lz->total, state);
Py_RETURN_NONE;
}
@@ -4475,9 +4463,8 @@
static PyObject *
zip_longest_setstate(ziplongestobject *lz, PyObject *state)
{
- Py_CLEAR(lz->fillvalue);
- lz->fillvalue = state;
- Py_INCREF(lz->fillvalue);
+ Py_INCREF(state);
+ Py_SETREF(lz->fillvalue, state);
Py_RETURN_NONE;
}
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -206,8 +206,7 @@
seq = PySequence_Tuple(val);
if (!seq)
return -1;
- Py_CLEAR(self->args);
- self->args = seq;
+ Py_SETREF(self->args, seq);
return 0;
}
@@ -646,9 +645,8 @@
if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg))
return -1;
- Py_CLEAR(self->msg); /* replacing */
- self->msg = msg;
- Py_INCREF(self->msg);
+ Py_INCREF(msg);
+ Py_SETREF(self->msg, msg);
return 0;
}
@@ -858,8 +856,7 @@
#endif
/* Steals the reference to args */
- Py_CLEAR(self->args);
- self->args = args;
+ Py_SETREF(self->args, args);
*p_args = args = NULL;
return 0;
@@ -1278,9 +1275,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);
@@ -1295,21 +1291,17 @@
return -1;
}
- Py_CLEAR(self->filename);
- self->filename = PyTuple_GET_ITEM(info, 0);
- Py_INCREF(self->filename);
-
- Py_CLEAR(self->lineno);
- self->lineno = PyTuple_GET_ITEM(info, 1);
- Py_INCREF(self->lineno);
-
- Py_CLEAR(self->offset);
- self->offset = PyTuple_GET_ITEM(info, 2);
- Py_INCREF(self->offset);
-
- Py_CLEAR(self->text);
- self->text = PyTuple_GET_ITEM(info, 3);
- Py_INCREF(self->text);
+ Py_INCREF(PyTuple_GET_ITEM(info, 0));
+ Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0));
+
+ Py_INCREF(PyTuple_GET_ITEM(info, 1));
+ Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1));
+
+ Py_INCREF(PyTuple_GET_ITEM(info, 2));
+ Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2));
+
+ Py_INCREF(PyTuple_GET_ITEM(info, 3));
+ Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3));
Py_DECREF(info);
@@ -1554,8 +1546,7 @@
PyObject *obj = PyUnicode_FromString(value);
if (!obj)
return -1;
- Py_CLEAR(*attr);
- *attr = obj;
+ Py_SETREF(*attr, obj);
return 0;
}
@@ -1961,8 +1952,7 @@
Py_buffer view;
if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0)
goto error;
- Py_CLEAR(ude->object);
- ude->object = PyBytes_FromStringAndSize(view.buf, view.len);
+ Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len));
PyBuffer_Release(&view);
if (!ude->object)
goto error;
@@ -2871,9 +2861,8 @@
}
if (PyUnicode_Tailmatch(self->text, print_prefix,
start, text_len, -1)) {
- Py_CLEAR(self->msg);
- self->msg = PyUnicode_FromString(
- "Missing parentheses in call to 'print'");
+ Py_SETREF(self->msg,
+ PyUnicode_FromString("Missing parentheses in call to 'print'"));
return 1;
}
@@ -2886,9 +2875,8 @@
}
if (PyUnicode_Tailmatch(self->text, exec_prefix,
start, text_len, -1)) {
- Py_CLEAR(self->msg);
- self->msg = PyUnicode_FromString(
- "Missing parentheses in call to 'exec'");
+ Py_SETREF(self->msg,
+ PyUnicode_FromString("Missing parentheses in call to 'exec'"));
return 1;
}
/* Fall back to the default error message */
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -1001,8 +1001,7 @@
return NULL;
cmp = PyObject_RichCompareBool(state, zero, Py_LT);
if (cmp > 0) {
- Py_CLEAR(r->index);
- r->index = zero;
+ Py_SETREF(r->index, zero);
Py_RETURN_NONE;
}
Py_DECREF(zero);
@@ -1015,9 +1014,8 @@
if (cmp > 0)
state = r->len;
- Py_CLEAR(r->index);
- r->index = state;
- Py_INCREF(r->index);
+ Py_INCREF(state);
+ Py_SETREF(r->index, state);
Py_RETURN_NONE;
}
diff --git a/Python/ceval.c b/Python/ceval.c
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4474,10 +4474,8 @@
{
PyThreadState *tstate = PyThreadState_GET();
- Py_CLEAR(tstate->coroutine_wrapper);
-
Py_XINCREF(wrapper);
- tstate->coroutine_wrapper = wrapper;
+ Py_SETREF(tstate->coroutine_wrapper, wrapper);
}
PyObject *
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list