Skip to content

Commit

Permalink
Auto merge of rust-lang#114016 - krtab:delete_sys_memchr, r=workingju…
Browse files Browse the repository at this point in the history
…bilee

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 rust-lang#113654
  • Loading branch information
bors committed Dec 16, 2023
2 parents 1c6a061 + 513e4e2 commit decdc73
Show file tree
Hide file tree
Showing 17 changed files with 4 additions and 133 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/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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;

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
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 decdc73

Please sign in to comment.