@@ -231,16 +231,14 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
231
231
PyObject * errors )
232
232
/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
233
233
{
234
- self -> decoder = decoder ;
235
- Py_INCREF (decoder );
234
+ self -> decoder = Py_NewRef (decoder );
236
235
237
236
if (errors == NULL ) {
238
- self -> errors = & _Py_ID (strict );
237
+ self -> errors = Py_NewRef ( & _Py_ID (strict ) );
239
238
}
240
239
else {
241
- self -> errors = errors ;
240
+ self -> errors = Py_NewRef ( errors ) ;
242
241
}
243
- Py_INCREF (self -> errors );
244
242
245
243
self -> translate = translate ? 1 : 0 ;
246
244
self -> seennl = 0 ;
@@ -301,8 +299,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
301
299
& _Py_ID (decode ), input , final ? Py_True : Py_False , NULL );
302
300
}
303
301
else {
304
- output = input ;
305
- Py_INCREF (output );
302
+ output = Py_NewRef (input );
306
303
}
307
304
308
305
if (check_decoded (output ) < 0 )
@@ -1148,17 +1145,15 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
1148
1145
* of the partially constructed object (like self->encoding)
1149
1146
*/
1150
1147
1151
- Py_INCREF (errors );
1152
- self -> errors = errors ;
1148
+ self -> errors = Py_NewRef (errors );
1153
1149
self -> chunk_size = 8192 ;
1154
1150
self -> line_buffering = line_buffering ;
1155
1151
self -> write_through = write_through ;
1156
1152
if (set_newline (self , newline ) < 0 ) {
1157
1153
goto error ;
1158
1154
}
1159
1155
1160
- self -> buffer = buffer ;
1161
- Py_INCREF (buffer );
1156
+ self -> buffer = Py_NewRef (buffer );
1162
1157
1163
1158
/* Build the decoder object */
1164
1159
if (_textiowrapper_set_decoder (self , codec_info , PyUnicode_AsUTF8 (errors )) != 0 )
@@ -1284,9 +1279,8 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
1284
1279
}
1285
1280
Py_DECREF (codec_info );
1286
1281
1287
- Py_INCREF (errors );
1288
1282
Py_SETREF (self -> encoding , encoding );
1289
- Py_SETREF (self -> errors , errors );
1283
+ Py_SETREF (self -> errors , Py_NewRef ( errors ) );
1290
1284
1291
1285
return _textiowrapper_fix_encoder_state (self );
1292
1286
}
@@ -1502,8 +1496,7 @@ _textiowrapper_writeflush(textio *self)
1502
1496
PyObject * b ;
1503
1497
1504
1498
if (PyBytes_Check (pending )) {
1505
- b = pending ;
1506
- Py_INCREF (b );
1499
+ b = Py_NewRef (pending );
1507
1500
}
1508
1501
else if (PyUnicode_Check (pending )) {
1509
1502
assert (PyUnicode_IS_ASCII (pending ));
@@ -1618,8 +1611,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
1618
1611
// See bpo-43260
1619
1612
PyUnicode_GET_LENGTH (text ) <= self -> chunk_size &&
1620
1613
is_asciicompat_encoding (self -> encodefunc )) {
1621
- b = text ;
1622
- Py_INCREF (b );
1614
+ b = Py_NewRef (text );
1623
1615
}
1624
1616
else {
1625
1617
b = (* self -> encodefunc )((PyObject * ) self , text );
@@ -1741,8 +1733,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
1741
1733
return NULL ;
1742
1734
}
1743
1735
else {
1744
- chars = self -> decoded_chars ;
1745
- Py_INCREF (chars );
1736
+ chars = Py_NewRef (self -> decoded_chars );
1746
1737
}
1747
1738
1748
1739
self -> decoded_chars_used += n ;
@@ -2139,10 +2130,9 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
2139
2130
}
2140
2131
2141
2132
if (remaining == NULL ) {
2142
- line = self -> decoded_chars ;
2133
+ line = Py_NewRef ( self -> decoded_chars ) ;
2143
2134
start = self -> decoded_chars_used ;
2144
2135
offset_to_buffer = 0 ;
2145
- Py_INCREF (line );
2146
2136
}
2147
2137
else {
2148
2138
assert (self -> decoded_chars_used == 0 );
@@ -3115,8 +3105,7 @@ static PyObject *
3115
3105
textiowrapper_errors_get (textio * self , void * context )
3116
3106
{
3117
3107
CHECK_INITIALIZED (self );
3118
- Py_INCREF (self -> errors );
3119
- return self -> errors ;
3108
+ return Py_NewRef (self -> errors );
3120
3109
}
3121
3110
3122
3111
static PyObject *
0 commit comments