Issue #20440: Applied yet one patch for using Py_SETREF. · pythoncapi/cpython@bdb908e · GitHub
Skip to content

Commit bdb908e

Browse files
Issue python#20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
2 parents 40005a7 + 4a1e70f commit bdb908e

11 files changed

Lines changed: 62 additions & 105 deletions

File tree

Modules/_bz2module.c

Lines changed: 2 additions & 3 deletions

Modules/_io/bufferedio.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,7 @@ _buffered_readline(buffered *self, Py_ssize_t limit)
11961196
Py_CLEAR(res);
11971197
goto end;
11981198
}
1199-
Py_CLEAR(res);
1200-
res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
1199+
Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks));
12011200

12021201
end:
12031202
LEAVE_BUFFERED(self)
@@ -1452,9 +1451,8 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
14521451
if (_PyIOBase_check_readable(raw, Py_True) == NULL)
14531452
return -1;
14541453

1455-
Py_CLEAR(self->raw);
14561454
Py_INCREF(raw);
1457-
self->raw = raw;
1455+
Py_SETREF(self->raw, raw);
14581456
self->buffer_size = buffer_size;
14591457
self->readable = 1;
14601458
self->writable = 0;
@@ -1805,9 +1803,8 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
18051803
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
18061804
return -1;
18071805

1808-
Py_CLEAR(self->raw);
18091806
Py_INCREF(raw);
1810-
self->raw = raw;
1807+
Py_SETREF(self->raw, raw);
18111808
self->readable = 0;
18121809
self->writable = 1;
18131810

@@ -2309,9 +2306,8 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
23092306
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
23102307
return -1;
23112308

2312-
Py_CLEAR(self->raw);
23132309
Py_INCREF(raw);
2314-
self->raw = raw;
2310+
Py_SETREF(self->raw, raw);
23152311
self->buffer_size = buffer_size;
23162312
self->readable = 1;
23172313
self->writable = 1;

Modules/_io/textio.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
995995
"Oi", self->decoder, (int)self->readtranslate);
996996
if (incrementalDecoder == NULL)
997997
goto error;
998-
Py_CLEAR(self->decoder);
999-
self->decoder = incrementalDecoder;
998+
Py_SETREF(self->decoder, incrementalDecoder);
1000999
}
10011000
}
10021001

@@ -1374,8 +1373,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
13741373
static void
13751374
textiowrapper_set_decoded_chars(textio *self, PyObject *chars)
13761375
{
1377-
Py_CLEAR(self->decoded_chars);
1378-
self->decoded_chars = chars;
1376+
Py_SETREF(self->decoded_chars, chars);
13791377
self->decoded_chars_used = 0;
13801378
}
13811379

@@ -1523,8 +1521,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
15231521
dec_buffer = NULL; /* Reference lost to PyBytes_Concat */
15241522
goto fail;
15251523
}
1526-
Py_CLEAR(self->snapshot);
1527-
self->snapshot = Py_BuildValue("NN", dec_flags, next_input);
1524+
Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input));
15281525
}
15291526
Py_DECREF(input_chunk);
15301527

@@ -1630,8 +1627,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
16301627
if (chunks != NULL) {
16311628
if (result != NULL && PyList_Append(chunks, result) < 0)
16321629
goto fail;
1633-
Py_CLEAR(result);
1634-
result = PyUnicode_Join(_PyIO_empty_str, chunks);
1630+
Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks));
16351631
if (result == NULL)
16361632
goto fail;
16371633
Py_CLEAR(chunks);

Modules/_lzmamodule.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,8 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length)
10111011
if (d->eof) {
10121012
d->needs_input = 0;
10131013
if (lzs->avail_in > 0) {
1014-
Py_CLEAR(d->unused_data);
1015-
d->unused_data = PyBytes_FromStringAndSize(
1016-
(char *)lzs->next_in, lzs->avail_in);
1014+
Py_SETREF(d->unused_data,
1015+
PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in));
10171016
if (d->unused_data == NULL)
10181017
goto error;
10191018
}

Modules/_pickle.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
869869
static int
870870
_Pickler_ClearBuffer(PicklerObject *self)
871871
{
872-
Py_CLEAR(self->output_buffer);
873-
self->output_buffer =
874-
PyBytes_FromStringAndSize(NULL, self->max_output_len);
872+
Py_SETREF(self->output_buffer,
873+
PyBytes_FromStringAndSize(NULL, self->max_output_len));
875874
if (self->output_buffer == NULL)
876875
return -1;
877876
self->output_len = 0;
@@ -3116,9 +3115,8 @@ fix_imports(PyObject **module_name, PyObject **global_name)
31163115
Py_TYPE(item)->tp_name);
31173116
return -1;
31183117
}
3119-
Py_CLEAR(*module_name);
31203118
Py_INCREF(item);
3121-
*module_name = item;
3119+
Py_SETREF(*module_name, item);
31223120
}
31233121
else if (PyErr_Occurred()) {
31243122
return -1;

Modules/_struct.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
14371437
return -1;
14381438
}
14391439

1440-
Py_CLEAR(soself->s_format);
1441-
soself->s_format = o_format;
1440+
Py_SETREF(soself->s_format, o_format);
14421441

14431442
ret = prepare_s(soself);
14441443
return ret;

Modules/cjkcodecs/multibytecodec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
793793
ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0);
794794
if (r == NULL) {
795795
/* recover the original pending buffer */
796-
Py_CLEAR(ctx->pending);
797-
ctx->pending = origpending;
796+
Py_SETREF(ctx->pending, origpending);
798797
origpending = NULL;
799798
goto errorexit;
800799
}

Modules/itertoolsmodule.c

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state)
158158
PyObject *currkey, *currvalue, *tgtkey;
159159
if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey))
160160
return NULL;
161-
Py_CLEAR(lz->currkey);
162-
lz->currkey = currkey;
163-
Py_INCREF(lz->currkey);
164-
Py_CLEAR(lz->currvalue);
165-
lz->currvalue = currvalue;
166-
Py_INCREF(lz->currvalue);
167-
Py_CLEAR(lz->tgtkey);
168-
lz->tgtkey = tgtkey;
169-
Py_INCREF(lz->tgtkey);
161+
Py_INCREF(currkey);
162+
Py_SETREF(lz->currkey, currkey);
163+
Py_INCREF(currvalue);
164+
Py_SETREF(lz->currvalue, currvalue);
165+
Py_INCREF(tgtkey);
166+
Py_SETREF(lz->tgtkey, tgtkey);
170167
Py_RETURN_NONE;
171168
}
172169

@@ -745,9 +742,8 @@ tee_setstate(teeobject *to, PyObject *state)
745742
PyErr_SetString(PyExc_ValueError, "Index out of range");
746743
return NULL;
747744
}
748-
Py_CLEAR(to->dataobj);
749-
to->dataobj = tdo;
750-
Py_INCREF(to->dataobj);
745+
Py_INCREF(tdo);
746+
Py_SETREF(to->dataobj, tdo);
751747
to->index = index;
752748
Py_RETURN_NONE;
753749
}
@@ -988,8 +984,7 @@ cycle_setstate(cycleobject *lz, PyObject *state)
988984
if (!PyArg_ParseTuple(state, "O!i", &PyList_Type, &saved, &firstpass))
989985
return NULL;
990986
Py_INCREF(saved);
991-
Py_CLEAR(lz->saved);
992-
lz->saved = saved;
987+
Py_SETREF(lz->saved, saved);
993988
lz->firstpass = firstpass != 0;
994989
lz->index = 0;
995990
Py_RETURN_NONE;
@@ -1920,12 +1915,10 @@ chain_setstate(chainobject *lz, PyObject *state)
19201915
if (! PyArg_ParseTuple(state, "O|O", &source, &active))
19211916
return NULL;
19221917

1923-
Py_CLEAR(lz->source);
1924-
lz->source = source;
1925-
Py_INCREF(lz->source);
1926-
Py_CLEAR(lz->active);
1927-
lz->active = active;
1928-
Py_XINCREF(lz->active);
1918+
Py_INCREF(source);
1919+
Py_SETREF(lz->source, source);
1920+
Py_XINCREF(active);
1921+
Py_SETREF(lz->active, active);
19291922
Py_RETURN_NONE;
19301923
}
19311924

@@ -2282,8 +2275,7 @@ product_setstate(productobject *lz, PyObject *state)
22822275
Py_INCREF(element);
22832276
PyTuple_SET_ITEM(result, i, element);
22842277
}
2285-
Py_CLEAR(lz->result);
2286-
lz->result = result;
2278+
Py_SETREF(lz->result, result);
22872279
Py_RETURN_NONE;
22882280
}
22892281

@@ -2604,8 +2596,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
26042596
PyTuple_SET_ITEM(result, i, element);
26052597
}
26062598

2607-
Py_CLEAR(lz->result);
2608-
lz->result = result;
2599+
Py_SETREF(lz->result, result);
26092600
Py_RETURN_NONE;
26102601
}
26112602

@@ -2935,8 +2926,7 @@ cwr_setstate(cwrobject *lz, PyObject *state)
29352926
Py_INCREF(element);
29362927
PyTuple_SET_ITEM(result, i, element);
29372928
}
2938-
Py_CLEAR(lz->result);
2939-
lz->result = result;
2929+
Py_SETREF(lz->result, result);
29402930
Py_RETURN_NONE;
29412931
}
29422932

@@ -3324,8 +3314,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
33243314
Py_INCREF(element);
33253315
PyTuple_SET_ITEM(result, i, element);
33263316
}
3327-
Py_CLEAR(po->result);
3328-
po->result = result;
3317+
Py_SETREF(po->result, result);
33293318
Py_RETURN_NONE;
33303319
}
33313320

@@ -3495,9 +3484,8 @@ accumulate_reduce(accumulateobject *lz)
34953484
static PyObject *
34963485
accumulate_setstate(accumulateobject *lz, PyObject *state)
34973486
{
3498-
Py_CLEAR(lz->total);
3499-
lz->total = state;
3500-
Py_INCREF(lz->total);
3487+
Py_INCREF(state);
3488+
Py_SETREF(lz->total, state);
35013489
Py_RETURN_NONE;
35023490
}
35033491

@@ -4475,9 +4463,8 @@ zip_longest_reduce(ziplongestobject *lz)
44754463
static PyObject *
44764464
zip_longest_setstate(ziplongestobject *lz, PyObject *state)
44774465
{
4478-
Py_CLEAR(lz->fillvalue);
4479-
lz->fillvalue = state;
4480-
Py_INCREF(lz->fillvalue);
4466+
Py_INCREF(state);
4467+
Py_SETREF(lz->fillvalue, state);
44814468
Py_RETURN_NONE;
44824469
}
44834470

Objects/exceptions.c

Lines changed: 20 additions & 32 deletions

0 commit comments

Comments
 (0)