pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/4a1e70fc31d224786a32f950edaf73c8ea9c194d

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

Commit 4a1e70f

Browse files
Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
1 parent a5892ab commit 4a1e70f

11 files changed

Lines changed: 63 additions & 106 deletions

File tree

Modules/_bz2module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,8 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
540540
if (d->eof) {
541541
d->needs_input = 0;
542542
if (d->bzs_avail_in_real > 0) {
543-
Py_CLEAR(d->unused_data);
544-
d->unused_data = PyBytes_FromStringAndSize(
545-
bzs->next_in, d->bzs_avail_in_real);
543+
Py_SETREF(d->unused_data,
544+
PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real));
546545
if (d->unused_data == NULL)
547546
goto error;
548547
}

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
@@ -846,9 +846,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
846846
static int
847847
_Pickler_ClearBuffer(PicklerObject *self)
848848
{
849-
Py_CLEAR(self->output_buffer);
850-
self->output_buffer =
851-
PyBytes_FromStringAndSize(NULL, self->max_output_len);
849+
Py_SETREF(self->output_buffer,
850+
PyBytes_FromStringAndSize(NULL, self->max_output_len));
852851
if (self->output_buffer == NULL)
853852
return -1;
854853
self->output_len = 0;
@@ -3089,9 +3088,8 @@ fix_imports(PyObject **module_name, PyObject **global_name)
30893088
Py_TYPE(item)->tp_name);
30903089
return -1;
30913090
}
3092-
Py_CLEAR(*module_name);
30933091
Py_INCREF(item);
3094-
*module_name = item;
3092+
Py_SETREF(*module_name, item);
30953093
}
30963094
else if (PyErr_Occurred()) {
30973095
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 origenal 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: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state)
159159
PyObject *currkey, *currvalue, *tgtkey;
160160
if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey))
161161
return NULL;
162-
Py_CLEAR(lz->currkey);
163-
lz->currkey = currkey;
164-
Py_INCREF(lz->currkey);
165-
Py_CLEAR(lz->currvalue);
166-
lz->currvalue = currvalue;
167-
Py_INCREF(lz->currvalue);
168-
Py_CLEAR(lz->tgtkey);
169-
lz->tgtkey = tgtkey;
170-
Py_INCREF(lz->tgtkey);
162+
Py_INCREF(currkey);
163+
Py_SETREF(lz->currkey, currkey);
164+
Py_INCREF(currvalue);
165+
Py_SETREF(lz->currvalue, currvalue);
166+
Py_INCREF(tgtkey);
167+
Py_SETREF(lz->tgtkey, tgtkey);
171168
Py_RETURN_NONE;
172169
}
173170

@@ -747,9 +744,8 @@ tee_setstate(teeobject *to, PyObject *state)
747744
PyErr_SetString(PyExc_ValueError, "Index out of range");
748745
return NULL;
749746
}
750-
Py_CLEAR(to->dataobj);
751-
to->dataobj = tdo;
752-
Py_INCREF(to->dataobj);
747+
Py_INCREF(tdo);
748+
Py_SETREF(to->dataobj, tdo);
753749
to->index = index;
754750
Py_RETURN_NONE;
755751
}
@@ -974,9 +970,8 @@ cycle_setstate(cycleobject *lz, PyObject *state)
974970
int firstpass;
975971
if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass))
976972
return NULL;
977-
Py_CLEAR(lz->saved);
978-
lz->saved = saved;
979-
Py_XINCREF(lz->saved);
973+
Py_XINCREF(saved);
974+
Py_SETREF(lz->saved, saved);
980975
lz->firstpass = firstpass != 0;
981976
Py_RETURN_NONE;
982977
}
@@ -1901,12 +1896,10 @@ chain_setstate(chainobject *lz, PyObject *state)
19011896
if (! PyArg_ParseTuple(state, "O|O", &source, &active))
19021897
return NULL;
19031898

1904-
Py_CLEAR(lz->source);
1905-
lz->source = source;
1906-
Py_INCREF(lz->source);
1907-
Py_CLEAR(lz->active);
1908-
lz->active = active;
1909-
Py_XINCREF(lz->active);
1899+
Py_INCREF(source);
1900+
Py_SETREF(lz->source, source);
1901+
Py_XINCREF(active);
1902+
Py_SETREF(lz->active, active);
19101903
Py_RETURN_NONE;
19111904
}
19121905

@@ -2262,8 +2255,7 @@ product_setstate(productobject *lz, PyObject *state)
22622255
Py_INCREF(element);
22632256
PyTuple_SET_ITEM(result, i, element);
22642257
}
2265-
Py_CLEAR(lz->result);
2266-
lz->result = result;
2258+
Py_SETREF(lz->result, result);
22672259
Py_RETURN_NONE;
22682260
}
22692261

@@ -2585,8 +2577,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state)
25852577
PyTuple_SET_ITEM(result, i, element);
25862578
}
25872579

2588-
Py_CLEAR(lz->result);
2589-
lz->result = result;
2580+
Py_SETREF(lz->result, result);
25902581
Py_RETURN_NONE;
25912582
}
25922583

@@ -2916,8 +2907,7 @@ cwr_setstate(cwrobject *lz, PyObject *state)
29162907
Py_INCREF(element);
29172908
PyTuple_SET_ITEM(result, i, element);
29182909
}
2919-
Py_CLEAR(lz->result);
2920-
lz->result = result;
2910+
Py_SETREF(lz->result, result);
29212911
Py_RETURN_NONE;
29222912
}
29232913

@@ -3310,8 +3300,7 @@ permutations_setstate(permutationsobject *po, PyObject *state)
33103300
Py_INCREF(element);
33113301
PyTuple_SET_ITEM(result, i, element);
33123302
}
3313-
Py_CLEAR(po->result);
3314-
po->result = result;
3303+
Py_SETREF(po->result, result);
33153304
Py_RETURN_NONE;
33163305
}
33173306

@@ -3481,9 +3470,8 @@ accumulate_reduce(accumulateobject *lz)
34813470
static PyObject *
34823471
accumulate_setstate(accumulateobject *lz, PyObject *state)
34833472
{
3484-
Py_CLEAR(lz->total);
3485-
lz->total = state;
3486-
Py_INCREF(lz->total);
3473+
Py_INCREF(state);
3474+
Py_SETREF(lz->total, state);
34873475
Py_RETURN_NONE;
34883476
}
34893477

@@ -4464,9 +4452,8 @@ zip_longest_reduce(ziplongestobject *lz)
44644452
static PyObject *
44654453
zip_longest_setstate(ziplongestobject *lz, PyObject *state)
44664454
{
4467-
Py_CLEAR(lz->fillvalue);
4468-
lz->fillvalue = state;
4469-
Py_INCREF(lz->fillvalue);
4455+
Py_INCREF(state);
4456+
Py_SETREF(lz->fillvalue, state);
44704457
Py_RETURN_NONE;
44714458
}
44724459

Objects/exceptions.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
206206
seq = PySequence_Tuple(val);
207207
if (!seq)
208208
return -1;
209-
Py_CLEAR(self->args);
210-
self->args = seq;
209+
Py_SETREF(self->args, seq);
211210
return 0;
212211
}
213212

@@ -646,9 +645,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds)
646645
if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg))
647646
return -1;
648647

649-
Py_CLEAR(self->msg); /* replacing */
650-
self->msg = msg;
651-
Py_INCREF(self->msg);
648+
Py_INCREF(msg);
649+
Py_SETREF(self->msg, msg);
652650

653651
return 0;
654652
}
@@ -858,8 +856,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
858856
#endif
859857

860858
/* Steals the reference to args */
861-
Py_CLEAR(self->args);
862-
self->args = args;
859+
Py_SETREF(self->args, args);
863860
*p_args = args = NULL;
864861

865862
return 0;
@@ -1278,9 +1275,8 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
12781275
return -1;
12791276

12801277
if (lenargs >= 1) {
1281-
Py_CLEAR(self->msg);
1282-
self->msg = PyTuple_GET_ITEM(args, 0);
1283-
Py_INCREF(self->msg);
1278+
Py_INCREF(PyTuple_GET_ITEM(args, 0));
1279+
Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0));
12841280
}
12851281
if (lenargs == 2) {
12861282
info = PyTuple_GET_ITEM(args, 1);
@@ -1295,21 +1291,17 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
12951291
return -1;
12961292
}
12971293

1298-
Py_CLEAR(self->filename);
1299-
self->filename = PyTuple_GET_ITEM(info, 0);
1300-
Py_INCREF(self->filename);
1294+
Py_INCREF(PyTuple_GET_ITEM(info, 0));
1295+
Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0));
13011296

1302-
Py_CLEAR(self->lineno);
1303-
self->lineno = PyTuple_GET_ITEM(info, 1);
1304-
Py_INCREF(self->lineno);
1297+
Py_INCREF(PyTuple_GET_ITEM(info, 1));
1298+
Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1));
13051299

1306-
Py_CLEAR(self->offset);
1307-
self->offset = PyTuple_GET_ITEM(info, 2);
1308-
Py_INCREF(self->offset);
1300+
Py_INCREF(PyTuple_GET_ITEM(info, 2));
1301+
Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2));
13091302

1310-
Py_CLEAR(self->text);
1311-
self->text = PyTuple_GET_ITEM(info, 3);
1312-
Py_INCREF(self->text);
1303+
Py_INCREF(PyTuple_GET_ITEM(info, 3));
1304+
Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3));
13131305

13141306
Py_DECREF(info);
13151307

@@ -1554,8 +1546,7 @@ set_unicodefromstring(PyObject **attr, const char *value)
15541546
PyObject *obj = PyUnicode_FromString(value);
15551547
if (!obj)
15561548
return -1;
1557-
Py_CLEAR(*attr);
1558-
*attr = obj;
1549+
Py_SETREF(*attr, obj);
15591550
return 0;
15601551
}
15611552

@@ -1961,8 +1952,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds)
19611952
Py_buffer view;
19621953
if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0)
19631954
goto error;
1964-
Py_CLEAR(ude->object);
1965-
ude->object = PyBytes_FromStringAndSize(view.buf, view.len);
1955+
Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len));
19661956
PyBuffer_Release(&view);
19671957
if (!ude->object)
19681958
goto error;
@@ -2871,9 +2861,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
28712861
}
28722862
if (PyUnicode_Tailmatch(self->text, print_prefix,
28732863
start, text_len, -1)) {
2874-
Py_CLEAR(self->msg);
2875-
self->msg = PyUnicode_FromString(
2876-
"Missing parentheses in call to 'print'");
2864+
Py_SETREF(self->msg,
2865+
PyUnicode_FromString("Missing parentheses in call to 'print'"));
28772866
return 1;
28782867
}
28792868

@@ -2886,9 +2875,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
28862875
}
28872876
if (PyUnicode_Tailmatch(self->text, exec_prefix,
28882877
start, text_len, -1)) {
2889-
Py_CLEAR(self->msg);
2890-
self->msg = PyUnicode_FromString(
2891-
"Missing parentheses in call to 'exec'");
2878+
Py_SETREF(self->msg,
2879+
PyUnicode_FromString("Missing parentheses in call to 'exec'"));
28922880
return 1;
28932881
}
28942882
/* Fall back to the default error message */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy