@@ -734,8 +734,8 @@ struct textio
734734/* Helpers to safely operate on self->buffer.
735735
736736 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. */
737+ leading to NULL pointer dereferences (see gh-143008, gh-142594). Protect
738+ against that by using helpers to check self->buffer validity at callsites. */
739739static PyObject *
740740buffer_access_safe (textio * self )
741741{
@@ -752,6 +752,9 @@ buffer_access_safe(textio *self)
752752 }
753753 return NULL ;
754754 }
755+
756+ // Returning a borrowed reference is safe since TextIOWrapper
757+ // methods are protected by critical sections.
755758 return self -> buffer ;
756759}
757760
@@ -1119,6 +1122,7 @@ io_check_errors(PyObject *errors)
11191122
11201123
11211124/*[clinic input]
1125+ @critical_section
11221126_io.TextIOWrapper.__init__
11231127 buffer: object
11241128 encoding: str(accept={str, NoneType}) = None
@@ -1162,7 +1166,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11621166 const char * encoding , PyObject * errors ,
11631167 const char * newline , int line_buffering ,
11641168 int write_through )
1165- /*[clinic end generated code: output=72267c0c01032ed2 input=e6cfaaaf6059d4f5 ]*/
1169+ /*[clinic end generated code: output=72267c0c01032ed2 input=0f077220214c40a4 ]*/
11661170{
11671171 PyObject * raw , * codec_info = NULL ;
11681172 PyObject * res ;
0 commit comments