@@ -1368,11 +1368,9 @@ _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
13681368 return NULL ;
13691369 }
13701370
1371- PyObject * res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
1372- if (res == NULL ) {
1371+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
13731372 return NULL ;
13741373 }
1375- Py_DECREF (res );
13761374 self -> b2cratio = 0 ;
13771375
13781376 if (newline_obj != NULL && set_newline (self , newline ) < 0 ) {
@@ -1508,12 +1506,11 @@ static PyObject *
15081506_io_TextIOWrapper_detach_impl (textio * self )
15091507/*[clinic end generated code: output=7ba3715cd032d5f2 input=e5a71fbda9e1d9f9]*/
15101508{
1511- PyObject * buffer , * res ;
1509+ PyObject * buffer ;
15121510 CHECK_ATTACHED (self );
1513- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
1514- if (res == NULL )
1511+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
15151512 return NULL ;
1516- Py_DECREF ( res );
1513+ }
15171514 buffer = self -> buffer ;
15181515 self -> buffer = NULL ;
15191516 self -> detached = 1 ;
@@ -1713,10 +1710,9 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
17131710 }
17141711
17151712 if (needflush ) {
1716- ret = PyObject_CallMethodNoArgs (self -> buffer , & _Py_ID (flush ));
1717- if (ret == NULL )
1713+ if (_PyFile_Flush (self -> buffer ) < 0 ) {
17181714 return NULL ;
1719- Py_DECREF ( ret );
1715+ }
17201716 }
17211717
17221718 textiowrapper_set_decoded_chars (self , NULL );
@@ -2502,10 +2498,9 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
25022498 goto fail ;
25032499 }
25042500
2505- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
2506- if (res == NULL )
2501+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
25072502 goto fail ;
2508- Py_DECREF ( res );
2503+ }
25092504
25102505 textiowrapper_set_decoded_chars (self , NULL );
25112506 Py_CLEAR (self -> snapshot );
@@ -2550,10 +2545,9 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
25502545 goto fail ;
25512546 }
25522547
2553- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
2554- if (res == NULL )
2548+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
25552549 goto fail ;
2556- Py_DECREF ( res );
2550+ }
25572551
25582552 /* The strategy of seek() is to go back to the safe start point
25592553 * and replay the effect of read(chars_to_skip) from there.
@@ -2677,10 +2671,9 @@ _io_TextIOWrapper_tell_impl(textio *self)
26772671
26782672 if (_textiowrapper_writeflush (self ) < 0 )
26792673 return NULL ;
2680- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
2681- if (res == NULL )
2674+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
26822675 goto fail ;
2683- Py_DECREF ( res );
2676+ }
26842677
26852678 posobj = PyObject_CallMethodNoArgs (self -> buffer , & _Py_ID (tell ));
26862679 if (posobj == NULL )
@@ -2885,14 +2878,11 @@ static PyObject *
28852878_io_TextIOWrapper_truncate_impl (textio * self , PyObject * pos )
28862879/*[clinic end generated code: output=90ec2afb9bb7745f input=56ec8baa65aea377]*/
28872880{
2888- PyObject * res ;
2889-
28902881 CHECK_ATTACHED (self )
28912882
2892- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
2893- if (res == NULL )
2883+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
28942884 return NULL ;
2895- Py_DECREF ( res );
2885+ }
28962886
28972887 return PyObject_CallMethodOneArg (self -> buffer , & _Py_ID (truncate ), pos );
28982888}
@@ -3076,13 +3066,9 @@ _io_TextIOWrapper_close_impl(textio *self)
30763066 PyErr_Clear ();
30773067 }
30783068 }
3079- res = PyObject_CallMethodNoArgs ((PyObject * )self , & _Py_ID (flush ));
3080- if (res == NULL ) {
3069+ if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
30813070 exc = PyErr_GetRaisedException ();
30823071 }
3083- else {
3084- Py_DECREF (res );
3085- }
30863072
30873073 res = PyObject_CallMethodNoArgs (self -> buffer , & _Py_ID (close ));
30883074 if (exc != NULL ) {
0 commit comments