Skip to content

Commit

Permalink
std: Move a plattform-specific constant to sys::stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Nov 1, 2016
1 parent 8b2600d commit 6d54cd4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/common/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions src/libstd/sys/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion src/tools/tidy/src/pal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

3 comments on commit 6d54cd4

@benaryorg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to dig up this rather old commit, but did this actually drop the distinction of Windows 8k buffers and Unix 64k buffers and made everything 8k?

@sourcejedi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benaryorg commit 8128817 goes from 64k to 8k, that might be what you're thinking of. I'm not sure where the idea of a different value on Windows comes from, unless that was the behaviour even earlier when libuv was used.

@benaryorg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distinction came from Windows not handling the 64k buffers well, hence they choose to set it so something less on Windows.
But seeing it being set to 8k on both of 'em, this doesn't matter now anyway.
Thanks for your effort though.

Please sign in to comment.