Skip to content

Commit ef4d4a0

Browse files
committed
Auto merge of rust-lang#128195 - matthiaskrgr:rollup-195dfdf, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#126908 (Use Cow<'static, str> for InlineAsmTemplatePiece::String) - rust-lang#127999 (Inject arm32 shims into Windows metadata generation) - rust-lang#128137 (CStr: derive PartialEq, Eq; add test for Ord) - rust-lang#128185 (Fix a span error when parsing a wrong param of function.) - rust-lang#128187 (Fix 1.80.0 version in RELEASES.md) - rust-lang#128189 (Turn an unreachable code path into an ICE) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ea3a99f + 5b6c1e1 commit ef4d4a0

File tree

7 files changed

+47
-52
lines changed

7 files changed

+47
-52
lines changed

core/src/ffi/c_str.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use crate::str;
9494
/// ```
9595
///
9696
/// [str]: prim@str "str"
97-
#[derive(Hash)]
97+
#[derive(PartialEq, Eq, Hash)]
9898
#[stable(feature = "core_c_str", since = "1.64.0")]
9999
#[rustc_has_incoherent_inherent_impls]
100100
#[lang = "CStr"]
@@ -104,7 +104,6 @@ use crate::str;
104104
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
105105
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
106106
#[repr(transparent)]
107-
#[allow(clippy::derived_hash_with_manual_eq)]
108107
pub struct CStr {
109108
// FIXME: this should not be represented with a DST slice but rather with
110109
// just a raw `c_char` along with some form of marker to make
@@ -678,15 +677,9 @@ impl CStr {
678677
}
679678
}
680679

681-
#[stable(feature = "rust1", since = "1.0.0")]
682-
impl PartialEq for CStr {
683-
#[inline]
684-
fn eq(&self, other: &CStr) -> bool {
685-
self.to_bytes().eq(other.to_bytes())
686-
}
687-
}
688-
#[stable(feature = "rust1", since = "1.0.0")]
689-
impl Eq for CStr {}
680+
// `.to_bytes()` representations are compared instead of the inner `[c_char]`s,
681+
// because `c_char` is `i8` (not `u8`) on some platforms.
682+
// That is why this is implemented manually and not derived.
690683
#[stable(feature = "rust1", since = "1.0.0")]
691684
impl PartialOrd for CStr {
692685
#[inline]

core/tests/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod cstr;

core/tests/ffi/cstr.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use core::ffi::CStr;
2+
3+
#[test]
4+
fn compares_as_u8s() {
5+
let a: &CStr = c"Hello!"; // Starts with ascii
6+
let a_bytes: &[u8] = a.to_bytes();
7+
assert!((..0b1000_0000).contains(&a_bytes[0]));
8+
9+
let b: &CStr = c"こんにちは!"; // Starts with non ascii
10+
let b_bytes: &[u8] = b.to_bytes();
11+
assert!((0b1000_0000..).contains(&b_bytes[0]));
12+
13+
assert_eq!(Ord::cmp(a, b), Ord::cmp(a_bytes, b_bytes));
14+
assert_eq!(PartialOrd::partial_cmp(a, b), PartialOrd::partial_cmp(a_bytes, b_bytes));
15+
}

core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ mod clone;
132132
mod cmp;
133133
mod const_ptr;
134134
mod convert;
135+
mod ffi;
135136
mod fmt;
136137
mod future;
137138
mod hash;

std/src/sys/pal/windows/c.rs

-41
Original file line numberDiff line numberDiff line change
@@ -276,44 +276,3 @@ compat_fn_with_fallback! {
276276
Status as u32
277277
}
278278
}
279-
280-
// # Arm32 shim
281-
//
282-
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
283-
// However, Microsoft no longer supports thumbv7a so definitions for those targets
284-
// are not included in the win32 metadata. We work around that by defining them here.
285-
//
286-
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
287-
cfg_if::cfg_if! {
288-
if #[cfg(not(target_vendor = "uwp"))] {
289-
#[link(name = "kernel32")]
290-
extern "system" {
291-
pub fn AddVectoredExceptionHandler(
292-
first: u32,
293-
handler: PVECTORED_EXCEPTION_HANDLER,
294-
) -> *mut c_void;
295-
}
296-
pub type PVECTORED_EXCEPTION_HANDLER = Option<
297-
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
298-
>;
299-
#[repr(C)]
300-
pub struct EXCEPTION_POINTERS {
301-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
302-
pub ContextRecord: *mut CONTEXT,
303-
}
304-
#[cfg(target_arch = "arm")]
305-
pub enum CONTEXT {}
306-
}}
307-
// WSAStartup is only redefined here so that we can override WSADATA for Arm32
308-
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32);
309-
#[cfg(target_arch = "arm")]
310-
#[repr(C)]
311-
pub struct WSADATA {
312-
pub wVersion: u16,
313-
pub wHighVersion: u16,
314-
pub szDescription: [u8; 257],
315-
pub szSystemStatus: [u8; 129],
316-
pub iMaxSockets: u16,
317-
pub iMaxUdpDg: u16,
318-
pub lpVendorInfo: PSTR,
319-
}

std/src/sys/pal/windows/c/bindings.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ Windows.Win32.Networking.WinSock.WSARecv
21762176
Windows.Win32.Networking.WinSock.WSASend
21772177
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
21782178
Windows.Win32.Networking.WinSock.WSASocketW
2179+
Windows.Win32.Networking.WinSock.WSAStartup
21792180
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
21802181
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
21812182
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
@@ -2420,6 +2421,7 @@ Windows.Win32.System.Console.STD_HANDLE
24202421
Windows.Win32.System.Console.STD_INPUT_HANDLE
24212422
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
24222423
Windows.Win32.System.Console.WriteConsoleW
2424+
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
24232425
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
24242426
Windows.Win32.System.Diagnostics.Debug.CONTEXT
24252427
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD

std/src/sys/pal/windows/c/windows_sys.rs

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ windows_targets::link!("advapi32.dll" "system" fn OpenProcessToken(processhandle
55
windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN);
66
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockExclusive(srwlock : *mut SRWLOCK));
77
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockShared(srwlock : *mut SRWLOCK));
8+
windows_targets::link!("kernel32.dll" "system" fn AddVectoredExceptionHandler(first : u32, handler : PVECTORED_EXCEPTION_HANDLER) -> *mut core::ffi::c_void);
89
windows_targets::link!("kernel32.dll" "system" fn CancelIo(hfile : HANDLE) -> BOOL);
910
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL);
1011
windows_targets::link!("kernel32.dll" "system" fn CompareStringOrdinal(lpstring1 : PCWSTR, cchcount1 : i32, lpstring2 : PCWSTR, cchcount2 : i32, bignorecase : BOOL) -> COMPARESTRING_RESULT);
@@ -114,6 +115,7 @@ windows_targets::link!("ws2_32.dll" "system" fn WSAGetLastError() -> WSA_ERROR);
114115
windows_targets::link!("ws2_32.dll" "system" fn WSARecv(s : SOCKET, lpbuffers : *const WSABUF, dwbuffercount : u32, lpnumberofbytesrecvd : *mut u32, lpflags : *mut u32, lpoverlapped : *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> i32);
115116
windows_targets::link!("ws2_32.dll" "system" fn WSASend(s : SOCKET, lpbuffers : *const WSABUF, dwbuffercount : u32, lpnumberofbytessent : *mut u32, dwflags : u32, lpoverlapped : *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> i32);
116117
windows_targets::link!("ws2_32.dll" "system" fn WSASocketW(af : i32, r#type : i32, protocol : i32, lpprotocolinfo : *const WSAPROTOCOL_INFOW, g : u32, dwflags : u32) -> SOCKET);
118+
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested : u16, lpwsadata : *mut WSADATA) -> i32);
117119
windows_targets::link!("ws2_32.dll" "system" fn accept(s : SOCKET, addr : *mut SOCKADDR, addrlen : *mut i32) -> SOCKET);
118120
windows_targets::link!("ws2_32.dll" "system" fn bind(s : SOCKET, name : *const SOCKADDR, namelen : i32) -> i32);
119121
windows_targets::link!("ws2_32.dll" "system" fn closesocket(s : SOCKET) -> i32);
@@ -2284,6 +2286,12 @@ pub type EXCEPTION_DISPOSITION = i32;
22842286
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
22852287
#[repr(C)]
22862288
#[derive(Clone, Copy)]
2289+
pub struct EXCEPTION_POINTERS {
2290+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
2291+
pub ContextRecord: *mut CONTEXT,
2292+
}
2293+
#[repr(C)]
2294+
#[derive(Clone, Copy)]
22872295
pub struct EXCEPTION_RECORD {
22882296
pub ExceptionCode: NTSTATUS,
22892297
pub ExceptionFlags: u32,
@@ -2860,6 +2868,8 @@ pub type PTIMERAPCROUTINE = Option<
28602868
dwtimerhighvalue: u32,
28612869
),
28622870
>;
2871+
pub type PVECTORED_EXCEPTION_HANDLER =
2872+
Option<unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32>;
28632873
pub type PWSTR = *mut u16;
28642874
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
28652875
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
@@ -3292,5 +3302,19 @@ pub struct XSAVE_FORMAT {
32923302
pub XmmRegisters: [M128A; 8],
32933303
pub Reserved4: [u8; 224],
32943304
}
3305+
3306+
#[cfg(target_arch = "arm")]
3307+
#[repr(C)]
3308+
pub struct WSADATA {
3309+
pub wVersion: u16,
3310+
pub wHighVersion: u16,
3311+
pub szDescription: [u8; 257],
3312+
pub szSystemStatus: [u8; 129],
3313+
pub iMaxSockets: u16,
3314+
pub iMaxUdpDg: u16,
3315+
pub lpVendorInfo: PSTR,
3316+
}
3317+
#[cfg(target_arch = "arm")]
3318+
pub enum CONTEXT {}
32953319
// ignore-tidy-filelength
32963320
use super::windows_targets;

0 commit comments

Comments
 (0)