Auto merge of #128195 - matthiaskrgr:rollup-195dfdf, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #126908 (Use Cow<'static, str> for InlineAsmTemplatePiece::String) - #127999 (Inject arm32 shims into Windows metadata generation) - #128137 (CStr: derive PartialEq, Eq; add test for Ord) - #128185 (Fix a span error when parsing a wrong param of function.) - #128187 (Fix 1.80.0 version in RELEASES.md) - #128189 (Turn an unreachable code path into an ICE) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
aa877bc71c
17 changed files with 142 additions and 92 deletions
|
@ -94,7 +94,7 @@ use crate::str;
|
|||
/// ```
|
||||
///
|
||||
/// [str]: prim@str "str"
|
||||
#[derive(Hash)]
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
#[stable(feature = "core_c_str", since = "1.64.0")]
|
||||
#[rustc_has_incoherent_inherent_impls]
|
||||
#[lang = "CStr"]
|
||||
|
@ -104,7 +104,6 @@ use crate::str;
|
|||
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
|
||||
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
|
||||
#[repr(transparent)]
|
||||
#[allow(clippy::derived_hash_with_manual_eq)]
|
||||
pub struct CStr {
|
||||
// FIXME: this should not be represented with a DST slice but rather with
|
||||
// just a raw `c_char` along with some form of marker to make
|
||||
|
@ -678,15 +677,9 @@ impl CStr {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialEq for CStr {
|
||||
#[inline]
|
||||
fn eq(&self, other: &CStr) -> bool {
|
||||
self.to_bytes().eq(other.to_bytes())
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Eq for CStr {}
|
||||
// `.to_bytes()` representations are compared instead of the inner `[c_char]`s,
|
||||
// because `c_char` is `i8` (not `u8`) on some platforms.
|
||||
// That is why this is implemented manually and not derived.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl PartialOrd for CStr {
|
||||
#[inline]
|
||||
|
|
1
library/core/tests/ffi.rs
Normal file
1
library/core/tests/ffi.rs
Normal file
|
@ -0,0 +1 @@
|
|||
mod cstr;
|
15
library/core/tests/ffi/cstr.rs
Normal file
15
library/core/tests/ffi/cstr.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use core::ffi::CStr;
|
||||
|
||||
#[test]
|
||||
fn compares_as_u8s() {
|
||||
let a: &CStr = c"Hello!"; // Starts with ascii
|
||||
let a_bytes: &[u8] = a.to_bytes();
|
||||
assert!((..0b1000_0000).contains(&a_bytes[0]));
|
||||
|
||||
let b: &CStr = c"こんにちは!"; // Starts with non ascii
|
||||
let b_bytes: &[u8] = b.to_bytes();
|
||||
assert!((0b1000_0000..).contains(&b_bytes[0]));
|
||||
|
||||
assert_eq!(Ord::cmp(a, b), Ord::cmp(a_bytes, b_bytes));
|
||||
assert_eq!(PartialOrd::partial_cmp(a, b), PartialOrd::partial_cmp(a_bytes, b_bytes));
|
||||
}
|
|
@ -132,6 +132,7 @@ mod clone;
|
|||
mod cmp;
|
||||
mod const_ptr;
|
||||
mod convert;
|
||||
mod ffi;
|
||||
mod fmt;
|
||||
mod future;
|
||||
mod hash;
|
||||
|
|
|
@ -276,44 +276,3 @@ compat_fn_with_fallback! {
|
|||
Status as u32
|
||||
}
|
||||
}
|
||||
|
||||
// # Arm32 shim
|
||||
//
|
||||
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
|
||||
// However, Microsoft no longer supports thumbv7a so definitions for those targets
|
||||
// are not included in the win32 metadata. We work around that by defining them here.
|
||||
//
|
||||
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(not(target_vendor = "uwp"))] {
|
||||
#[link(name = "kernel32")]
|
||||
extern "system" {
|
||||
pub fn AddVectoredExceptionHandler(
|
||||
first: u32,
|
||||
handler: PVECTORED_EXCEPTION_HANDLER,
|
||||
) -> *mut c_void;
|
||||
}
|
||||
pub type PVECTORED_EXCEPTION_HANDLER = Option<
|
||||
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
|
||||
>;
|
||||
#[repr(C)]
|
||||
pub struct EXCEPTION_POINTERS {
|
||||
pub ExceptionRecord: *mut EXCEPTION_RECORD,
|
||||
pub ContextRecord: *mut CONTEXT,
|
||||
}
|
||||
#[cfg(target_arch = "arm")]
|
||||
pub enum CONTEXT {}
|
||||
}}
|
||||
// WSAStartup is only redefined here so that we can override WSADATA for Arm32
|
||||
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32);
|
||||
#[cfg(target_arch = "arm")]
|
||||
#[repr(C)]
|
||||
pub struct WSADATA {
|
||||
pub wVersion: u16,
|
||||
pub wHighVersion: u16,
|
||||
pub szDescription: [u8; 257],
|
||||
pub szSystemStatus: [u8; 129],
|
||||
pub iMaxSockets: u16,
|
||||
pub iMaxUdpDg: u16,
|
||||
pub lpVendorInfo: PSTR,
|
||||
}
|
||||
|
|
|
@ -2176,6 +2176,7 @@ Windows.Win32.Networking.WinSock.WSARecv
|
|||
Windows.Win32.Networking.WinSock.WSASend
|
||||
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
|
||||
Windows.Win32.Networking.WinSock.WSASocketW
|
||||
Windows.Win32.Networking.WinSock.WSAStartup
|
||||
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
|
||||
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
|
||||
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
|
||||
|
@ -2420,6 +2421,7 @@ Windows.Win32.System.Console.STD_HANDLE
|
|||
Windows.Win32.System.Console.STD_INPUT_HANDLE
|
||||
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
|
||||
Windows.Win32.System.Console.WriteConsoleW
|
||||
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
|
||||
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
|
||||
Windows.Win32.System.Diagnostics.Debug.CONTEXT
|
||||
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD
|
||||
|
|
|
@ -5,6 +5,7 @@ windows_targets::link!("advapi32.dll" "system" fn OpenProcessToken(processhandle
|
|||
windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN);
|
||||
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockExclusive(srwlock : *mut SRWLOCK));
|
||||
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockShared(srwlock : *mut SRWLOCK));
|
||||
windows_targets::link!("kernel32.dll" "system" fn AddVectoredExceptionHandler(first : u32, handler : PVECTORED_EXCEPTION_HANDLER) -> *mut core::ffi::c_void);
|
||||
windows_targets::link!("kernel32.dll" "system" fn CancelIo(hfile : HANDLE) -> BOOL);
|
||||
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL);
|
||||
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);
|
|||
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);
|
||||
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);
|
||||
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);
|
||||
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested : u16, lpwsadata : *mut WSADATA) -> i32);
|
||||
windows_targets::link!("ws2_32.dll" "system" fn accept(s : SOCKET, addr : *mut SOCKADDR, addrlen : *mut i32) -> SOCKET);
|
||||
windows_targets::link!("ws2_32.dll" "system" fn bind(s : SOCKET, name : *const SOCKADDR, namelen : i32) -> i32);
|
||||
windows_targets::link!("ws2_32.dll" "system" fn closesocket(s : SOCKET) -> i32);
|
||||
|
@ -2284,6 +2286,12 @@ pub type EXCEPTION_DISPOSITION = i32;
|
|||
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct EXCEPTION_POINTERS {
|
||||
pub ExceptionRecord: *mut EXCEPTION_RECORD,
|
||||
pub ContextRecord: *mut CONTEXT,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct EXCEPTION_RECORD {
|
||||
pub ExceptionCode: NTSTATUS,
|
||||
pub ExceptionFlags: u32,
|
||||
|
@ -2860,6 +2868,8 @@ pub type PTIMERAPCROUTINE = Option<
|
|||
dwtimerhighvalue: u32,
|
||||
),
|
||||
>;
|
||||
pub type PVECTORED_EXCEPTION_HANDLER =
|
||||
Option<unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32>;
|
||||
pub type PWSTR = *mut u16;
|
||||
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
|
||||
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
|
||||
|
@ -3292,5 +3302,19 @@ pub struct XSAVE_FORMAT {
|
|||
pub XmmRegisters: [M128A; 8],
|
||||
pub Reserved4: [u8; 224],
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "arm")]
|
||||
#[repr(C)]
|
||||
pub struct WSADATA {
|
||||
pub wVersion: u16,
|
||||
pub wHighVersion: u16,
|
||||
pub szDescription: [u8; 257],
|
||||
pub szSystemStatus: [u8; 129],
|
||||
pub iMaxSockets: u16,
|
||||
pub iMaxUdpDg: u16,
|
||||
pub lpVendorInfo: PSTR,
|
||||
}
|
||||
#[cfg(target_arch = "arm")]
|
||||
pub enum CONTEXT {}
|
||||
// ignore-tidy-filelength
|
||||
use super::windows_targets;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue