Skip to content

Commit 6ffebb6

Browse files
committed
Move args into std::sys
1 parent 1bc5618 commit 6ffebb6

File tree

26 files changed

+53
-41
lines changed

26 files changed

+53
-41
lines changed

library/std/src/sys/args/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Platform-dependent command line arguments abstraction.
2+
3+
#![forbid(unsafe_op_in_unsafe_fn)]
4+
5+
cfg_if::cfg_if! {
6+
if #[cfg(target_family = "unix")] {
7+
mod unix;
8+
pub use unix::*;
9+
} else if #[cfg(target_family = "windows")] {
10+
mod windows;
11+
pub use windows::*;
12+
} else if #[cfg(target_os = "hermit")] {
13+
mod hermit;
14+
pub use hermit::*;
15+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
16+
mod sgx;
17+
pub use sgx::*;
18+
} else if #[cfg(target_os = "uefi")] {
19+
mod uefi;
20+
pub use uefi::*;
21+
} else if #[cfg(target_os = "wasi")] {
22+
mod wasi;
23+
pub use wasi::*;
24+
} else if #[cfg(target_os = "xous")] {
25+
mod xous;
26+
pub use xous::*;
27+
} else if #[cfg(target_os = "zkvm")] {
28+
mod zkvm;
29+
pub use zkvm::*;
30+
} else {
31+
mod unsupported;
32+
pub use unsupported::*;
33+
}
34+
}

library/std/src/sys/pal/sgx/args.rs renamed to library/std/src/sys/args/sgx.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use super::abi::usercalls::alloc;
2-
use super::abi::usercalls::raw::ByteBuffer;
1+
#![allow(fuzzy_provenance_casts)] // FIXME: this module systematically confuses pointers and integers
2+
33
use crate::ffi::OsString;
44
use crate::sync::atomic::{AtomicUsize, Ordering};
55
use crate::sys::os_str::Buf;
6+
use crate::sys::pal::abi::usercalls::alloc;
7+
use crate::sys::pal::abi::usercalls::raw::ByteBuffer;
68
use crate::sys_common::FromInner;
79
use crate::{fmt, slice};
810

library/std/src/sys/pal/uefi/args.rs renamed to library/std/src/sys/args/uefi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use r_efi::protocols::loaded_image;
22

3-
use super::helpers;
43
use crate::env::current_exe;
54
use crate::ffi::OsString;
65
use crate::iter::Iterator;
6+
use crate::sys::pal::helpers;
77
use crate::{fmt, vec};
88

99
pub struct Args {

library/std/src/sys/pal/unix/args.rs renamed to library/std/src/sys/args/unix.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{fmt, vec};
1111

1212
/// One-time global initialization.
1313
pub unsafe fn init(argc: isize, argv: *const *const u8) {
14-
imp::init(argc, argv)
14+
unsafe { imp::init(argc, argv) }
1515
}
1616

1717
/// Returns the command line arguments
@@ -141,7 +141,7 @@ mod imp {
141141
pub unsafe fn init(argc: isize, argv: *const *const u8) {
142142
// on GNU/Linux if we are main then we will init argv and argc twice, it "duplicates work"
143143
// BUT edge-cases are real: only using .init_array can break most emulators, dlopen, etc.
144-
really_init(argc, argv);
144+
unsafe { really_init(argc, argv) };
145145
}
146146

147147
/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.
@@ -159,9 +159,7 @@ mod imp {
159159
argv: *const *const u8,
160160
_envp: *const *const u8,
161161
) {
162-
unsafe {
163-
really_init(argc as isize, argv);
164-
}
162+
unsafe { really_init(argc as isize, argv) };
165163
}
166164
init_wrapper
167165
};

library/std/src/sys/pal/windows/args.rs renamed to library/std/src/sys/args/windows.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
#[cfg(test)]
77
mod tests;
88

9-
use super::ensure_no_nuls;
10-
use super::os::current_exe;
119
use crate::ffi::{OsStr, OsString};
1210
use crate::num::NonZero;
1311
use crate::os::windows::prelude::*;
1412
use crate::path::{Path, PathBuf};
13+
use crate::sys::pal::os::current_exe;
14+
use crate::sys::pal::{ensure_no_nuls, fill_utf16_buf};
1515
use crate::sys::path::get_long_path;
1616
use crate::sys::{c, to_u16s};
1717
use crate::sys_common::AsInner;
1818
use crate::sys_common::wstr::WStrUnits;
19-
use crate::{fmt, io, iter, vec};
19+
use crate::{fmt, io, iter, ptr, vec};
2020

2121
pub fn args() -> Args {
2222
// SAFETY: `GetCommandLineW` returns a pointer to a null terminated UTF-16
@@ -384,9 +384,6 @@ pub(crate) fn to_user_path(path: &Path) -> io::Result<Vec<u16>> {
384384
from_wide_to_user_path(to_u16s(path)?)
385385
}
386386
pub(crate) fn from_wide_to_user_path(mut path: Vec<u16>) -> io::Result<Vec<u16>> {
387-
use super::fill_utf16_buf;
388-
use crate::ptr;
389-
390387
// UTF-16 encoded code points, used in parsing and building UTF-16 paths.
391388
// All of these are in the ASCII range so they can be cast directly to `u16`.
392389
const SEP: u16 = b'\\' as _;

library/std/src/sys/pal/xous/args.rs renamed to library/std/src/sys/args/xous.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::ffi::OsString;
2-
use crate::sys::pal::xous::os::get_application_parameters;
3-
use crate::sys::pal::xous::os::params::ArgumentList;
2+
use crate::sys::pal::os::get_application_parameters;
3+
use crate::sys::pal::os::params::ArgumentList;
44
use crate::{fmt, vec};
55

66
pub struct Args {

0 commit comments

Comments
 (0)