Skip to content

Commit

Permalink
Delete architecture-specific memchr code in std::sys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krtab committed Dec 16, 2023
1 parent 1aa6aef commit 8ddbdb2
Show file tree
Hide file tree
Showing 21 changed files with 9 additions and 141 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/hermit/memchr.rs

This file was deleted.

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

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

This file was deleted.

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

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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
3 changes: 2 additions & 1 deletion library/std/src/sys/solid/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ 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
4 changes: 2 additions & 2 deletions library/std/src/sys/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub mod locks;
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 All @@ -49,6 +47,8 @@ pub mod time;

use crate::io::ErrorKind;

use core::slice::memchr;

pub fn abort_internal() -> ! {
unsafe { libc::abort() }
}
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,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/unix/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub mod kernel_copy;
#[cfg(target_os = "l4re")]
mod l4re;
pub mod locks;
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/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/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/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/windows/memchr.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/std/src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub mod fs;
pub mod handle;
pub mod io;
pub mod locks;
pub mod memchr;
pub mod net;
pub mod os;
pub mod os_str;
Expand Down
51 changes: 0 additions & 51 deletions library/std/src/sys_common/memchr.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 8ddbdb2

Please sign in to comment.