Skip to content

Commit 6f435eb

Browse files
committed
Auto merge of #114016 - krtab:delete_sys_memchr, r=workingjubilee
Delete architecture-specific memchr code in std::sys Currently all architecture-specific memchr code is only used in `std::io`. Most of the actual `memchr` capacity exposed to the user through the slice API is instead implemented in `core::slice::memchr`. Hence this commit deletes `memchr` from `std::sys[_common]` and replace calls to it by calls to `core::slice::memchr` functions. This deletes `(r)memchr` from the list of symbols linked to libc. The interest of putting architecture specific code back in core is linked to the discussion to be had in #113654
2 parents 77be7a3 + 88ac7ac commit 6f435eb

File tree

23 files changed

+8
-231
lines changed

23 files changed

+8
-231
lines changed

library/std/src/io/buffered/linewritershim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::io::{self, BufWriter, IoSlice, Write};
2-
use crate::sys_common::memchr;
2+
use core::slice::memchr;
33

44
/// Private helper struct for implementing the line-buffered writing logic.
55
/// This shim temporarily wraps a BufWriter, and uses its internals to

library/std/src/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ use crate::ops::{Deref, DerefMut};
304304
use crate::slice;
305305
use crate::str;
306306
use crate::sys;
307-
use crate::sys_common::memchr;
307+
use core::slice::memchr;
308308

309309
#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
310310
pub use self::buffered::WriterPanicked;

library/std/src/sys/pal/hermit/memchr.rs

-1
This file was deleted.

library/std/src/sys/pal/hermit/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub mod fs;
2525
pub mod futex;
2626
#[path = "../unsupported/io.rs"]
2727
pub mod io;
28-
pub mod memchr;
2928
pub mod net;
3029
pub mod os;
3130
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/hermit/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::os::hermit::ffi::OsStringExt;
99
use crate::path::{self, PathBuf};
1010
use crate::str;
1111
use crate::sync::Mutex;
12-
use crate::sys::memchr;
1312
use crate::sys::unsupported;
1413
use crate::vec;
14+
use core::slice::memchr;
1515

1616
pub fn errno() -> i32 {
1717
unsafe { abi::get_errno() }

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

-1
This file was deleted.

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

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod fd;
1717
pub mod fs;
1818
#[path = "../unsupported/io.rs"]
1919
pub mod io;
20-
pub mod memchr;
2120
pub mod net;
2221
pub mod os;
2322
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/solid/memchr.rs

-21
This file was deleted.

library/std/src/sys/pal/solid/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub mod pipe;
3333
pub mod process;
3434
pub mod stdio;
3535
pub use self::itron::thread;
36-
pub mod memchr;
3736
pub mod thread_local_dtor;
3837
pub mod thread_local_key;
3938
pub use self::itron::thread_parking;

library/std/src/sys/pal/solid/os.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::sync::{PoisonError, RwLock};
1212
use crate::sys::common::small_c_string::run_with_cstr;
1313
use crate::vec;
1414

15-
use super::{error, itron, memchr};
15+
use super::{error, itron};
16+
17+
use core::slice::memchr;
1618

1719
// `solid` directly maps `errno`s to μITRON error codes.
1820
impl itron::error::ItronError {

library/std/src/sys/pal/teeos/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ pub mod env;
1818
pub mod fs;
1919
#[path = "../unsupported/io.rs"]
2020
pub mod io;
21-
#[path = "../unix/memchr.rs"]
22-
pub mod memchr;
2321
pub mod net;
2422
#[path = "../unsupported/once.rs"]
2523
pub mod once;

library/std/src/sys/pal/uefi/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ use crate::os::uefi;
4848
use crate::ptr::NonNull;
4949
use crate::sync::atomic::{AtomicPtr, Ordering};
5050

51-
pub mod memchr {
52-
pub use core::slice::memchr::{memchr, memrchr};
53-
}
54-
5551
static EXIT_BOOT_SERVICE_EVENT: AtomicPtr<crate::ffi::c_void> =
5652
AtomicPtr::new(crate::ptr::null_mut());
5753

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

-40
This file was deleted.

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

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub mod io;
2020
pub mod kernel_copy;
2121
#[cfg(target_os = "l4re")]
2222
mod l4re;
23-
pub mod memchr;
2423
#[cfg(not(target_os = "l4re"))]
2524
pub mod net;
2625
#[cfg(target_os = "l4re")]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::sync::{PoisonError, RwLock};
2121
use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr};
2222
use crate::sys::cvt;
2323
use crate::sys::fd;
24-
use crate::sys::memchr;
2524
use crate::vec;
25+
use core::slice::memchr;
2626

2727
#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
2828
use crate::sys::weak::weak;

library/std/src/sys/pal/unsupported/common.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use crate::io as std_io;
22

3-
pub mod memchr {
4-
pub use core::slice::memchr::{memchr, memrchr};
5-
}
6-
73
// SAFETY: must be called only once during runtime initialization.
84
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
95
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}

library/std/src/sys/pal/wasi/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::os::wasi::prelude::*;
1010
use crate::path::{self, PathBuf};
1111
use crate::str;
1212
use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr};
13-
use crate::sys::memchr;
1413
use crate::sys::unsupported;
1514
use crate::vec;
15+
use core::slice::memchr;
1616

1717
// Add a few symbols not in upstream `libc` just yet.
1818
mod libc {

library/std/src/sys/pal/windows/memchr.rs

-5
This file was deleted.

library/std/src/sys/pal/windows/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod env;
1919
pub mod fs;
2020
pub mod handle;
2121
pub mod io;
22-
pub mod memchr;
2322
pub mod net;
2423
pub mod os;
2524
pub mod pipe;

library/std/src/sys/pal/zkvm/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ mod abi;
4343

4444
use crate::io as std_io;
4545

46-
pub mod memchr {
47-
pub use core::slice::memchr::{memchr, memrchr};
48-
}
49-
5046
// SAFETY: must be called only once during runtime initialization.
5147
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
5248
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}

library/std/src/sys_common/memchr.rs

-51
This file was deleted.

library/std/src/sys_common/memchr/tests.rs

-86
This file was deleted.

library/std/src/sys_common/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub mod backtrace;
2424
pub mod fs;
2525
pub mod io;
2626
pub mod lazy_box;
27-
pub mod memchr;
2827
pub mod once;
2928
pub mod process;
3029
pub mod thread;

0 commit comments

Comments
 (0)