@@ -733,49 +733,56 @@ struct textio
733733
734734/* Helpers to safely operate on self->buffer.
735735
736- self->buffer can be detached (set to NULL) by any user code that is called
737- leading to NULL pointer dereferences (see gh-143008, gh-142594). Protect against
738- that by using helpers to check self->buffer validity at callsites. */
736+ self->buffer can be detached (set to NULL) by any user code that is called
737+ leading to NULL pointer dereferences (see gh-143008, gh-142594). Protect against
738+ that by using helpers to check self->buffer validity at callsites. */
739739static PyObject *
740- _textiowrapper_buffer_safe (textio * self ) {
740+ _textiowrapper_buffer_safe (textio * self )
741+ {
741742 /* Check self->buffer directly but match errors of CHECK_ATTACHED since this
742743 is called during construction and destruction where self->ok which
743744 CHECK_ATTACHED uses does not imply self->buffer state. */
744745 if (self -> buffer == NULL ) {
745746 if (self -> ok <= 0 ) {
746747 PyErr_SetString (PyExc_ValueError ,
747- "I/O operation on uninitialized object" );
748+ "I/O operation on uninitialized object" );
748749 }
749750 else {
750751 PyErr_SetString (PyExc_ValueError ,
751- "underlying buffer has been detached" );
752+ "underlying buffer has been detached" );
752753 }
753754 return NULL ;
754755 }
755756 return self -> buffer ;
756757}
757758
758759static PyObject *
759- _textiowrapper_buffer_get_attr (textio * self , PyObject * attr_name ) {
760+ _textiowrapper_buffer_get_attr (textio * self , PyObject * attr_name )
761+ {
760762 PyObject * buffer = _textiowrapper_buffer_safe (self );
763+
761764 if (buffer == NULL ) {
762765 return NULL ;
763766 }
764767 return PyObject_GetAttr (buffer , attr_name );
765768}
766769
767770static PyObject *
768- _textiowrapper_buffer_callmethod_noargs (textio * self , PyObject * name ) {
771+ _textiowrapper_buffer_callmethod_noargs (textio * self , PyObject * name )
772+ {
769773 PyObject * buffer = _textiowrapper_buffer_safe (self );
774+
770775 if (buffer == NULL ) {
771776 return NULL ;
772777 }
773778 return PyObject_CallMethodNoArgs (buffer , name );
774779}
775780
776781static PyObject *
777- _textiowrapper_buffer_callmethod_onearg (textio * self , PyObject * name , PyObject * arg ) {
782+ _textiowrapper_buffer_callmethod_onearg (textio * self , PyObject * name , PyObject * arg )
783+ {
778784 PyObject * buffer = _textiowrapper_buffer_safe (self );
785+
779786 if (buffer == NULL ) {
780787 return NULL ;
781788 }
@@ -1053,14 +1060,14 @@ _textiowrapper_fix_encoder_state(textio *self)
10531060
10541061 self -> encoding_start_of_stream = 1 ;
10551062
1056- PyObject * cookieObj = _textiowrapper_buffer_callmethod_noargs (
1057- self , & _Py_ID (tell ));
1058- if (cookieObj == NULL ) {
1063+ PyObject * cookie = _textiowrapper_buffer_callmethod_noargs (self ,
1064+ & _Py_ID (tell ));
1065+ if (cookie == NULL ) {
10591066 return -1 ;
10601067 }
10611068
1062- int cmp = PyObject_RichCompareBool (cookieObj , _PyLong_GetZero (), Py_EQ );
1063- Py_DECREF (cookieObj );
1069+ int cmp = PyObject_RichCompareBool (cookie , _PyLong_GetZero (), Py_EQ );
1070+ Py_DECREF (cookie );
10641071 if (cmp < 0 ) {
10651072 return -1 ;
10661073 }
@@ -1972,7 +1979,10 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
19721979 goto fail ;
19731980
19741981 input_chunk = _textiowrapper_buffer_callmethod_onearg (self ,
1975- (self -> has_read1 ? & _Py_ID (read1 ): & _Py_ID (read )),
1982+ (self -> has_read1 ?
1983+ & _Py_ID (read1 ):
1984+ & _Py_ID (read )
1985+ ),
19761986 chunk_size );
19771987 Py_DECREF (chunk_size );
19781988 if (input_chunk == NULL )
@@ -2058,7 +2068,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
20582068 if (n < 0 ) {
20592069 /* Read everything */
20602070 PyObject * bytes = _textiowrapper_buffer_callmethod_noargs (self ,
2061- & _Py_ID (read ));
2071+ & _Py_ID (read ));
20622072 PyObject * decoded ;
20632073 if (bytes == NULL )
20642074 goto fail ;
@@ -3040,7 +3050,9 @@ _io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos)
30403050 return NULL ;
30413051 }
30423052
3043- return _textiowrapper_buffer_callmethod_onearg (self , & _Py_ID (truncate ), pos );
3053+ return _textiowrapper_buffer_callmethod_onearg (self ,
3054+ & _Py_ID (truncate ),
3055+ pos );
30443056}
30453057
30463058static PyObject *
@@ -3221,7 +3233,8 @@ _io_TextIOWrapper_close_impl(textio *self)
32213233 PyObject * exc = NULL ;
32223234 if (self -> finalizing ) {
32233235 res = _textiowrapper_buffer_callmethod_onearg (self ,
3224- & _Py_ID (_dealloc_warn ), (PyObject * )self );
3236+ & _Py_ID (_dealloc_warn ),
3237+ (PyObject * )self );
32253238 if (res ) {
32263239 Py_DECREF (res );
32273240 }
0 commit comments