Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When the io is flushed in unbuffered mode in Windows, all bytes are now
properly written to the console.
15 changes: 5 additions & 10 deletions Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,16 +978,6 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)

Py_BEGIN_ALLOW_THREADS
wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, NULL, 0);

/* issue11395 there is an unspecified upper bound on how many bytes
can be written at once. We cap at 32k - the caller will have to
handle partial writes.
Since we don't know how many input bytes are being ignored, we
have to reduce and recalculate. */
while (wlen > 32766 / sizeof(wchar_t)) {
len /= 2;
wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, NULL, 0);
}
Py_END_ALLOW_THREADS

if (!wlen)
Expand All @@ -998,6 +988,11 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
Py_BEGIN_ALLOW_THREADS
wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, wbuf, wlen);
if (wlen) {
/* Note that it's possible that this would fail to print big strings
* on Windows 7 (before Windows 8 LPC-based pseudo-files were used
* for I/O and would be limited to a 64 KiB heap).
* As Windows 7 is no longer supported, that's OK.
*/
res = WriteConsoleW(handle, wbuf, wlen, &n, NULL);
if (res && n < wlen) {
/* Wrote fewer characters than expected, which means our
Expand Down
9 changes: 0 additions & 9 deletions Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,15 +1774,6 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
int async_err = 0;

_Py_BEGIN_SUPPRESS_IPH
#ifdef MS_WINDOWS
if (count > 32767 && isatty(fd)) {
/* Issue #11395: 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). */
count = 32767;
}
#endif
if (count > _PY_WRITE_MAX) {
count = _PY_WRITE_MAX;
}
Expand Down