@@ -753,22 +753,14 @@ buffer_access_safe(textio *self)
753753 return NULL ;
754754 }
755755
756- /* The critical section protects this borrowed reference until the caller
757- can acquire its own reference. */
758756 _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED (self );
759- return self -> buffer ;
760- }
761-
762- static PyObject *
763- buffer_acquire_safe (textio * self )
764- {
765- return Py_XNewRef (buffer_access_safe (self ));
757+ return Py_NewRef (self -> buffer );
766758}
767759
768760static PyObject *
769761buffer_getattr (textio * self , PyObject * attr_name )
770762{
771- PyObject * buffer = buffer_acquire_safe (self );
763+ PyObject * buffer = buffer_access_safe (self );
772764 if (buffer == NULL ) {
773765 return NULL ;
774766 }
@@ -781,7 +773,7 @@ buffer_getattr(textio *self, PyObject *attr_name)
781773static PyObject *
782774buffer_callmethod_noargs (textio * self , PyObject * name )
783775{
784- PyObject * buffer = buffer_acquire_safe (self );
776+ PyObject * buffer = buffer_access_safe (self );
785777 if (buffer == NULL ) {
786778 return NULL ;
787779 }
@@ -794,7 +786,7 @@ buffer_callmethod_noargs(textio *self, PyObject *name)
794786static PyObject *
795787buffer_callmethod_onearg (textio * self , PyObject * name , PyObject * arg )
796788{
797- PyObject * buffer = buffer_acquire_safe (self );
789+ PyObject * buffer = buffer_access_safe (self );
798790 if (buffer == NULL ) {
799791 return NULL ;
800792 }
@@ -1651,8 +1643,8 @@ _io_TextIOWrapper_detach_impl(textio *self)
16511643 if (buffer == NULL ) {
16521644 return NULL ;
16531645 }
1654- self -> buffer = NULL ;
16551646 self -> detached = 1 ;
1647+ Py_CLEAR (self -> buffer );
16561648 return buffer ;
16571649}
16581650
@@ -1874,7 +1866,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
18741866 }
18751867
18761868 if (needflush ) {
1877- PyObject * buffer = buffer_acquire_safe (self );
1869+ PyObject * buffer = buffer_access_safe (self );
18781870 if (buffer == NULL ) {
18791871 return NULL ;
18801872 }
@@ -2694,7 +2686,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
26942686 Py_DECREF (res );
26952687 }
26962688
2697- PyObject * buf = buffer_acquire_safe (self );
2689+ PyObject * buf = buffer_access_safe (self );
26982690 if (buf == NULL ) {
26992691 goto fail ;
27002692 }
@@ -3457,7 +3449,7 @@ static PyObject *
34573449_io_TextIOWrapper_buffer_get_impl (textio * self )
34583450/*[clinic end generated code: output=d265a34555aa5d4b input=5951cfa148f7350a]*/
34593451{
3460- return buffer_acquire_safe (self );
3452+ return buffer_access_safe (self );
34613453}
34623454
34633455static PyMethodDef incrementalnewlinedecoder_methods [] = {
0 commit comments