Skip to content

Commit 8688aca

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.
1 parent 82ea0f9 commit 8688aca

4 files changed

Lines changed: 33 additions & 57 deletions

File tree

Modules/_io/bufferedio.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ _buffered_readline(buffered *self, Py_ssize_t limit)
10281028
Py_CLEAR(res);
10291029
goto end;
10301030
}
1031-
Py_CLEAR(res);
1032-
res = _PyBytes_Join(_PyIO_empty_bytes, chunks);
1031+
Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks));
10331032

10341033
end:
10351034
LEAVE_BUFFERED(self)
@@ -1264,9 +1263,8 @@ bufferedreader_init(buffered *self, PyObject *args, PyObject *kwds)
12641263
if (_PyIOBase_check_readable(raw, Py_True) == NULL)
12651264
return -1;
12661265

1267-
Py_CLEAR(self->raw);
12681266
Py_INCREF(raw);
1269-
self->raw = raw;
1267+
Py_SETREF(self->raw, raw);
12701268
self->buffer_size = buffer_size;
12711269
self->readable = 1;
12721270
self->writable = 0;
@@ -1687,9 +1685,8 @@ bufferedwriter_init(buffered *self, PyObject *args, PyObject *kwds)
16871685
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
16881686
return -1;
16891687

1690-
Py_CLEAR(self->raw);
16911688
Py_INCREF(raw);
1692-
self->raw = raw;
1689+
Py_SETREF(self->raw, raw);
16931690
self->readable = 0;
16941691
self->writable = 1;
16951692

@@ -2344,9 +2341,8 @@ bufferedrandom_init(buffered *self, PyObject *args, PyObject *kwds)
23442341
if (_PyIOBase_check_writable(raw, Py_True) == NULL)
23452342
return -1;
23462343

2347-
Py_CLEAR(self->raw);
23482344
Py_INCREF(raw);
2349-
self->raw = raw;
2345+
Py_SETREF(self->raw, raw);
23502346
self->buffer_size = buffer_size;
23512347
self->readable = 1;
23522348
self->writable = 1;

Modules/_io/textio.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,7 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
966966
"Oi", self->decoder, (int)self->readtranslate);
967967
if (incrementalDecoder == NULL)
968968
goto error;
969-
Py_CLEAR(self->decoder);
970-
self->decoder = incrementalDecoder;
969+
Py_SETREF(self->decoder, incrementalDecoder);
971970
}
972971
}
973972

@@ -1347,8 +1346,7 @@ textiowrapper_write(textio *self, PyObject *args)
13471346
static void
13481347
textiowrapper_set_decoded_chars(textio *self, PyObject *chars)
13491348
{
1350-
Py_CLEAR(self->decoded_chars);
1351-
self->decoded_chars = chars;
1349+
Py_SETREF(self->decoded_chars, chars);
13521350
self->decoded_chars_used = 0;
13531351
}
13541352

@@ -1477,8 +1475,7 @@ textiowrapper_read_chunk(textio *self)
14771475
goto fail;
14781476
}
14791477
Py_DECREF(dec_buffer);
1480-
Py_CLEAR(self->snapshot);
1481-
self->snapshot = Py_BuildValue("NN", dec_flags, next_input);
1478+
Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input));
14821479
}
14831480
Py_DECREF(input_chunk);
14841481

@@ -1578,8 +1575,7 @@ textiowrapper_read(textio *self, PyObject *args)
15781575
if (chunks != NULL) {
15791576
if (result != NULL && PyList_Append(chunks, result) < 0)
15801577
goto fail;
1581-
Py_CLEAR(result);
1582-
result = PyUnicode_Join(_PyIO_empty_str, chunks);
1578+
Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks));
15831579
if (result == NULL)
15841580
goto fail;
15851581
Py_CLEAR(chunks);
@@ -1836,8 +1832,7 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
18361832
if (chunks != NULL) {
18371833
if (line != NULL && PyList_Append(chunks, line) < 0)
18381834
goto error;
1839-
Py_CLEAR(line);
1840-
line = PyUnicode_Join(_PyIO_empty_str, chunks);
1835+
Py_SETREF(line, PyUnicode_Join(_PyIO_empty_str, chunks));
18411836
if (line == NULL)
18421837
goto error;
18431838
Py_DECREF(chunks);

Modules/_struct.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,15 +1377,13 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds)
13771377

13781378
if (PyString_Check(o_format)) {
13791379
Py_INCREF(o_format);
1380-
Py_CLEAR(soself->s_format);
1381-
soself->s_format = o_format;
1380+
Py_SETREF(soself->s_format, o_format);
13821381
}
13831382
else if (PyUnicode_Check(o_format)) {
13841383
PyObject *str = PyUnicode_AsEncodedString(o_format, "ascii", NULL);
13851384
if (str == NULL)
13861385
return -1;
1387-
Py_CLEAR(soself->s_format);
1388-
soself->s_format = str;
1386+
Py_SETREF(soself->s_format, str);
13891387
}
13901388
else {
13911389
PyErr_Format(PyExc_TypeError,

Objects/exceptions.c

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
6262
Py_SETREF(self->args, args);
6363

6464
if (PyTuple_GET_SIZE(self->args) == 1) {
65-
Py_CLEAR(self->message);
66-
self->message = PyTuple_GET_ITEM(self->args, 0);
67-
Py_INCREF(self->message);
65+
Py_INCREF(PyTuple_GET_ITEM(self->args, 0));
66+
Py_SETREF(self->message, PyTuple_GET_ITEM(self->args, 0));
6867
}
6968
return 0;
7069
}
@@ -279,9 +278,8 @@ BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val)
279278
PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary");
280279
return -1;
281280
}
282-
Py_CLEAR(self->dict);
283281
Py_INCREF(val);
284-
self->dict = val;
282+
Py_SETREF(self->dict, val);
285283
return 0;
286284
}
287285

@@ -307,8 +305,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
307305
seq = PySequence_Tuple(val);
308306
if (!seq)
309307
return -1;
310-
Py_CLEAR(self->args);
311-
self->args = seq;
308+
Py_SETREF(self->args, seq);
312309
return 0;
313310
}
314311

@@ -608,19 +605,16 @@ EnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args,
608605
&myerrno, &strerror, &filename)) {
609606
return -1;
610607
}
611-
Py_CLEAR(self->myerrno); /* replacing */
612-
self->myerrno = myerrno;
613-
Py_INCREF(self->myerrno);
608+
Py_INCREF(myerrno);
609+
Py_SETREF(self->myerrno, myerrno);
614610

615-
Py_CLEAR(self->strerror); /* replacing */
616-
self->strerror = strerror;
617-
Py_INCREF(self->strerror);
611+
Py_INCREF(strerror);
612+
Py_SETREF(self->strerror, strerror);
618613

619614
/* self->filename will remain Py_None otherwise */
620615
if (filename != NULL) {
621-
Py_CLEAR(self->filename); /* replacing */
622-
self->filename = filename;
623-
Py_INCREF(self->filename);
616+
Py_INCREF(filename);
617+
Py_SETREF(self->filename, filename);
624618

625619
subslice = PyTuple_GetSlice(args, 0, 2);
626620
if (!subslice)
@@ -877,8 +871,7 @@ WindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds)
877871
return -1;
878872
posix_errno = winerror_to_errno(errcode);
879873

880-
Py_CLEAR(self->winerror);
881-
self->winerror = self->myerrno;
874+
Py_SETREF(self->winerror, self->myerrno);
882875

883876
o_errcode = PyInt_FromLong(posix_errno);
884877
if (!o_errcode)
@@ -1063,9 +1056,8 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
10631056
return -1;
10641057

10651058
if (lenargs >= 1) {
1066-
Py_CLEAR(self->msg);
1067-
self->msg = PyTuple_GET_ITEM(args, 0);
1068-
Py_INCREF(self->msg);
1059+
Py_INCREF(PyTuple_GET_ITEM(args, 0));
1060+
Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0));
10691061
}
10701062
if (lenargs == 2) {
10711063
info = PyTuple_GET_ITEM(args, 1);
@@ -1080,21 +1072,17 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
10801072
return -1;
10811073
}
10821074

1083-
Py_CLEAR(self->filename);
1084-
self->filename = PyTuple_GET_ITEM(info, 0);
1085-
Py_INCREF(self->filename);
1075+
Py_INCREF(PyTuple_GET_ITEM(info, 0));
1076+
Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0));
10861077

1087-
Py_CLEAR(self->lineno);
1088-
self->lineno = PyTuple_GET_ITEM(info, 1);
1089-
Py_INCREF(self->lineno);
1078+
Py_INCREF(PyTuple_GET_ITEM(info, 1));
1079+
Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1));
10901080

1091-
Py_CLEAR(self->offset);
1092-
self->offset = PyTuple_GET_ITEM(info, 2);
1093-
Py_INCREF(self->offset);
1081+
Py_INCREF(PyTuple_GET_ITEM(info, 2));
1082+
Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2));
10941083

1095-
Py_CLEAR(self->text);
1096-
self->text = PyTuple_GET_ITEM(info, 3);
1097-
Py_INCREF(self->text);
1084+
Py_INCREF(PyTuple_GET_ITEM(info, 3));
1085+
Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3));
10981086

10991087
Py_DECREF(info);
11001088
}
@@ -1327,8 +1315,7 @@ set_string(PyObject **attr, const char *value)
13271315
PyObject *obj = PyString_FromString(value);
13281316
if (!obj)
13291317
return -1;
1330-
Py_CLEAR(*attr);
1331-
*attr = obj;
1318+
Py_SETREF(*attr, obj);
13321319
return 0;
13331320
}
13341321

0 commit comments

Comments
 (0)