mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
use c literals in library
This commit is contained in:
parent
a17561ffc9
commit
f212ba6d6d
@ -240,6 +240,7 @@
|
||||
#![feature(allocator_internals)]
|
||||
#![feature(allow_internal_unsafe)]
|
||||
#![feature(allow_internal_unstable)]
|
||||
#![feature(c_str_literals)]
|
||||
#![feature(c_unwind)]
|
||||
#![feature(cfg_target_thread_local)]
|
||||
#![feature(concat_idents)]
|
||||
|
@ -242,13 +242,13 @@ mod imp {
|
||||
let mut res = Vec::new();
|
||||
|
||||
unsafe {
|
||||
let process_info_sel = sel_registerName("processInfo\0".as_ptr());
|
||||
let arguments_sel = sel_registerName("arguments\0".as_ptr());
|
||||
let utf8_sel = sel_registerName("UTF8String\0".as_ptr());
|
||||
let count_sel = sel_registerName("count\0".as_ptr());
|
||||
let object_at_sel = sel_registerName("objectAtIndex:\0".as_ptr());
|
||||
let process_info_sel = sel_registerName(c"processInfo".as_ptr());
|
||||
let arguments_sel = sel_registerName(c"arguments".as_ptr());
|
||||
let utf8_sel = sel_registerName(c"UTF8String".as_ptr());
|
||||
let count_sel = sel_registerName(c"count".as_ptr());
|
||||
let object_at_sel = sel_registerName(c"objectAtIndex:".as_ptr());
|
||||
|
||||
let klass = objc_getClass("NSProcessInfo\0".as_ptr());
|
||||
let klass = objc_getClass(c"NSProcessInfo".as_ptr());
|
||||
let info = objc_msgSend(klass, process_info_sel);
|
||||
let args = objc_msgSend(info, arguments_sel);
|
||||
|
||||
|
@ -1063,7 +1063,7 @@ impl File {
|
||||
cfg_has_statx! {
|
||||
if let Some(ret) = unsafe { try_statx(
|
||||
fd,
|
||||
b"\0" as *const _ as *const c_char,
|
||||
c"".as_ptr() as *const c_char,
|
||||
libc::AT_EMPTY_PATH | libc::AT_STATX_SYNC_AS_STAT,
|
||||
libc::STATX_ALL,
|
||||
) } {
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![allow(missing_docs, nonstandard_style)]
|
||||
|
||||
use crate::ffi::CStr;
|
||||
use crate::io::ErrorKind;
|
||||
|
||||
pub use self::rand::hashmap_random_keys;
|
||||
@ -75,7 +74,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
// thread-id for the main thread and so renaming the main thread will rename the
|
||||
// process and we only want to enable this on platforms we've tested.
|
||||
if cfg!(target_os = "macos") {
|
||||
thread::Thread::set_name(&CStr::from_bytes_with_nul_unchecked(b"main\0"));
|
||||
thread::Thread::set_name(&c"main");
|
||||
}
|
||||
|
||||
unsafe fn sanitize_standard_fds() {
|
||||
@ -121,7 +120,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
if pfd.revents & libc::POLLNVAL == 0 {
|
||||
continue;
|
||||
}
|
||||
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
if open64(c"/dev/null".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
// If the stream is closed but we failed to reopen it, abort the
|
||||
// process. Otherwise we wouldn't preserve the safety of
|
||||
// operations on the corresponding Rust object Stdin, Stdout, or
|
||||
@ -151,7 +150,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
use libc::open64;
|
||||
for fd in 0..3 {
|
||||
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
|
||||
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
if open64(c"/dev/null".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
|
||||
// If the stream is closed but we failed to reopen it, abort the
|
||||
// process. Otherwise we wouldn't preserve the safety of
|
||||
// operations on the corresponding Rust object Stdin, Stdout, or
|
||||
|
@ -24,11 +24,11 @@ cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "fuchsia")] {
|
||||
// fuchsia doesn't have /dev/null
|
||||
} else if #[cfg(target_os = "redox")] {
|
||||
const DEV_NULL: &str = "null:\0";
|
||||
const DEV_NULL: &CStr = c"null:";
|
||||
} else if #[cfg(target_os = "vxworks")] {
|
||||
const DEV_NULL: &str = "/null\0";
|
||||
const DEV_NULL: &CStr = c"/null";
|
||||
} else {
|
||||
const DEV_NULL: &str = "/dev/null\0";
|
||||
const DEV_NULL: &CStr = c"/dev/null";
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,8 +474,7 @@ impl Stdio {
|
||||
let mut opts = OpenOptions::new();
|
||||
opts.read(readable);
|
||||
opts.write(!readable);
|
||||
let path = unsafe { CStr::from_ptr(DEV_NULL.as_ptr() as *const _) };
|
||||
let fd = File::open_c(&path, &opts)?;
|
||||
let fd = File::open_c(DEV_NULL, &opts)?;
|
||||
Ok((ChildStdio::Owned(fd.into_inner()), None))
|
||||
}
|
||||
|
||||
|
@ -163,10 +163,9 @@ impl Thread {
|
||||
#[cfg(target_os = "netbsd")]
|
||||
pub fn set_name(name: &CStr) {
|
||||
unsafe {
|
||||
let cname = CStr::from_bytes_with_nul_unchecked(b"%s\0".as_slice());
|
||||
let res = libc::pthread_setname_np(
|
||||
libc::pthread_self(),
|
||||
cname.as_ptr(),
|
||||
c"%s".as_ptr(),
|
||||
name.as_ptr() as *mut libc::c_void,
|
||||
);
|
||||
debug_assert_eq!(res, 0);
|
||||
|
@ -317,7 +317,7 @@ pub unsafe fn NtWriteFile(
|
||||
// Functions that aren't available on every version of Windows that we support,
|
||||
// but we still use them and just provide some form of a fallback implementation.
|
||||
compat_fn_with_fallback! {
|
||||
pub static KERNEL32: &CStr = ansi_str!("kernel32");
|
||||
pub static KERNEL32: &CStr = c"kernel32";
|
||||
|
||||
// >= Win10 1607
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
|
||||
@ -350,7 +350,7 @@ compat_fn_optional! {
|
||||
}
|
||||
|
||||
compat_fn_with_fallback! {
|
||||
pub static NTDLL: &CStr = ansi_str!("ntdll");
|
||||
pub static NTDLL: &CStr = c"ntdll";
|
||||
|
||||
pub fn NtCreateKeyedEvent(
|
||||
KeyedEventHandle: LPHANDLE,
|
||||
|
@ -228,9 +228,9 @@ macro_rules! compat_fn_optional {
|
||||
/// Load all needed functions from "api-ms-win-core-synch-l1-2-0".
|
||||
pub(super) fn load_synch_functions() {
|
||||
fn try_load() -> Option<()> {
|
||||
const MODULE_NAME: &CStr = ansi_str!("api-ms-win-core-synch-l1-2-0");
|
||||
const WAIT_ON_ADDRESS: &CStr = ansi_str!("WaitOnAddress");
|
||||
const WAKE_BY_ADDRESS_SINGLE: &CStr = ansi_str!("WakeByAddressSingle");
|
||||
const MODULE_NAME: &CStr = c"api-ms-win-core-synch-l1-2-0";
|
||||
const WAIT_ON_ADDRESS: &CStr = c"WaitOnAddress";
|
||||
const WAKE_BY_ADDRESS_SINGLE: &CStr = c"WakeByAddressSingle";
|
||||
|
||||
// Try loading the library and all the required functions.
|
||||
// If any step fails, then they all fail.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(missing_docs, nonstandard_style)]
|
||||
|
||||
use crate::ffi::{CStr, OsStr, OsString};
|
||||
use crate::ffi::{OsStr, OsString};
|
||||
use crate::io::ErrorKind;
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
|
||||
@ -51,7 +51,7 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {
|
||||
|
||||
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
|
||||
// exists, we have to call it ourselves.
|
||||
thread::Thread::set_name(&CStr::from_bytes_with_nul_unchecked(b"main\0"));
|
||||
thread::Thread::set_name(&c"main");
|
||||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
|
@ -132,7 +132,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
"crypto-common",
|
||||
"cstr",
|
||||
"datafrog",
|
||||
"derive_more",
|
||||
"digest",
|
||||
|
Loading…
Reference in New Issue
Block a user