Skip to content

Commit 05b6f7b

Browse files
authored
Unrolled build for rust-lang#127712
Rollup merge of rust-lang#127712 - ChrisDenton:raw-types, r=workingjubilee Windows: Remove some unnecessary type aliases Back in the olden days, C did not have fixed-width types so these type aliases were at least potentially useful. Nowadays, and especially in Rust, we don't need the aliases and they don't help with anything. Notably the windows bindings we use also don't bother with the aliases. And even when we have used aliases they're often only used once then forgotten about. The only one that gives me pause is `DWORD` because it's used a fair bit. But it's still used inconsistently and we implicitly assume it's a `u32` anyway (e.g. `as` casting from an `i32`).
2 parents adeb79d + 816d90a commit 05b6f7b

File tree

21 files changed

+167
-201
lines changed

21 files changed

+167
-201
lines changed

library/std/src/process/tests.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -385,29 +385,25 @@ fn test_interior_nul_in_env_value_is_error() {
385385
#[cfg(windows)]
386386
fn test_creation_flags() {
387387
use crate::os::windows::process::CommandExt;
388-
use crate::sys::c::{BOOL, DWORD, INFINITE};
388+
use crate::sys::c::{BOOL, INFINITE};
389389
#[repr(C)]
390390
struct DEBUG_EVENT {
391-
pub event_code: DWORD,
392-
pub process_id: DWORD,
393-
pub thread_id: DWORD,
391+
pub event_code: u32,
392+
pub process_id: u32,
393+
pub thread_id: u32,
394394
// This is a union in the real struct, but we don't
395395
// need this data for the purposes of this test.
396396
pub _junk: [u8; 164],
397397
}
398398

399399
extern "system" {
400-
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: DWORD) -> BOOL;
401-
fn ContinueDebugEvent(
402-
dwProcessId: DWORD,
403-
dwThreadId: DWORD,
404-
dwContinueStatus: DWORD,
405-
) -> BOOL;
400+
fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: u32) -> BOOL;
401+
fn ContinueDebugEvent(dwProcessId: u32, dwThreadId: u32, dwContinueStatus: u32) -> BOOL;
406402
}
407403

408-
const DEBUG_PROCESS: DWORD = 1;
409-
const EXIT_PROCESS_DEBUG_EVENT: DWORD = 5;
410-
const DBG_EXCEPTION_NOT_HANDLED: DWORD = 0x80010001;
404+
const DEBUG_PROCESS: u32 = 1;
405+
const EXIT_PROCESS_DEBUG_EVENT: u32 = 5;
406+
const DBG_EXCEPTION_NOT_HANDLED: u32 = 0x80010001;
411407

412408
let mut child =
413409
Command::new("cmd").creation_flags(DEBUG_PROCESS).stdin(Stdio::piped()).spawn().unwrap();

library/std/src/sys/pal/windows/alloc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod tests;
1515
// See https://docs.microsoft.com/windows/win32/api/heapapi/
1616

1717
// Flag to indicate that the memory returned by `HeapAlloc` should be zeroed.
18-
const HEAP_ZERO_MEMORY: c::DWORD = 0x00000008;
18+
const HEAP_ZERO_MEMORY: u32 = 0x00000008;
1919

2020
// Get a handle to the default heap of the current process, or null if the operation fails.
2121
//
@@ -113,9 +113,9 @@ fn init_or_get_process_heap() -> c::HANDLE {
113113
#[cold]
114114
extern "C" fn process_heap_init_and_alloc(
115115
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`
116-
flags: c::DWORD,
117-
dwBytes: c::SIZE_T,
118-
) -> c::LPVOID {
116+
flags: u32,
117+
dwBytes: usize,
118+
) -> *mut c_void {
119119
let heap = init_or_get_process_heap();
120120
if core::intrinsics::unlikely(heap.is_null()) {
121121
return ptr::null_mut();
@@ -127,9 +127,9 @@ extern "C" fn process_heap_init_and_alloc(
127127
#[inline(never)]
128128
fn process_heap_alloc(
129129
_heap: MaybeUninit<c::HANDLE>, // We pass this argument to match the ABI of `HeapAlloc`,
130-
flags: c::DWORD,
131-
dwBytes: c::SIZE_T,
132-
) -> c::LPVOID {
130+
flags: u32,
131+
dwBytes: usize,
132+
) -> *mut c_void {
133133
let heap = HEAP.load(Ordering::Relaxed);
134134
if core::intrinsics::likely(!heap.is_null()) {
135135
// SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`.
@@ -240,7 +240,7 @@ unsafe impl GlobalAlloc for System {
240240

241241
// SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`,
242242
// `block` is a pointer to the start of an allocated block.
243-
unsafe { HeapFree(heap, 0, block as c::LPVOID) };
243+
unsafe { HeapFree(heap, 0, block.cast::<c_void>()) };
244244
}
245245

246246
#[inline]
@@ -253,7 +253,7 @@ unsafe impl GlobalAlloc for System {
253253
// SAFETY: `heap` is a non-null handle returned by `GetProcessHeap`,
254254
// `ptr` is a pointer to the start of an allocated block.
255255
// The returned pointer points to the start of an allocated block.
256-
unsafe { HeapReAlloc(heap, 0, ptr as c::LPVOID, new_size) as *mut u8 }
256+
unsafe { HeapReAlloc(heap, 0, ptr.cast::<c_void>(), new_size).cast::<u8>() }
257257
} else {
258258
// SAFETY: `realloc_fallback` is implemented using `dealloc` and `alloc`, which will
259259
// correctly handle `ptr` and return a pointer satisfying the guarantees of `System`

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

+28-50
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
use crate::ffi::CStr;
99
use crate::mem;
10-
use crate::num::NonZero;
11-
pub use crate::os::raw::c_int;
12-
use crate::os::raw::{c_char, c_long, c_longlong, c_uint, c_ulong, c_ushort, c_void};
10+
use crate::os::raw::{c_char, c_int, c_uint, c_ulong, c_ushort, c_void};
1311
use crate::os::windows::io::{AsRawHandle, BorrowedHandle};
1412
use crate::ptr;
1513

@@ -18,30 +16,10 @@ pub(super) mod windows_targets;
1816
mod windows_sys;
1917
pub use windows_sys::*;
2018

21-
pub type DWORD = c_ulong;
22-
pub type NonZeroDWORD = NonZero<c_ulong>;
23-
pub type LARGE_INTEGER = c_longlong;
24-
#[cfg_attr(target_vendor = "uwp", allow(unused))]
25-
pub type LONG = c_long;
26-
pub type UINT = c_uint;
2719
pub type WCHAR = u16;
28-
pub type USHORT = c_ushort;
29-
pub type SIZE_T = usize;
30-
pub type CHAR = c_char;
31-
pub type ULONG = c_ulong;
32-
33-
pub type LPCVOID = *const c_void;
34-
pub type LPOVERLAPPED = *mut OVERLAPPED;
35-
pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
36-
pub type LPVOID = *mut c_void;
37-
pub type LPWCH = *mut WCHAR;
38-
pub type LPWSTR = *mut WCHAR;
39-
40-
#[cfg(target_vendor = "win7")]
41-
pub type PSRWLOCK = *mut SRWLOCK;
4220

4321
pub type socklen_t = c_int;
44-
pub type ADDRESS_FAMILY = USHORT;
22+
pub type ADDRESS_FAMILY = c_ushort;
4523
pub use FD_SET as fd_set;
4624
pub use LINGER as linger;
4725
pub use TIMEVAL as timeval;
@@ -151,25 +129,25 @@ pub struct MOUNT_POINT_REPARSE_BUFFER {
151129
#[repr(C)]
152130
pub struct SOCKADDR_STORAGE_LH {
153131
pub ss_family: ADDRESS_FAMILY,
154-
pub __ss_pad1: [CHAR; 6],
132+
pub __ss_pad1: [c_char; 6],
155133
pub __ss_align: i64,
156-
pub __ss_pad2: [CHAR; 112],
134+
pub __ss_pad2: [c_char; 112],
157135
}
158136

159137
#[repr(C)]
160138
#[derive(Copy, Clone)]
161139
pub struct sockaddr_in {
162140
pub sin_family: ADDRESS_FAMILY,
163-
pub sin_port: USHORT,
141+
pub sin_port: c_ushort,
164142
pub sin_addr: in_addr,
165-
pub sin_zero: [CHAR; 8],
143+
pub sin_zero: [c_char; 8],
166144
}
167145

168146
#[repr(C)]
169147
#[derive(Copy, Clone)]
170148
pub struct sockaddr_in6 {
171149
pub sin6_family: ADDRESS_FAMILY,
172-
pub sin6_port: USHORT,
150+
pub sin6_port: c_ushort,
173151
pub sin6_flowinfo: c_ulong,
174152
pub sin6_addr: in6_addr,
175153
pub sin6_scope_id: c_ulong,
@@ -271,9 +249,9 @@ pub unsafe fn NtReadFile(
271249
apccontext: *mut c_void,
272250
iostatusblock: &mut IO_STATUS_BLOCK,
273251
buffer: *mut crate::mem::MaybeUninit<u8>,
274-
length: ULONG,
275-
byteoffset: Option<&LARGE_INTEGER>,
276-
key: Option<&ULONG>,
252+
length: u32,
253+
byteoffset: Option<&i64>,
254+
key: Option<&u32>,
277255
) -> NTSTATUS {
278256
windows_sys::NtReadFile(
279257
filehandle.as_raw_handle(),
@@ -294,9 +272,9 @@ pub unsafe fn NtWriteFile(
294272
apccontext: *mut c_void,
295273
iostatusblock: &mut IO_STATUS_BLOCK,
296274
buffer: *const u8,
297-
length: ULONG,
298-
byteoffset: Option<&LARGE_INTEGER>,
299-
key: Option<&ULONG>,
275+
length: u32,
276+
byteoffset: Option<&i64>,
277+
key: Option<&u32>,
300278
) -> NTSTATUS {
301279
windows_sys::NtWriteFile(
302280
filehandle.as_raw_handle(),
@@ -336,13 +314,13 @@ compat_fn_with_fallback! {
336314
// >= Win10 1607
337315
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription
338316
pub fn SetThreadDescription(hthread: HANDLE, lpthreaddescription: PCWSTR) -> HRESULT {
339-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
317+
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL
340318
}
341319

342320
// >= Win10 1607
343321
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreaddescription
344322
pub fn GetThreadDescription(hthread: HANDLE, lpthreaddescription: *mut PWSTR) -> HRESULT {
345-
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); E_NOTIMPL
323+
SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); E_NOTIMPL
346324
}
347325

348326
// >= Win8 / Server 2012
@@ -403,27 +381,27 @@ compat_fn_with_fallback! {
403381
#[cfg(target_vendor = "win7")]
404382
pub fn NtCreateKeyedEvent(
405383
KeyedEventHandle: *mut HANDLE,
406-
DesiredAccess: DWORD,
407-
ObjectAttributes: LPVOID,
408-
Flags: ULONG
384+
DesiredAccess: u32,
385+
ObjectAttributes: *mut c_void,
386+
Flags: u32
409387
) -> NTSTATUS {
410388
panic!("keyed events not available")
411389
}
412390
#[cfg(target_vendor = "win7")]
413391
pub fn NtReleaseKeyedEvent(
414392
EventHandle: HANDLE,
415-
Key: LPVOID,
393+
Key: *const c_void,
416394
Alertable: BOOLEAN,
417-
Timeout: *mut c_longlong
395+
Timeout: *mut i64
418396
) -> NTSTATUS {
419397
panic!("keyed events not available")
420398
}
421399
#[cfg(target_vendor = "win7")]
422400
pub fn NtWaitForKeyedEvent(
423401
EventHandle: HANDLE,
424-
Key: LPVOID,
402+
Key: *const c_void,
425403
Alertable: BOOLEAN,
426-
Timeout: *mut c_longlong
404+
Timeout: *mut i64
427405
) -> NTSTATUS {
428406
panic!("keyed events not available")
429407
}
@@ -453,9 +431,9 @@ compat_fn_with_fallback! {
453431
apccontext: *mut c_void,
454432
iostatusblock: &mut IO_STATUS_BLOCK,
455433
buffer: *mut crate::mem::MaybeUninit<u8>,
456-
length: ULONG,
457-
byteoffset: Option<&LARGE_INTEGER>,
458-
key: Option<&ULONG>
434+
length: u32,
435+
byteoffset: Option<&i64>,
436+
key: Option<&u32>
459437
) -> NTSTATUS {
460438
STATUS_NOT_IMPLEMENTED
461439
}
@@ -467,9 +445,9 @@ compat_fn_with_fallback! {
467445
apccontext: *mut c_void,
468446
iostatusblock: &mut IO_STATUS_BLOCK,
469447
buffer: *const u8,
470-
length: ULONG,
471-
byteoffset: Option<&LARGE_INTEGER>,
472-
key: Option<&ULONG>
448+
length: u32,
449+
byteoffset: Option<&i64>,
450+
key: Option<&u32>
473451
) -> NTSTATUS {
474452
STATUS_NOT_IMPLEMENTED
475453
}

0 commit comments

Comments
 (0)