@@ -60,8 +60,12 @@ PyDoc_STRVAR(module_doc,
6060"DEFAULT_BUFFER_SIZE\n" 
6161"\n" 
6262"   An int containing the default buffer size used by the module's buffered\n" 
63- "   I/O classes. open() uses the file's blksize (as obtained by os.stat) if\n" 
64- "   possible.\n" 
63+ "   I/O classes.\n" 
64+ "\n" 
65+ "MAXIMUM_BUFFER_SIZE\n" 
66+ "\n" 
67+ "   An int containing the maximum buffer size used by the module's buffered\n" 
68+ "   I/O classes.\n" 
6569    );
6670
6771
@@ -132,8 +136,9 @@ the size of a fixed-size chunk buffer.  When no buffering argument is
132136given, the default buffering policy works as follows: 
133137
134138* Binary files are buffered in fixed-size chunks; the size of the buffer 
135-  is the maximum of the DEFAULT_BUFFER_SIZE and the device block size. 
136-  On most systems, the buffer will typically be 131072 bytes long. 
139+  is max(min(blocksize, MAXIMUM_BUFFER_SIZE), DEFAULT_BUFFER_SIZE) 
140+  when the device block size is available. 
141+  On most systems, the buffer will typically be 128 kilobytes long. 
137142
138143* "Interactive" text files (files for which isatty() returns True) 
139144  use line buffering.  Other text files use the policy described above 
@@ -199,7 +204,7 @@ static PyObject *
199204_io_open_impl (PyObject  * module , PyObject  * file , const  char  * mode ,
200205              int  buffering , const  char  * encoding , const  char  * errors ,
201206              const  char  * newline , int  closefd , PyObject  * opener )
202- /*[clinic end generated code: output=aefafc4ce2b46dc0 input=105f6f1cb63368c4 ]*/ 
207+ /*[clinic end generated code: output=aefafc4ce2b46dc0 input=e1e2d41c6e922cbe ]*/ 
203208{
204209    size_t  i ;
205210
@@ -367,14 +372,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
367372        if  (blksize_obj  ==  NULL )
368373            goto error ;
369374        buffering  =  PyLong_AsLong (blksize_obj );
370-         if  (buffering  >  8192  *  1024 )
371-         {
372-             buffering  =  8192  *  1024 ;
373-         }
374-         if  (buffering  <  DEFAULT_BUFFER_SIZE )
375-         {
376-             buffering  =  DEFAULT_BUFFER_SIZE ;
377-         }
375+         buffering  =  Py_MAX (Py_MIN (buffering , MAXIMUM_BUFFER_SIZE ), DEFAULT_BUFFER_SIZE );
378376        Py_DECREF (blksize_obj );
379377        if  (buffering  ==  -1  &&  PyErr_Occurred ())
380378            goto error ;
0 commit comments