Skip to content

Commit 7433ba6

Browse files
committed
std: get rid of sys_common::io
1 parent a9df224 commit 7433ba6

File tree

17 files changed

+84
-88
lines changed

17 files changed

+84
-88
lines changed

library/std/src/fs/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::os::unix::fs::symlink as junction_point;
1414
use crate::os::windows::fs::{OpenOptionsExt, junction_point, symlink_dir, symlink_file};
1515
use crate::path::Path;
1616
use crate::sync::Arc;
17-
use crate::sys_common::io::test::{TempDir, tmpdir};
17+
use crate::test_helpers::{TempDir, tmpdir};
1818
use crate::time::{Duration, Instant, SystemTime};
1919
use crate::{env, str, thread};
2020

library/std/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub mod prelude;
344344
mod stdio;
345345
mod util;
346346

347-
const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
347+
const DEFAULT_BUF_SIZE: usize = crate::sys::io::DEFAULT_BUF_SIZE;
348348

349349
pub(crate) use stdio::cleanup;
350350

library/std/src/lib.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -739,27 +739,4 @@ mod sealed {
739739

740740
#[cfg(test)]
741741
#[allow(dead_code)] // Not used in all configurations.
742-
pub(crate) mod test_helpers {
743-
/// Test-only replacement for `rand::thread_rng()`, which is unusable for
744-
/// us, as we want to allow running stdlib tests on tier-3 targets which may
745-
/// not have `getrandom` support.
746-
///
747-
/// Does a bit of a song and dance to ensure that the seed is different on
748-
/// each call (as some tests sadly rely on this), but doesn't try that hard.
749-
///
750-
/// This is duplicated in the `core`, `alloc` test suites (as well as
751-
/// `std`'s integration tests), but figuring out a mechanism to share these
752-
/// seems far more painful than copy-pasting a 7 line function a couple
753-
/// times, given that even under a perma-unstable feature, I don't think we
754-
/// want to expose types from `rand` from `std`.
755-
#[track_caller]
756-
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
757-
use core::hash::{BuildHasher, Hash, Hasher};
758-
let mut hasher = crate::hash::RandomState::new().build_hasher();
759-
core::panic::Location::caller().hash(&mut hasher);
760-
let hc64 = hasher.finish();
761-
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
762-
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
763-
rand::SeedableRng::from_seed(seed)
764-
}
765-
}
742+
pub(crate) mod test_helpers;

library/std/src/os/unix/fs/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
#[test]
44
fn read_vectored_at() {
55
let msg = b"preadv is working!";
6-
let dir = crate::sys_common::io::test::tmpdir();
6+
let dir = crate::test_helpers::tmpdir();
77

88
let filename = dir.join("preadv.txt");
99
{
@@ -31,7 +31,7 @@ fn read_vectored_at() {
3131
#[test]
3232
fn write_vectored_at() {
3333
let msg = b"pwritev is not working!";
34-
let dir = crate::sys_common::io::test::tmpdir();
34+
let dir = crate::test_helpers::tmpdir();
3535

3636
let filename = dir.join("preadv.txt");
3737
{

library/std/src/os/unix/net/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::os::android::net::{SocketAddrExt, UnixSocketExt};
77
use crate::os::linux::net::{SocketAddrExt, UnixSocketExt};
88
#[cfg(any(target_os = "android", target_os = "linux"))]
99
use crate::os::unix::io::AsRawFd;
10-
use crate::sys_common::io::test::tmpdir;
10+
use crate::test_helpers::tmpdir;
1111
use crate::thread;
1212
use crate::time::Duration;
1313

library/std/src/process/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ fn debug_print() {
697697
#[test]
698698
#[cfg(windows)]
699699
fn run_bat_script() {
700-
let tempdir = crate::sys_common::io::test::tmpdir();
700+
let tempdir = crate::test_helpers::tmpdir();
701701
let script_path = tempdir.join("hello.cmd");
702702

703703
crate::fs::write(&script_path, "@echo Hello, %~1!").unwrap();
@@ -716,7 +716,7 @@ fn run_bat_script() {
716716
#[test]
717717
#[cfg(windows)]
718718
fn run_canonical_bat_script() {
719-
let tempdir = crate::sys_common::io::test::tmpdir();
719+
let tempdir = crate::test_helpers::tmpdir();
720720
let script_path = tempdir.join("hello.cmd");
721721

722722
crate::fs::write(&script_path, "@echo Hello, %~1!").unwrap();

library/std/src/sys/io/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ mod is_terminal {
3838

3939
pub use io_slice::{IoSlice, IoSliceMut};
4040
pub use is_terminal::is_terminal;
41+
42+
// Bare metal platforms usually have very small amounts of RAM
43+
// (in the order of hundreds of KB)
44+
pub const DEFAULT_BUF_SIZE: usize = if cfg!(target_os = "espidf") { 512 } else { 8 * 1024 };

library/std/src/sys/pal/sgx/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl io::Write for Stderr {
6262
}
6363
}
6464

65-
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
65+
pub const STDIN_BUF_SIZE: usize = crate::sys::io::DEFAULT_BUF_SIZE;
6666

6767
pub fn is_ebadf(err: &io::Error) -> bool {
6868
// FIXME: Rust normally maps Unix EBADF to `Uncategorized`

library/std/src/sys/pal/unix/kernel_copy/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::fs::OpenOptions;
22
use crate::io;
33
use crate::io::{BufRead, Read, Result, Seek, SeekFrom, Write};
44
use crate::os::unix::io::AsRawFd;
5-
use crate::sys_common::io::test::tmpdir;
5+
use crate::test_helpers::tmpdir;
66

77
#[test]
88
fn copy_specialization() -> Result<()> {

library/std/src/sys/pal/unix/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn is_ebadf(err: &io::Error) -> bool {
9292
err.raw_os_error() == Some(libc::EBADF as i32)
9393
}
9494

95-
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
95+
pub const STDIN_BUF_SIZE: usize = crate::sys::io::DEFAULT_BUF_SIZE;
9696

9797
pub fn panic_output() -> Option<impl io::Write> {
9898
Some(Stderr::new())

0 commit comments

Comments
 (0)