cpython: 8939a21bdb94 (original) (raw)
Mercurial > cpython
changeset 68772:8939a21bdb94 3.2
Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on Windows if the file is a TTY to workaround a Windows bug. The Windows console returns an error (12: not enough space error) on writing into stdout if stdout mode is binary and the length is greater than 66,000 bytes (or less, depending on heap usage). [#11395]
Victor Stinner victor.stinner@haypocalc.com | |
---|---|
date | Sun, 20 Mar 2011 23:36:35 +0100 |
parents | 0b6f6514461e |
children | 4b3472169493 c60271bb1fb1 |
files | Lib/test/test_os.py Misc/NEWS Modules/_io/fileio.c |
diffstat | 3 files changed, 33 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_os.py 19 Misc/NEWS 6 Modules/_io/fileio.c 9 |
line wrap: on
line diff
--- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -90,6 +90,25 @@ class FileTests(unittest.TestCase): self.assertEqual(fobj.read().splitlines(), [b"bacon", b"eggs", b"spam"])
- def write_windows_console(self, *args):
retcode = subprocess.call(args,[](#l1.8)
# use a new console to not flood the test output[](#l1.9)
creationflags=subprocess.CREATE_NEW_CONSOLE,[](#l1.10)
# use a shell to hide the console window (SW_HIDE)[](#l1.11)
shell=True)[](#l1.12)
self.assertEqual(retcode, 0)[](#l1.13)
- @unittest.skipUnless(sys.platform == 'win32',
'test specific to the Windows console')[](#l1.16)
- def test_write_windows_console(self):
# Issue #11395: the Windows console returns an error (12: not enough[](#l1.18)
# space error) on writing into stdout if stdout mode is binary and the[](#l1.19)
# length is greater than 66,000 bytes (or less, depending on heap[](#l1.20)
# usage).[](#l1.21)
code = "print('x' * 100000)"[](#l1.22)
self.write_windows_console(sys.executable, "-c", code)[](#l1.23)
self.write_windows_console(sys.executable, "-u", "-c", code)[](#l1.24)
+ class TemporaryFileTests(unittest.TestCase): def setUp(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,12 @@ What's New in Python 3.2.1? Core and Builtins ----------------- +- Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on
- Windows if the file is a TTY to workaround a Windows bug. The Windows console
- returns an error (12: not enough space error) on writing into stdout if
- stdout mode is binary and the length is greater than 66,000 bytes (or less,
- depending on heap usage). +
- Issue #11320: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath().
--- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -712,7 +712,14 @@ fileio_write(fileio *self, PyObject *arg errno = 0; len = pbuf.len; #if defined(MS_WIN64) || defined(MS_WINDOWS)
if (len > INT_MAX)[](#l3.7)
if (len > 32767 && isatty(self->fd)) {[](#l3.8)
/* Issue #11395: the Windows console returns an error (12: not[](#l3.9)
enough space error) on writing into stdout if stdout mode is[](#l3.10)
binary and the length is greater than 66,000 bytes (or less,[](#l3.11)
depending on heap usage). */[](#l3.12)
len = 32767;[](#l3.13)
}[](#l3.14)
else if (len > INT_MAX)[](#l3.15) len = INT_MAX;[](#l3.16) n = write(self->fd, pbuf.buf, (int)len);[](#l3.17)