Skip to content

Commit

Permalink
Auto merge of #114016 - krtab:delete_sys_memchr, r=workingjubilee
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Mar 1, 2024
2 parents 77be7a3 + 88ac7ac commit 6f435eb
Show file tree
Hide file tree
Showing 23 changed files with 8 additions and 231 deletions.
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/linewritershim.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::io::{self, BufWriter, IoSlice, Write};
use crate::sys_common::memchr;
use core::slice::memchr;

/// Private helper struct for implementing the line-buffered writing logic.
/// This shim temporarily wraps a BufWriter, and uses its internals to
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ use crate::ops::{Deref, DerefMut};
use crate::slice;
use crate::str;
use crate::sys;
use crate::sys_common::memchr;
use core::slice::memchr;

#[stable(feature = "bufwriter_into_parts", since = "1.56.0")]
pub use self::buffered::WriterPanicked;
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/hermit/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod fs;
pub mod futex;
#[path = "../unsupported/io.rs"]
pub mod io;
pub mod memchr;
pub mod net;
pub mod os;
#[path = "../unsupported/pipe.rs"]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/hermit/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::os::hermit::ffi::OsStringExt;
use crate::path::{self, PathBuf};
use crate::str;
use crate::sync::Mutex;
use crate::sys::memchr;
use crate::sys::unsupported;
use crate::vec;
use core::slice::memchr;

pub fn errno() -> i32 {
unsafe { abi::get_errno() }
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/pal/sgx/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub mod fd;
pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
pub mod memchr;
pub mod net;
pub mod os;
#[path = "../unsupported/pipe.rs"]
Expand Down
21 changes: 0 additions & 21 deletions library/std/src/sys/pal/solid/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod pipe;
pub mod process;
pub mod stdio;
pub use self::itron::thread;
pub mod memchr;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub use self::itron::thread_parking;
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/sys/pal/solid/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::sync::{PoisonError, RwLock};
use crate::sys::common::small_c_string::run_with_cstr;
use crate::vec;

use super::{error, itron, memchr};
use super::{error, itron};

use core::slice::memchr;

// `solid` directly maps `errno`s to μITRON error codes.
impl itron::error::ItronError {
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub mod env;
pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
#[path = "../unix/memchr.rs"]
pub mod memchr;
pub mod net;
#[path = "../unsupported/once.rs"]
pub mod once;
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ use crate::os::uefi;
use crate::ptr::NonNull;
use crate::sync::atomic::{AtomicPtr, Ordering};

pub mod memchr {
pub use core::slice::memchr::{memchr, memrchr};
}

static EXIT_BOOT_SERVICE_EVENT: AtomicPtr<crate::ffi::c_void> =
AtomicPtr::new(crate::ptr::null_mut());

Expand Down
40 changes: 0 additions & 40 deletions library/std/src/sys/pal/unix/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub mod io;
pub mod kernel_copy;
#[cfg(target_os = "l4re")]
mod l4re;
pub mod memchr;
#[cfg(not(target_os = "l4re"))]
pub mod net;
#[cfg(target_os = "l4re")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::sync::{PoisonError, RwLock};
use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr};
use crate::sys::cvt;
use crate::sys::fd;
use crate::sys::memchr;
use crate::vec;
use core::slice::memchr;

#[cfg(all(target_env = "gnu", not(target_os = "vxworks")))]
use crate::sys::weak::weak;
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/unsupported/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crate::io as std_io;

pub mod memchr {
pub use core::slice::memchr::{memchr, memrchr};
}

// SAFETY: must be called only once during runtime initialization.
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::os::wasi::prelude::*;
use crate::path::{self, PathBuf};
use crate::str;
use crate::sys::common::small_c_string::{run_path_with_cstr, run_with_cstr};
use crate::sys::memchr;
use crate::sys::unsupported;
use crate::vec;
use core::slice::memchr;

// Add a few symbols not in upstream `libc` just yet.
mod libc {
Expand Down
5 changes: 0 additions & 5 deletions library/std/src/sys/pal/windows/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/pal/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod env;
pub mod fs;
pub mod handle;
pub mod io;
pub mod memchr;
pub mod net;
pub mod os;
pub mod pipe;
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/zkvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ mod abi;

use crate::io as std_io;

pub mod memchr {
pub use core::slice::memchr::{memchr, memrchr};
}

// SAFETY: must be called only once during runtime initialization.
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {}
Expand Down
51 changes: 0 additions & 51 deletions library/std/src/sys_common/memchr.rs

This file was deleted.

86 changes: 0 additions & 86 deletions library/std/src/sys_common/memchr/tests.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub mod backtrace;
pub mod fs;
pub mod io;
pub mod lazy_box;
pub mod memchr;
pub mod once;
pub mod process;
pub mod thread;
Expand Down

0 comments on commit 6f435eb

Please sign in to comment.