Skip to content

Commit

Permalink
Remove LPVOID
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Jul 15, 2024
1 parent 68ac381 commit d3205de
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions std/src/sys/pal/windows/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extern "C" fn process_heap_init_and_alloc(
_heap: MaybeUninit<c::HANDLE>, // 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();
Expand All @@ -129,7 +129,7 @@ fn process_heap_alloc(
_heap: MaybeUninit<c::HANDLE>, // 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`.
Expand Down Expand Up @@ -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::<c_void>()) };
}

#[inline]
Expand All @@ -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::<c_void>(), new_size).cast::<u8>() }
} else {
// SAFETY: `realloc_fallback` is implemented using `dealloc` and `alloc`, which will
// correctly handle `ptr` and return a pointer satisfying the guarantees of `System`
Expand Down
8 changes: 3 additions & 5 deletions std/src/sys/pal/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -390,15 +388,15 @@ 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")
}
#[cfg(target_vendor = "win7")]
pub fn NtReleaseKeyedEvent(
EventHandle: HANDLE,
Key: LPVOID,
Key: *mut c_void,
Alertable: BOOLEAN,
Timeout: *mut c_longlong
) -> NTSTATUS {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions std/src/sys/pal/windows/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<usize> {
// Use "alertable I/O" to synchronize the pipe I/O.
Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn read_u16s(handle: c::HANDLE, buf: &mut [MaybeUninit<u16>]) -> io::Result<usiz
c::SetLastError(0);
c::ReadConsoleW(
handle,
buf.as_mut_ptr() as c::LPVOID,
buf.as_mut_ptr() as *mut core::ffi::c_void,
buf.len() as u32,
&mut amount,
&input_control,
Expand Down
9 changes: 5 additions & 4 deletions std/src/sys/sync/thread_parking/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use crate::sync::atomic::{
};
use crate::sys::{c, dur2timeout};
use crate::time::Duration;
use core::ffi::c_void;

pub struct Parker {
state: AtomicI8,
Expand Down Expand Up @@ -117,7 +118,7 @@ impl Parker {

loop {
// Wait for something to happen, assuming it's still set to PARKED.
c::WaitOnAddress(self.ptr(), &PARKED as *const _ as c::LPVOID, 1, c::INFINITE);
c::WaitOnAddress(self.ptr(), &PARKED as *const _ as *const c_void, 1, c::INFINITE);
// Change NOTIFIED=>EMPTY but leave PARKED alone.
if self.state.compare_exchange(NOTIFIED, EMPTY, Acquire, Acquire).is_ok() {
// Actually woken up by unpark().
Expand All @@ -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
Expand Down Expand Up @@ -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::<c_void>()
}
}

Expand Down
5 changes: 3 additions & 2 deletions std/src/sys/thread_local/guard/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))]
Expand Down

0 comments on commit d3205de

Please sign in to comment.