@@ -231,16 +231,14 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
231231 PyObject * errors )
232232/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
233233{
234- self -> decoder = decoder ;
235- Py_INCREF (decoder );
234+ self -> decoder = Py_NewRef (decoder );
236235
237236 if (errors == NULL ) {
238- self -> errors = & _Py_ID (strict );
237+ self -> errors = Py_NewRef ( & _Py_ID (strict ) );
239238 }
240239 else {
241- self -> errors = errors ;
240+ self -> errors = Py_NewRef ( errors ) ;
242241 }
243- Py_INCREF (self -> errors );
244242
245243 self -> translate = translate ? 1 : 0 ;
246244 self -> seennl = 0 ;
@@ -301,8 +299,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
301299 & _Py_ID (decode ), input , final ? Py_True : Py_False , NULL );
302300 }
303301 else {
304- output = input ;
305- Py_INCREF (output );
302+ output = Py_NewRef (input );
306303 }
307304
308305 if (check_decoded (output ) < 0 )
@@ -1148,17 +1145,15 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11481145 * of the partially constructed object (like self->encoding)
11491146 */
11501147
1151- Py_INCREF (errors );
1152- self -> errors = errors ;
1148+ self -> errors = Py_NewRef (errors );
11531149 self -> chunk_size = 8192 ;
11541150 self -> line_buffering = line_buffering ;
11551151 self -> write_through = write_through ;
11561152 if (set_newline (self , newline ) < 0 ) {
11571153 goto error ;
11581154 }
11591155
1160- self -> buffer = buffer ;
1161- Py_INCREF (buffer );
1156+ self -> buffer = Py_NewRef (buffer );
11621157
11631158 /* Build the decoder object */
11641159 if (_textiowrapper_set_decoder (self , codec_info , PyUnicode_AsUTF8 (errors )) != 0 )
@@ -1284,9 +1279,8 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
12841279 }
12851280 Py_DECREF (codec_info );
12861281
1287- Py_INCREF (errors );
12881282 Py_SETREF (self -> encoding , encoding );
1289- Py_SETREF (self -> errors , errors );
1283+ Py_SETREF (self -> errors , Py_NewRef ( errors ) );
12901284
12911285 return _textiowrapper_fix_encoder_state (self );
12921286}
@@ -1502,8 +1496,7 @@ _textiowrapper_writeflush(textio *self)
15021496 PyObject * b ;
15031497
15041498 if (PyBytes_Check (pending )) {
1505- b = pending ;
1506- Py_INCREF (b );
1499+ b = Py_NewRef (pending );
15071500 }
15081501 else if (PyUnicode_Check (pending )) {
15091502 assert (PyUnicode_IS_ASCII (pending ));
@@ -1618,8 +1611,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
16181611 // See bpo-43260
16191612 PyUnicode_GET_LENGTH (text ) <= self -> chunk_size &&
16201613 is_asciicompat_encoding (self -> encodefunc )) {
1621- b = text ;
1622- Py_INCREF (b );
1614+ b = Py_NewRef (text );
16231615 }
16241616 else {
16251617 b = (* self -> encodefunc )((PyObject * ) self , text );
@@ -1741,8 +1733,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
17411733 return NULL ;
17421734 }
17431735 else {
1744- chars = self -> decoded_chars ;
1745- Py_INCREF (chars );
1736+ chars = Py_NewRef (self -> decoded_chars );
17461737 }
17471738
17481739 self -> decoded_chars_used += n ;
@@ -2139,10 +2130,9 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
21392130 }
21402131
21412132 if (remaining == NULL ) {
2142- line = self -> decoded_chars ;
2133+ line = Py_NewRef ( self -> decoded_chars ) ;
21432134 start = self -> decoded_chars_used ;
21442135 offset_to_buffer = 0 ;
2145- Py_INCREF (line );
21462136 }
21472137 else {
21482138 assert (self -> decoded_chars_used == 0 );
@@ -3115,8 +3105,7 @@ static PyObject *
31153105textiowrapper_errors_get (textio * self , void * context )
31163106{
31173107 CHECK_INITIALIZED (self );
3118- Py_INCREF (self -> errors );
3119- return self -> errors ;
3108+ return Py_NewRef (self -> errors );
31203109}
31213110
31223111static PyObject *
0 commit comments