@@ -386,16 +386,20 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
386
386
return result ;
387
387
}
388
388
389
+ _PyIO_State * state = IO_STATE ();
389
390
/* wraps into a buffered file */
390
391
{
391
392
PyObject * Buffered_class ;
392
393
393
- if (updating )
394
- Buffered_class = (PyObject * )& PyBufferedRandom_Type ;
395
- else if (creating || writing || appending )
396
- Buffered_class = (PyObject * )& PyBufferedWriter_Type ;
397
- else if (reading )
398
- Buffered_class = (PyObject * )& PyBufferedReader_Type ;
394
+ if (updating ) {
395
+ Buffered_class = (PyObject * )state -> PyBufferedRandom_Type ;
396
+ }
397
+ else if (creating || writing || appending ) {
398
+ Buffered_class = (PyObject * )state -> PyBufferedWriter_Type ;
399
+ }
400
+ else if (reading ) {
401
+ Buffered_class = (PyObject * )state -> PyBufferedReader_Type ;
402
+ }
399
403
else {
400
404
PyErr_Format (PyExc_ValueError ,
401
405
"unknown mode: '%s'" , mode );
@@ -417,7 +421,6 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
417
421
}
418
422
419
423
/* wraps into a TextIOWrapper */
420
- _PyIO_State * state = IO_STATE ();
421
424
wrapper = PyObject_CallFunction ((PyObject * )state -> PyTextIOWrapper_Type ,
422
425
"OsssO" ,
423
426
buffer ,
@@ -641,10 +644,6 @@ static PyTypeObject* static_types[] = {
641
644
642
645
// PyBufferedIOBase_Type(PyIOBase_Type) subclasses
643
646
& PyBytesIO_Type ,
644
- & PyBufferedReader_Type ,
645
- & PyBufferedWriter_Type ,
646
- & PyBufferedRWPair_Type ,
647
- & PyBufferedRandom_Type ,
648
647
649
648
// PyRawIOBase_Type(PyIOBase_Type) subclasses
650
649
& _PyBytesIOBuffer_Type ,
@@ -710,10 +709,6 @@ PyInit__io(void)
710
709
#ifdef MS_WINDOWS
711
710
PyWindowsConsoleIO_Type .tp_base = & PyRawIOBase_Type ;
712
711
#endif
713
- PyBufferedReader_Type .tp_base = & PyBufferedIOBase_Type ;
714
- PyBufferedWriter_Type .tp_base = & PyBufferedIOBase_Type ;
715
- PyBufferedRWPair_Type .tp_base = & PyBufferedIOBase_Type ;
716
- PyBufferedRandom_Type .tp_base = & PyBufferedIOBase_Type ;
717
712
718
713
// Add types
719
714
for (size_t i = 0 ; i < Py_ARRAY_LENGTH (static_types ); i ++ ) {
@@ -723,6 +718,16 @@ PyInit__io(void)
723
718
}
724
719
}
725
720
721
+ // PyBufferedIOBase_Type(PyIOBase_Type) subclasses
722
+ ADD_TYPE (m , state -> PyBufferedWriter_Type , & bufferedwriter_spec ,
723
+ & PyBufferedIOBase_Type );
724
+ ADD_TYPE (m , state -> PyBufferedReader_Type , & bufferedreader_spec ,
725
+ & PyBufferedIOBase_Type );
726
+ ADD_TYPE (m , state -> PyBufferedRWPair_Type , & bufferedrwpair_spec ,
727
+ & PyBufferedIOBase_Type );
728
+ ADD_TYPE (m , state -> PyBufferedRandom_Type , & bufferedrandom_spec ,
729
+ & PyBufferedIOBase_Type );
730
+
726
731
// PyRawIOBase_Type(PyIOBase_Type) subclasses
727
732
ADD_TYPE (m , state -> PyFileIO_Type , & fileio_spec , & PyRawIOBase_Type );
728
733
0 commit comments