summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/_bz2module.c5
-rw-r--r--Modules/_io/bufferedio.c12
-rw-r--r--Modules/_io/textio.c12
-rw-r--r--Modules/_lzmamodule.c5
-rw-r--r--Modules/_pickle.c8
-rw-r--r--Modules/_struct.c3
-rw-r--r--Modules/cjkcodecs/multibytecodec.c3
-rw-r--r--Modules/itertoolsmodule.c57
-rw-r--r--Objects/exceptions.c52
-rw-r--r--Objects/rangeobject.c8
-rw-r--r--Python/ceval.c4
11 files changed, 63 insertions, 106 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
index 7dfd307..425845f 100644
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -540,9 +540,8 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
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
index 6bb2200..ae4af9d 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1196,8 +1196,7 @@ found:
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 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
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 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
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 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
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
index b232b02..b1d2b6f 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -995,8 +995,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
"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 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
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 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
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 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
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
index 7e4e2df..9bc8033 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -1011,9 +1011,8 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
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
index 56bbd58..2a070e2 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -846,9 +846,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
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;
@@ -3089,9 +3088,8 @@ fix_imports(PyObject **module_name, PyObject **global_name)
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
index b61f9f6..1f1bb93 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1437,8 +1437,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
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
index e4547f7..70a606f 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -793,8 +793,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
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
index 1c9a173..ccd69be 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -159,15 +159,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state)
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;
}
@@ -747,9 +744,8 @@ tee_setstate(teeobject *to, PyObject *state)
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;
}
@@ -974,9 +970,8 @@ cycle_setstate(cycleobject *lz, PyObject *state)
int firstpass;
if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass))
return NULL;
- Py_CLEAR(lz->saved);
- lz->saved = saved;
- Py_XINCREF(lz->saved);
+ Py_XINCREF(saved);
+ Py_SETREF(lz->saved, saved);
lz->firstpass = firstpass != 0;
Py_RETURN_NONE;
}
@@ -1901,12 +1896,10 @@ chain_setstate(chainobject *lz, PyObject *state)
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;
}
@@ -2262,8 +2255,7 @@ product_setstate(productobject *lz, PyObject *state)
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -2585,8 +2577,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -2916,8 +2907,7 @@ cwr_setstate(cwrobject *lz, PyObject *state)
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(lz->result);
- lz->result = result;
+ Py_SETREF(lz->result, result);
Py_RETURN_NONE;
}
@@ -3310,8 +3300,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
Py_INCREF(element);
PyTuple_SET_ITEM(result, i, element);
}
- Py_CLEAR(po->result);
- po->result = result;
+ Py_SETREF(po->result, result);
Py_RETURN_NONE;
}
@@ -3481,9 +3470,8 @@ accumulate_reduce(accumulateobject *lz)
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;
}
@@ -4464,9 +4452,8 @@ zip_longest_reduce(ziplongestobject *lz)
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
index 62ea378..351304f 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -206,8 +206,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
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 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
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 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
#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 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
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 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
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);
@@ -1554,8 +1546,7 @@ set_unicodefromstring(PyObject **attr, const char *value)
PyObject *obj = PyUnicode_FromString(value);
if (!obj)
return -1;
- Py_CLEAR(*attr);
- *attr = obj;
+ Py_SETREF(*attr, obj);
return 0;
}
@@ -1961,8 +1952,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
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 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
}
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 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
}
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
index f858cd2..45656d2 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -1001,8 +1001,7 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
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 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
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
index 5fa555e..786adbf 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4410,10 +4410,8 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper)
{
PyThreadState *tstate = PyThreadState_GET();
- Py_CLEAR(tstate->coroutine_wrapper);
-
Py_XINCREF(wrapper);
- tstate->coroutine_wrapper = wrapper;
+ Py_SETREF(tstate->coroutine_wrapper, wrapper);
}
PyObject *