Skip to content

Commit

Permalink
Make std::sys::unix::args::init a no-op on glibc Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
leo60228 committed Nov 22, 2019
1 parent 55fe6d8 commit d448ab0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libstd/sys/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ mod imp {
// acquire this mutex reentrantly!
static LOCK: Mutex = Mutex::new();

pub unsafe fn init(argc: isize, argv: *const *const u8) {
unsafe fn really_init(argc: isize, argv: *const *const u8) {
let _guard = LOCK.lock();
ARGC = argc;
ARGV = argv;
}

#[inline(always)]
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
really_init(_argc, _argv);
}

/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.
/// This allows `std::env::args` to work even in a `cdylib`, as it does on macOS and Windows.
#[cfg(all(target_os = "linux", target_env = "gnu"))]
Expand All @@ -94,7 +100,7 @@ mod imp {
_envp: *const *const u8,
) {
unsafe {
init(argc as isize, argv);
really_init(argc as isize, argv);
}
}
init_wrapper
Expand Down

0 comments on commit d448ab0

Please sign in to comment.