diff options
| author | Brian Anderson <banderson@mozilla.com> | 2016-09-30 21:01:53 +0000 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2016-11-01 17:08:24 +0000 |
| commit | 6d54cd4b2cd864fbd6f2f8d036903f88b6ea79b4 (patch) | |
| tree | 72941b7a0515fc878ffc9f63d48e25c6dcb80089 | |
| parent | 8b2600dbf9a02a19acc92db5d980986cad2ea38d (diff) | |
| download | rust-6d54cd4b2cd864fbd6f2f8d036903f88b6ea79b4.tar.gz rust-6d54cd4b2cd864fbd6f2f8d036903f88b6ea79b4.zip | |
std: Move a plattform-specific constant to sys::stdio
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/common/io.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stdio.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stdio.rs | 5 | ||||
| -rw-r--r-- | src/tools/tidy/src/pal.rs | 1 |
6 files changed, 10 insertions, 11 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 37c3f70d54d..193f396c0d4 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -289,7 +289,7 @@ mod lazy; mod util; mod stdio; -const DEFAULT_BUF_SIZE: usize = 8 * 1024; +const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; // A few methods below (read_to_string, read_line) will append data into a // `String` buffer, but we need to be pretty careful when doing this. The diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index c24ee8ff303..1777b79ea1b 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -214,15 +214,7 @@ pub fn stdin() -> Stdin { _ => Maybe::Fake }; - // The default buffer capacity is 64k, but apparently windows - // doesn't like 64k reads on stdin. See #13304 for details, but the - // idea is that on windows we use a slightly smaller buffer that's - // been seen to be acceptable. - Arc::new(Mutex::new(if cfg!(windows) { - BufReader::with_capacity(8 * 1024, stdin) - } else { - BufReader::new(stdin) - })) + Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin))) } } diff --git a/src/libstd/sys/common/io.rs b/src/libstd/sys/common/io.rs index 0483725dd83..23daeeb5187 100644 --- a/src/libstd/sys/common/io.rs +++ b/src/libstd/sys/common/io.rs @@ -12,6 +12,8 @@ use io::ErrorKind; use io::Read; use slice::from_raw_parts_mut; +pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; + // Provides read_to_end functionality over an uninitialized buffer. // This function is unsafe because it calls the underlying // read function with a slice into uninitialized memory. The default diff --git a/src/libstd/sys/unix/stdio.rs b/src/libstd/sys/unix/stdio.rs index 947ba2cc752..273341b1918 100644 --- a/src/libstd/sys/unix/stdio.rs +++ b/src/libstd/sys/unix/stdio.rs @@ -67,3 +67,4 @@ impl io::Write for Stderr { } pub const EBADF_ERR: i32 = ::libc::EBADF as i32; +pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE; diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 5f097d2631d..72788776ded 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -207,3 +207,8 @@ fn invalid_encoding() -> io::Error { } pub const EBADF_ERR: i32 = ::sys::c::ERROR_INVALID_HANDLE as i32; +// The default buffer capacity is 64k, but apparently windows +// doesn't like 64k reads on stdin. See #13304 for details, but the +// idea is that on windows we use a slightly smaller buffer that's +// been seen to be acceptable. +pub const STDIN_BUF_SIZE: usize = 8 * 1024; diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 80a2d22691b..6ce5f7ee7fe 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -66,7 +66,6 @@ const EXCEPTION_PATHS: &'static [&'static str] = &[ "src/libstd/lib.rs", // This could probably be done within the sys directory "src/libstd/rtdeps.rs", // Until rustbuild replaces make "src/libstd/path.rs", - "src/libstd/io/stdio.rs", "src/libstd/num/f32.rs", "src/libstd/num/f64.rs", "src/libstd/sys/common/mod.rs", |
