Rollup merge of #152672 - joboet:apple_args_libc, r=jhpratt

std: use libc version of `_NSGetArgc`/`_NSGetArgv`

These were added to libc in https://github.com/rust-lang/libc/pull/3702.
This commit is contained in:
Stuart Cook 2026-02-18 17:29:47 +11:00 committed by GitHub
commit 9a82b6700a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -164,7 +164,7 @@ mod imp {
// of this used `[[NSProcessInfo processInfo] arguments]`. // of this used `[[NSProcessInfo processInfo] arguments]`.
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
mod imp { mod imp {
use crate::ffi::{c_char, c_int}; use crate::ffi::c_char;
pub unsafe fn init(_argc: isize, _argv: *const *const u8) { pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
// No need to initialize anything in here, `libdyld.dylib` has already // No need to initialize anything in here, `libdyld.dylib` has already
@ -172,12 +172,6 @@ mod imp {
} }
pub fn argc_argv() -> (isize, *const *const c_char) { pub fn argc_argv() -> (isize, *const *const c_char) {
unsafe extern "C" {
// These functions are in crt_externs.h.
fn _NSGetArgc() -> *mut c_int;
fn _NSGetArgv() -> *mut *mut *mut c_char;
}
// SAFETY: The returned pointer points to a static initialized early // SAFETY: The returned pointer points to a static initialized early
// in the program lifetime by `libdyld.dylib`, and as such is always // in the program lifetime by `libdyld.dylib`, and as such is always
// valid. // valid.
@ -187,9 +181,9 @@ mod imp {
// doesn't exist a lock that we can take. Instead, it is generally // doesn't exist a lock that we can take. Instead, it is generally
// expected that it's only modified in `main` / before other code // expected that it's only modified in `main` / before other code
// runs, so reading this here should be fine. // runs, so reading this here should be fine.
let argc = unsafe { _NSGetArgc().read() }; let argc = unsafe { libc::_NSGetArgc().read() };
// SAFETY: Same as above. // SAFETY: Same as above.
let argv = unsafe { _NSGetArgv().read() }; let argv = unsafe { libc::_NSGetArgv().read() };
// Cast from `*mut *mut c_char` to `*const *const c_char` // Cast from `*mut *mut c_char` to `*const *const c_char`
(argc as isize, argv.cast()) (argc as isize, argv.cast())