@@ -971,28 +971,64 @@ _io_StringIO___setstate___impl(stringio *self, PyObject *state)
971
971
static PyObject *
972
972
stringio_closed (stringio * self , void * context )
973
973
{
974
- CHECK_INITIALIZED (self );
975
- return PyBool_FromLong (self -> closed );
974
+ PyObject * result = NULL ;
975
+
976
+ Py_BEGIN_CRITICAL_SECTION (self );
977
+ if (self -> ok <= 0 ) {
978
+ PyErr_SetString (PyExc_ValueError ,
979
+ "I/O operation on uninitialized object" );
980
+ goto cleanup ;
981
+ };
982
+ result = PyBool_FromLong (self -> closed );
983
+
984
+ cleanup :
985
+ Py_END_CRITICAL_SECTION ();
986
+ return result ;
976
987
}
977
988
978
989
static PyObject *
979
990
stringio_line_buffering (stringio * self , void * context )
980
991
{
981
- CHECK_INITIALIZED (self );
982
- CHECK_CLOSED (self );
983
- Py_RETURN_FALSE ;
992
+ PyObject * result = NULL ;
993
+
994
+ Py_BEGIN_CRITICAL_SECTION (self );
995
+ if (self -> ok <= 0 ) {
996
+ PyErr_SetString (PyExc_ValueError ,
997
+ "I/O operation on uninitialized object" );
998
+ goto cleanup ;
999
+ };
1000
+ if (self -> closed ) {
1001
+ PyErr_SetString (PyExc_ValueError , "I/O operation on closed file" );
1002
+ goto cleanup ;
1003
+ };
1004
+ result = Py_NewRef (Py_False );
1005
+
1006
+ cleanup :
1007
+ Py_END_CRITICAL_SECTION ();
1008
+ return result ;
984
1009
}
985
1010
986
1011
static PyObject *
987
1012
stringio_newlines (stringio * self , void * context )
988
1013
{
989
- CHECK_INITIALIZED (self );
990
- CHECK_CLOSED (self );
991
- if (self -> decoder == NULL )
992
- Py_RETURN_NONE ;
993
1014
PyObject * result = NULL ;
1015
+
994
1016
Py_BEGIN_CRITICAL_SECTION (self );
1017
+ if (self -> ok <= 0 ) {
1018
+ PyErr_SetString (PyExc_ValueError ,
1019
+ "I/O operation on uninitialized object" );
1020
+ goto cleanup ;
1021
+ };
1022
+ if (self -> closed ) {
1023
+ PyErr_SetString (PyExc_ValueError , "I/O operation on closed file" );
1024
+ goto cleanup ;
1025
+ };
1026
+ if (self -> decoder == NULL ) {
1027
+ goto cleanup ;
1028
+ }
995
1029
result = PyObject_GetAttr (self -> decoder , & _Py_ID (newlines ));
1030
+
1031
+ cleanup :
996
1032
Py_END_CRITICAL_SECTION ();
997
1033
return result ;
998
1034
}
0 commit comments