Skip to content

Commit b8dab3e

Browse files
authored
Rollup merge of #113334 - fmease:revert-lexing-c-str-lits, r=compiler-errors
Revert the lexing of `c"…"` string literals Fixes \[after beta-backport\] #113235. Further progress is tracked in #113333. This PR *manually* reverts parts of #108801 (since a git-revert would've been too coarse-grained & messy) and git-reverts #111647. CC `@fee1-dead` (#108801) `@klensy` (#111647) r? `@compiler-errors` `@rustbot` label F-c_str_literals beta-nominated
2 parents 19faeaa + 776d882 commit b8dab3e

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
#![feature(allocator_internals)]
242242
#![feature(allow_internal_unsafe)]
243243
#![feature(allow_internal_unstable)]
244-
#![feature(c_str_literals)]
245244
#![feature(c_unwind)]
246245
#![feature(cfg_target_thread_local)]
247246
#![feature(concat_idents)]

std/src/sys/unix/args.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,13 @@ mod imp {
242242
let mut res = Vec::new();
243243

244244
unsafe {
245-
let process_info_sel =
246-
sel_registerName(c"processInfo".as_ptr() as *const libc::c_uchar);
247-
let arguments_sel = sel_registerName(c"arguments".as_ptr() as *const libc::c_uchar);
248-
let utf8_sel = sel_registerName(c"UTF8String".as_ptr() as *const libc::c_uchar);
249-
let count_sel = sel_registerName(c"count".as_ptr() as *const libc::c_uchar);
250-
let object_at_sel =
251-
sel_registerName(c"objectAtIndex:".as_ptr() as *const libc::c_uchar);
252-
253-
let klass = objc_getClass(c"NSProcessInfo".as_ptr() as *const libc::c_uchar);
245+
let process_info_sel = sel_registerName("processInfo\0".as_ptr());
246+
let arguments_sel = sel_registerName("arguments\0".as_ptr());
247+
let utf8_sel = sel_registerName("UTF8String\0".as_ptr());
248+
let count_sel = sel_registerName("count\0".as_ptr());
249+
let object_at_sel = sel_registerName("objectAtIndex:\0".as_ptr());
250+
251+
let klass = objc_getClass("NSProcessInfo\0".as_ptr());
254252
let info = objc_msgSend(klass, process_info_sel);
255253
let args = objc_msgSend(info, arguments_sel);
256254

std/src/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ impl File {
10971097
cfg_has_statx! {
10981098
if let Some(ret) = unsafe { try_statx(
10991099
fd,
1100-
c"".as_ptr() as *const c_char,
1100+
b"\0" as *const _ as *const c_char,
11011101
libc::AT_EMPTY_PATH | libc::AT_STATX_SYNC_AS_STAT,
11021102
libc::STATX_ALL,
11031103
) } {

std/src/sys/unix/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(missing_docs, nonstandard_style)]
22

3+
use crate::ffi::CStr;
34
use crate::io::ErrorKind;
45

56
pub use self::rand::hashmap_random_keys;
@@ -74,7 +75,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
7475
// thread-id for the main thread and so renaming the main thread will rename the
7576
// process and we only want to enable this on platforms we've tested.
7677
if cfg!(target_os = "macos") {
77-
thread::Thread::set_name(&c"main");
78+
thread::Thread::set_name(&CStr::from_bytes_with_nul_unchecked(b"main\0"));
7879
}
7980

8081
unsafe fn sanitize_standard_fds() {
@@ -121,7 +122,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
121122
if pfd.revents & libc::POLLNVAL == 0 {
122123
continue;
123124
}
124-
if open64(c"/dev/null".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
125+
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
125126
// If the stream is closed but we failed to reopen it, abort the
126127
// process. Otherwise we wouldn't preserve the safety of
127128
// operations on the corresponding Rust object Stdin, Stdout, or
@@ -151,7 +152,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
151152
use libc::open64;
152153
for fd in 0..3 {
153154
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
154-
if open64(c"/dev/null".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
155+
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
155156
// If the stream is closed but we failed to reopen it, abort the
156157
// process. Otherwise we wouldn't preserve the safety of
157158
// operations on the corresponding Rust object Stdin, Stdout, or

std/src/sys/unix/process/process_common.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ cfg_if::cfg_if! {
2424
if #[cfg(target_os = "fuchsia")] {
2525
// fuchsia doesn't have /dev/null
2626
} else if #[cfg(target_os = "redox")] {
27-
const DEV_NULL: &CStr = c"null:";
27+
const DEV_NULL: &str = "null:\0";
2828
} else if #[cfg(target_os = "vxworks")] {
29-
const DEV_NULL: &CStr = c"/null";
29+
const DEV_NULL: &str = "/null\0";
3030
} else {
31-
const DEV_NULL: &CStr = c"/dev/null";
31+
const DEV_NULL: &str = "/dev/null\0";
3232
}
3333
}
3434

@@ -474,7 +474,8 @@ impl Stdio {
474474
let mut opts = OpenOptions::new();
475475
opts.read(readable);
476476
opts.write(!readable);
477-
let fd = File::open_c(DEV_NULL, &opts)?;
477+
let path = unsafe { CStr::from_ptr(DEV_NULL.as_ptr() as *const _) };
478+
let fd = File::open_c(&path, &opts)?;
478479
Ok((ChildStdio::Owned(fd.into_inner()), None))
479480
}
480481

std/src/sys/unix/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ impl Thread {
163163
#[cfg(target_os = "netbsd")]
164164
pub fn set_name(name: &CStr) {
165165
unsafe {
166+
let cname = CStr::from_bytes_with_nul_unchecked(b"%s\0".as_slice());
166167
let res = libc::pthread_setname_np(
167168
libc::pthread_self(),
168-
c"%s".as_ptr(),
169+
cname.as_ptr(),
169170
name.as_ptr() as *mut libc::c_void,
170171
);
171172
debug_assert_eq!(res, 0);

std/src/sys/windows/c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub unsafe fn NtWriteFile(
321321
// Functions that aren't available on every version of Windows that we support,
322322
// but we still use them and just provide some form of a fallback implementation.
323323
compat_fn_with_fallback! {
324-
pub static KERNEL32: &CStr = c"kernel32";
324+
pub static KERNEL32: &CStr = ansi_str!("kernel32");
325325

326326
// >= Win10 1607
327327
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
@@ -354,7 +354,7 @@ compat_fn_optional! {
354354
}
355355

356356
compat_fn_with_fallback! {
357-
pub static NTDLL: &CStr = c"ntdll";
357+
pub static NTDLL: &CStr = ansi_str!("ntdll");
358358

359359
pub fn NtCreateKeyedEvent(
360360
KeyedEventHandle: LPHANDLE,

std/src/sys/windows/compat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ macro_rules! compat_fn_optional {
228228
/// Load all needed functions from "api-ms-win-core-synch-l1-2-0".
229229
pub(super) fn load_synch_functions() {
230230
fn try_load() -> Option<()> {
231-
const MODULE_NAME: &CStr = c"api-ms-win-core-synch-l1-2-0";
232-
const WAIT_ON_ADDRESS: &CStr = c"WaitOnAddress";
233-
const WAKE_BY_ADDRESS_SINGLE: &CStr = c"WakeByAddressSingle";
231+
const MODULE_NAME: &CStr = ansi_str!("api-ms-win-core-synch-l1-2-0");
232+
const WAIT_ON_ADDRESS: &CStr = ansi_str!("WaitOnAddress");
233+
const WAKE_BY_ADDRESS_SINGLE: &CStr = ansi_str!("WakeByAddressSingle");
234234

235235
// Try loading the library and all the required functions.
236236
// If any step fails, then they all fail.

std/src/sys/windows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(missing_docs, nonstandard_style)]
22

3-
use crate::ffi::{OsStr, OsString};
3+
use crate::ffi::{CStr, OsStr, OsString};
44
use crate::io::ErrorKind;
55
use crate::mem::MaybeUninit;
66
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
@@ -51,7 +51,7 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {
5151

5252
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
5353
// exists, we have to call it ourselves.
54-
thread::Thread::set_name(&c"main");
54+
thread::Thread::set_name(&CStr::from_bytes_with_nul_unchecked(b"main\0"));
5555
}
5656

5757
// SAFETY: must be called only once during runtime cleanup.

0 commit comments

Comments
 (0)