diff options
| author | bors <bors@rust-lang.org> | 2016-03-13 09:27:17 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-13 09:27:17 -0700 |
| commit | ce943eb369c9bdd0aef4917675e515f39f3b4a1e (patch) | |
| tree | b66a3a32cd6198ffea1bbf50afeba20092c5ca2e /src/libstd/io | |
| parent | 1c8b245928c3f2463b45fbddd862a0a70882d087 (diff) | |
| parent | bd80a53407e15f13ce50a07642491680010fa090 (diff) | |
Auto merge of #32184 - ollie27:win_stdout, r=alexcrichton
Fixup stout/stderr on Windows WriteConsoleW can fail if called with a large buffer so we need to slice any stdout/stderr output. However the current slicing has a few problems: 1. It slices by byte but still expects valid UTF-8. 2. The slicing happens even when not outputting to a console. 3. panic! output is not sliced. This fixes these issues by moving the slice to right before WriteConsoleW and slicing on a char boundary.
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/stdio.rs | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 25309a785c4..e1a388c38c4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -12,7 +12,6 @@ use prelude::v1::*; use io::prelude::*; use cell::{RefCell, BorrowState}; -use cmp; use fmt; use io::lazy::Lazy; use io::{self, BufReader, LineWriter}; @@ -312,22 +311,6 @@ impl<'a> BufRead for StdinLock<'a> { fn consume(&mut self, n: usize) { self.inner.consume(n) } } -// As with stdin on windows, stdout often can't handle writes of large -// sizes. For an example, see #14940. For this reason, don't try to -// write the entire output buffer on windows. On unix we can just -// write the whole buffer all at once. -// -// For some other references, it appears that this problem has been -// encountered by others [1] [2]. We choose the number 8KB just because -// libuv does the same. -// -// [1]: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/1232 -// [2]: http://www.mail-archive.com/log4net-dev@logging.apache.org/msg00661.html -#[cfg(windows)] -const OUT_MAX: usize = 8192; -#[cfg(unix)] -const OUT_MAX: usize = ::usize::MAX; - /// A handle to the global standard output stream of the current process. /// /// Each handle shares a global buffer of data to be written to the standard @@ -440,7 +423,7 @@ impl Write for Stdout { #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Write for StdoutLock<'a> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - self.inner.borrow_mut().write(&buf[..cmp::min(buf.len(), OUT_MAX)]) + self.inner.borrow_mut().write(buf) } fn flush(&mut self) -> io::Result<()> { self.inner.borrow_mut().flush() @@ -546,7 +529,7 @@ impl Write for Stderr { #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Write for StderrLock<'a> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - self.inner.borrow_mut().write(&buf[..cmp::min(buf.len(), OUT_MAX)]) + self.inner.borrow_mut().write(buf) } fn flush(&mut self) -> io::Result<()> { self.inner.borrow_mut().flush() |
