From d448ab0cf10a6c822b209f208a87ce200efd0772 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Thu, 21 Nov 2019 13:42:25 -0500 Subject: [PATCH] Make std::sys::unix::args::init a no-op on glibc Linux --- src/libstd/sys/unix/args.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs index 58fa305a8190a..15dafb1bcf964 100644 --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -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"))] @@ -94,7 +100,7 @@ mod imp { _envp: *const *const u8, ) { unsafe { - init(argc as isize, argv); + really_init(argc as isize, argv); } } init_wrapper