Skip to content

Commit

Permalink
Auto merge of rust-lang#132121 - workingjubilee:rollup-yrtn33e, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 6 pull requests

Successful merges:

 - rust-lang#131851 ([musl] use posix_spawn if a directory change was requested)
 - rust-lang#132048 (AIX: use /dev/urandom for random implementation )
 - rust-lang#132093 (compiletest: suppress Windows Error Reporting (WER) for `run-make` tests)
 - rust-lang#132101 (Avoid using imports in thread_local_inner! in static)
 - rust-lang#132113 (Provide a default impl for Pattern::as_utf8_pattern)
 - rust-lang#132115 (rustdoc: Extend fake_variadic to "wrapped" tuples)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 25, 2024
2 parents b4ea08d + 5cf142b commit 2da7b7f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 28 deletions.
14 changes: 3 additions & 11 deletions core/src/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ pub trait Pattern: Sized {
}

/// Returns the pattern as utf-8 bytes if possible.
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>;
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
}
/// Result of calling [`Pattern::as_utf8_pattern()`].
/// Can be used for inspecting the contents of a [`Pattern`] in cases
Expand Down Expand Up @@ -675,11 +677,6 @@ impl<C: MultiCharEq> Pattern for MultiCharEqPattern<C> {
fn into_searcher(self, haystack: &str) -> MultiCharEqSearcher<'_, C> {
MultiCharEqSearcher { haystack, char_eq: self.0, char_indices: haystack.char_indices() }
}

#[inline]
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
}

unsafe impl<'a, C: MultiCharEq> Searcher<'a> for MultiCharEqSearcher<'a, C> {
Expand Down Expand Up @@ -770,11 +767,6 @@ macro_rules! pattern_methods {
{
($pmap)(self).strip_suffix_of(haystack)
}

#[inline]
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>> {
None
}
};
}

Expand Down
14 changes: 14 additions & 0 deletions std/src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,23 @@ fn stdout_works() {
#[test]
#[cfg_attr(any(windows, target_os = "vxworks"), ignore)]
fn set_current_dir_works() {
// On many Unix platforms this will use the posix_spawn path.
let mut cmd = shell_cmd();
cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
assert_eq!(run_output(cmd), "/\n");

// Also test the fork/exec path by setting a pre_exec function.
#[cfg(unix)]
{
use crate::os::unix::process::CommandExt;

let mut cmd = shell_cmd();
cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped());
unsafe {
cmd.pre_exec(|| Ok(()));
}
assert_eq!(run_output(cmd), "/\n");
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion std/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::sys::random as sys;
/// Vita | `arc4random_buf`
/// Hermit | `read_entropy`
/// Horizon | `getrandom` shim
/// Hurd, L4Re, QNX | `/dev/urandom`
/// AIX, Hurd, L4Re, QNX | `/dev/urandom`
/// Redox | `/scheme/rand`
/// RTEMS | [`arc4random_buf`](https://docs.rtems.org/branches/master/bsp-howto/getentropy.html)
/// SGX | [`rdrand`](https://en.wikipedia.org/wiki/RDRAND)
Expand Down
54 changes: 43 additions & 11 deletions std/src/sys/pal/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ impl Command {
use core::sync::atomic::{AtomicU8, Ordering};

use crate::mem::MaybeUninit;
use crate::sys::weak::weak;
use crate::sys::{self, cvt_nz, on_broken_pipe_flag_used};

if self.get_gid().is_some()
Expand All @@ -462,6 +461,8 @@ impl Command {

cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
use crate::sys::weak::weak;

weak! {
fn pidfd_spawnp(
*mut libc::c_int,
Expand Down Expand Up @@ -575,16 +576,44 @@ impl Command {
}
}

// Solaris, glibc 2.29+, and musl 1.24+ can set a new working directory,
// and maybe others will gain this non-POSIX function too. We'll check
// for this weak symbol as soon as it's needed, so we can return early
// otherwise to do a manual chdir before exec.
weak! {
fn posix_spawn_file_actions_addchdir_np(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char
) -> libc::c_int
type PosixSpawnAddChdirFn = unsafe extern "C" fn(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char,
) -> libc::c_int;

/// Get the function pointer for adding a chdir action to a
/// `posix_spawn_file_actions_t`, if available, assuming a dynamic libc.
///
/// Some platforms can set a new working directory for a spawned process in the
/// `posix_spawn` path. This function looks up the function pointer for adding
/// such an action to a `posix_spawn_file_actions_t` struct.
#[cfg(not(all(target_os = "linux", target_env = "musl")))]
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
use crate::sys::weak::weak;

weak! {
fn posix_spawn_file_actions_addchdir_np(
*mut libc::posix_spawn_file_actions_t,
*const libc::c_char
) -> libc::c_int
}

posix_spawn_file_actions_addchdir_np.get()
}

/// Get the function pointer for adding a chdir action to a
/// `posix_spawn_file_actions_t`, if available, on platforms where the function
/// is known to exist.
///
/// Weak symbol lookup doesn't work with statically linked libcs, so in cases
/// where static linking is possible we need to either check for the presence
/// of the symbol at compile time or know about it upfront.
#[cfg(all(target_os = "linux", target_env = "musl"))]
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
// Our minimum required musl supports this function, so we can just use it.
Some(libc::posix_spawn_file_actions_addchdir_np)
}

let addchdir = match self.get_cwd() {
Some(cwd) => {
if cfg!(target_vendor = "apple") {
Expand All @@ -597,7 +626,10 @@ impl Command {
return Ok(None);
}
}
match posix_spawn_file_actions_addchdir_np.get() {
// Check for the availability of the posix_spawn addchdir
// function now. If it isn't available, bail and use the
// fork/exec path.
match get_posix_spawn_addchdir() {
Some(f) => Some((f, cwd)),
None => return Ok(None),
}
Expand Down
1 change: 1 addition & 0 deletions std/src/sys/random/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cfg_if::cfg_if! {
mod horizon;
pub use horizon::fill_bytes;
} else if #[cfg(any(
target_os = "aix",
target_os = "hurd",
target_os = "l4re",
target_os = "nto",
Expand Down
9 changes: 4 additions & 5 deletions std/src/sys/thread_local/statik.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ pub macro thread_local_inner {
(@key $t:ty, const $init:expr) => {{
const __INIT: $t = $init;

// NOTE: Please update the shadowing test in `tests/thread.rs` if these types are renamed.
unsafe {
use $crate::thread::LocalKey;
use $crate::thread::local_impl::EagerStorage;

LocalKey::new(|_| {
static VAL: EagerStorage<$t> = EagerStorage { value: __INIT };
$crate::thread::LocalKey::new(|_| {
static VAL: $crate::thread::local_impl::EagerStorage<$t> =
$crate::thread::local_impl::EagerStorage { value: __INIT };
&VAL.value
})
}
Expand Down

0 comments on commit 2da7b7f

Please sign in to comment.