From d3205de3d536d7bf0708d3fd434f08bbd40eb15e Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 14 Jul 2024 07:19:57 +0000 Subject: [PATCH] Remove LPVOID --- std/src/sys/pal/windows/alloc.rs | 8 ++++---- std/src/sys/pal/windows/c.rs | 8 +++----- std/src/sys/pal/windows/pipe.rs | 4 ++-- std/src/sys/pal/windows/stdio.rs | 2 +- std/src/sys/sync/thread_parking/windows.rs | 9 +++++---- std/src/sys/thread_local/guard/windows.rs | 5 +++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/std/src/sys/pal/windows/alloc.rs b/std/src/sys/pal/windows/alloc.rs index c2fb0c2b87640..f85d29c00a9ae 100644 --- a/std/src/sys/pal/windows/alloc.rs +++ b/std/src/sys/pal/windows/alloc.rs @@ -115,7 +115,7 @@ extern "C" fn process_heap_init_and_alloc( _heap: MaybeUninit, // We pass this argument to match the ABI of `HeapAlloc` flags: c::DWORD, dwBytes: usize, -) -> c::LPVOID { +) -> *mut c_void { let heap = init_or_get_process_heap(); if core::intrinsics::unlikely(heap.is_null()) { return ptr::null_mut(); @@ -129,7 +129,7 @@ fn process_heap_alloc( _heap: MaybeUninit, // We pass this argument to match the ABI of `HeapAlloc`, flags: c::DWORD, dwBytes: usize, -) -> c::LPVOID { +) -> *mut c_void { let heap = HEAP.load(Ordering::Relaxed); if core::intrinsics::likely(!heap.is_null()) { // SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`. @@ -240,7 +240,7 @@ unsafe impl GlobalAlloc for System { // SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`, // `block` is a pointer to the start of an allocated block. - unsafe { HeapFree(heap, 0, block as c::LPVOID) }; + unsafe { HeapFree(heap, 0, block.cast::()) }; } #[inline] @@ -253,7 +253,7 @@ unsafe impl GlobalAlloc for System { // SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`, // `ptr` is a pointer to the start of an allocated block. // The returned pointer points to the start of an allocated block. - unsafe { HeapReAlloc(heap, 0, ptr as c::LPVOID, new_size) as *mut u8 } + unsafe { HeapReAlloc(heap, 0, ptr.cast::(), new_size).cast::() } } else { // SAFETY: `realloc_fallback` is implemented using `dealloc` and `alloc`, which will // correctly handle `ptr` and return a pointer satisfying the guarantees of `System` diff --git a/std/src/sys/pal/windows/c.rs b/std/src/sys/pal/windows/c.rs index 48d46296d98fb..e284804c2c8de 100644 --- a/std/src/sys/pal/windows/c.rs +++ b/std/src/sys/pal/windows/c.rs @@ -21,8 +21,6 @@ pub type DWORD = c_ulong; pub type WCHAR = u16; pub type ULONG = c_ulong; -pub type LPVOID = *mut c_void; - #[cfg(target_vendor = "win7")] pub type PSRWLOCK = *mut SRWLOCK; @@ -390,7 +388,7 @@ compat_fn_with_fallback! { pub fn NtCreateKeyedEvent( KeyedEventHandle: *mut HANDLE, DesiredAccess: DWORD, - ObjectAttributes: LPVOID, + ObjectAttributes: *mut c_void, Flags: ULONG ) -> NTSTATUS { panic!("keyed events not available") @@ -398,7 +396,7 @@ compat_fn_with_fallback! { #[cfg(target_vendor = "win7")] pub fn NtReleaseKeyedEvent( EventHandle: HANDLE, - Key: LPVOID, + Key: *mut c_void, Alertable: BOOLEAN, Timeout: *mut c_longlong ) -> NTSTATUS { @@ -407,7 +405,7 @@ compat_fn_with_fallback! { #[cfg(target_vendor = "win7")] pub fn NtWaitForKeyedEvent( EventHandle: HANDLE, - Key: LPVOID, + Key: *mut c_void, Alertable: BOOLEAN, Timeout: *mut c_longlong ) -> NTSTATUS { diff --git a/std/src/sys/pal/windows/pipe.rs b/std/src/sys/pal/windows/pipe.rs index 408653f538f68..031660335483e 100644 --- a/std/src/sys/pal/windows/pipe.rs +++ b/std/src/sys/pal/windows/pipe.rs @@ -225,7 +225,7 @@ fn random_number() -> usize { // Abstracts over `ReadFileEx` and `WriteFileEx` type AlertableIoFn = unsafe extern "system" fn( BorrowedHandle<'_>, - c::LPVOID, + *mut core::ffi::c_void, c::DWORD, *mut c::OVERLAPPED, c::LPOVERLAPPED_COMPLETION_ROUTINE, @@ -327,7 +327,7 @@ impl AnonPipe { unsafe fn alertable_io_internal( &self, io: AlertableIoFn, - buf: c::LPVOID, + buf: *mut core::ffi::c_void, len: c::DWORD, ) -> io::Result { // Use "alertable I/O" to synchronize the pipe I/O. diff --git a/std/src/sys/pal/windows/stdio.rs b/std/src/sys/pal/windows/stdio.rs index 995be689b4671..07686ab293339 100644 --- a/std/src/sys/pal/windows/stdio.rs +++ b/std/src/sys/pal/windows/stdio.rs @@ -355,7 +355,7 @@ fn read_u16s(handle: c::HANDLE, buf: &mut [MaybeUninit]) -> io::ResultEMPTY but leave PARKED alone. if self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Acquire).is_ok() { // Actually woken up by unpark(). @@ -144,7 +145,7 @@ impl Parker { } // Wait for something to happen, assuming it's still set to PARKED. - c::WaitOnAddress(self.ptr(), &PARKED as *const _ as c::LPVOID, 1, dur2timeout(timeout)); + c::WaitOnAddress(self.ptr(), &PARKED as *const _ as *const c_void, 1, dur2timeout(timeout)); // Set the state back to EMPTY (from either PARKED or NOTIFIED). // Note that we don't just write EMPTY, but use swap() to also // include an acquire-ordered read to synchronize with unpark()'s @@ -177,8 +178,8 @@ impl Parker { } } - fn ptr(&self) -> c::LPVOID { - core::ptr::addr_of!(self.state) as c::LPVOID + fn ptr(&self) -> *const c_void { + core::ptr::addr_of!(self.state).cast::() } } diff --git a/std/src/sys/thread_local/guard/windows.rs b/std/src/sys/thread_local/guard/windows.rs index 81797f55170d7..c35b717fe75df 100644 --- a/std/src/sys/thread_local/guard/windows.rs +++ b/std/src/sys/thread_local/guard/windows.rs @@ -65,6 +65,7 @@ use crate::ptr; use crate::sys::c; +use core::ffi::c_void; pub fn enable() { // When destructors are used, we don't want LLVM eliminating CALLBACK for any @@ -74,9 +75,9 @@ pub fn enable() { #[link_section = ".CRT$XLB"] #[cfg_attr(miri, used)] // Miri only considers explicitly `#[used]` statics for `lookup_link_section` -pub static CALLBACK: unsafe extern "system" fn(c::LPVOID, c::DWORD, c::LPVOID) = tls_callback; +pub static CALLBACK: unsafe extern "system" fn(*mut c_void, c::DWORD, *mut c_void) = tls_callback; -unsafe extern "system" fn tls_callback(_h: c::LPVOID, dw_reason: c::DWORD, _pv: c::LPVOID) { +unsafe extern "system" fn tls_callback(_h: *mut c_void, dw_reason: c::DWORD, _pv: *mut c_void) { // See comments above for what this is doing. Note that we don't need this // trickery on GNU windows, just on MSVC. #[cfg(all(target_env = "msvc", not(target_thread_local)))]