Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3394072

Browse files
arihant2mathcoolreader18
authored andcommitted
upgrade to windows-sys 0.59.0
1 parent 05cb8c0 commit 3394072

File tree

10 files changed

+56
-54
lines changed

10 files changed

+56
-54
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ thiserror = "2.0"
181181
thread_local = "1.1.8"
182182
unicode_names2 = "1.3.0"
183183
widestring = "1.1.0"
184-
windows-sys = "0.52.0"
184+
windows-sys = "0.59.0"
185185
wasm-bindgen = "0.2.100"
186186

187187
# Lints

common/src/fileutils.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub mod windows {
116116
let h = h?;
117117
// reset stat?
118118

119-
let file_type = unsafe { GetFileType(h) };
119+
let file_type = unsafe { GetFileType(h as _) };
120120
if file_type == FILE_TYPE_UNKNOWN {
121121
return Err(std::io::Error::last_os_error());
122122
}
@@ -138,10 +138,10 @@ pub mod windows {
138138
let mut basic_info: FILE_BASIC_INFO = unsafe { std::mem::zeroed() };
139139
let mut id_info: FILE_ID_INFO = unsafe { std::mem::zeroed() };
140140

141-
if unsafe { GetFileInformationByHandle(h, &mut info) } == 0
141+
if unsafe { GetFileInformationByHandle(h as _, &mut info) } == 0
142142
|| unsafe {
143143
GetFileInformationByHandleEx(
144-
h,
144+
h as _,
145145
FileBasicInfo,
146146
&mut basic_info as *mut _ as *mut _,
147147
std::mem::size_of_val(&basic_info) as u32,
@@ -153,7 +153,7 @@ pub mod windows {
153153

154154
let p_id_info = if unsafe {
155155
GetFileInformationByHandleEx(
156-
h,
156+
h as _,
157157
FileIdInfo,
158158
&mut id_info as *mut _ as *mut _,
159159
std::mem::size_of_val(&id_info) as u32,
@@ -320,7 +320,7 @@ pub mod windows {
320320
.get_or_init(|| {
321321
let library_name = OsString::from("api-ms-win-core-file-l2-1-4").to_wide_with_nul();
322322
let module = unsafe { LoadLibraryW(library_name.as_ptr()) };
323-
if module == 0 {
323+
if module == std::ptr::null_mut() {
324324
return None;
325325
}
326326
let name = CString::new("GetFileInformationByName").unwrap();

stdlib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ features = [
125125
"Win32_NetworkManagement_Ndis",
126126
"Win32_Security_Cryptography",
127127
"Win32_System_Environment",
128+
"Win32_System_IO"
128129
]
129130

130131
[target.'cfg(target_os = "macos")'.dependencies]

stdlib/src/overlapped.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ mod _overlapped {
2424
use windows_sys::Win32::{
2525
Foundation::{
2626
ERROR_IO_PENDING, ERROR_NETNAME_DELETED, ERROR_OPERATION_ABORTED, ERROR_PIPE_BUSY,
27-
ERROR_PORT_UNREACHABLE, ERROR_SEM_TIMEOUT, INVALID_HANDLE_VALUE,
27+
ERROR_PORT_UNREACHABLE, ERROR_SEM_TIMEOUT,
2828
},
2929
Networking::WinSock::{
3030
SO_UPDATE_ACCEPT_CONTEXT, SO_UPDATE_CONNECT_CONTEXT, TF_REUSE_SOCKET,
3131
},
3232
System::Threading::INFINITE,
3333
};
34+
#[pyattr(once)]
35+
fn INVALID_HANDLE_VALUE(_vm: &VirtualMachine) -> isize {
36+
windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE as isize
37+
}
3438
#[pyattr]
3539
const NULL: isize = 0;
3640

@@ -126,7 +130,7 @@ mod _overlapped {
126130

127131
fn mark_as_completed(ov: &mut OVERLAPPED) {
128132
ov.Internal = 0;
129-
if ov.hEvent != 0 {
133+
if ov.hEvent != std::ptr::null_mut() {
130134
unsafe { windows_sys::Win32::System::Threading::SetEvent(ov.hEvent) };
131135
}
132136
}
@@ -164,7 +168,7 @@ mod _overlapped {
164168

165169
fn WSARecv_inner(
166170
inner: &mut OverlappedInner,
167-
handle: HANDLE,
171+
handle: isize,
168172
buf: &[u8],
169173
mut flags: u32,
170174
vm: &VirtualMachine,
@@ -209,7 +213,7 @@ mod _overlapped {
209213
#[pymethod]
210214
fn WSARecv(
211215
zelf: &Py<Self>,
212-
handle: HANDLE,
216+
handle: isize,
213217
size: u32,
214218
flags: u32,
215219
vm: &VirtualMachine,
@@ -224,9 +228,9 @@ mod _overlapped {
224228

225229
let buf = vec![0u8; std::cmp::max(size, 1) as usize];
226230
let buf = vm.ctx.new_bytes(buf);
227-
inner.handle = handle;
231+
inner.handle = handle as _;
228232

229-
let r = Self::WSARecv_inner(&mut inner, handle, buf.as_bytes(), flags, vm);
233+
let r = Self::WSARecv_inner(&mut inner, handle as _, buf.as_bytes(), flags, vm);
230234
inner.data = OverlappedData::Read(buf);
231235
r
232236
}
@@ -256,30 +260,30 @@ mod _overlapped {
256260
}
257261

258262
impl Constructor for Overlapped {
259-
type Args = (HANDLE,);
263+
type Args = (isize,);
260264

261265
fn py_new(cls: PyTypeRef, (mut event,): Self::Args, vm: &VirtualMachine) -> PyResult {
262-
if event == INVALID_HANDLE_VALUE {
266+
if event as isize == INVALID_HANDLE_VALUE as isize {
263267
event = unsafe {
264268
windows_sys::Win32::System::Threading::CreateEventA(
265269
std::ptr::null(),
266270
Foundation::TRUE,
267271
Foundation::FALSE,
268272
std::ptr::null(),
269-
)
273+
) as isize
270274
};
271-
if event == NULL {
275+
if event as isize == NULL {
272276
return Err(errno_err(vm));
273277
}
274278
}
275279

276280
let mut overlapped: OVERLAPPED = unsafe { std::mem::zeroed() };
277281
if event != NULL {
278-
overlapped.hEvent = event;
282+
overlapped.hEvent = event as _;
279283
}
280284
let inner = OverlappedInner {
281285
overlapped,
282-
handle: NULL,
286+
handle: NULL as _,
283287
error: 0,
284288
data: OverlappedData::None,
285289
};
@@ -292,29 +296,29 @@ mod _overlapped {
292296

293297
#[pyfunction]
294298
fn CreateIoCompletionPort(
295-
handle: HANDLE,
296-
port: HANDLE,
299+
handle: isize,
300+
port: isize,
297301
key: usize,
298302
concurrency: u32,
299303
vm: &VirtualMachine,
300-
) -> PyResult<HANDLE> {
304+
) -> PyResult<isize> {
301305
let r = unsafe {
302-
windows_sys::Win32::System::IO::CreateIoCompletionPort(handle, port, key, concurrency)
306+
windows_sys::Win32::System::IO::CreateIoCompletionPort(handle as _, port as _, key, concurrency) as isize
303307
};
304-
if r == 0 {
308+
if r as usize == 0 {
305309
return Err(errno_err(vm));
306310
}
307311
Ok(r)
308312
}
309313

310314
#[pyfunction]
311-
fn GetQueuedCompletionStatus(port: HANDLE, msecs: u32, vm: &VirtualMachine) -> PyResult {
315+
fn GetQueuedCompletionStatus(port: isize, msecs: u32, vm: &VirtualMachine) -> PyResult {
312316
let mut bytes_transferred = 0;
313317
let mut completion_key = 0;
314318
let mut overlapped: *mut OVERLAPPED = std::ptr::null_mut();
315319
let ret = unsafe {
316320
windows_sys::Win32::System::IO::GetQueuedCompletionStatus(
317-
port,
321+
port as _,
318322
&mut bytes_transferred,
319323
&mut completion_key,
320324
&mut overlapped,

stdlib/src/socket.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ mod _socket {
3636
#[cfg(windows)]
3737
mod c {
3838
pub use windows_sys::Win32::NetworkManagement::IpHelper::{if_indextoname, if_nametoindex};
39-
40-
pub const INADDR_ANY: u32 = 0x00000000;
41-
pub const INADDR_LOOPBACK: u32 = 0x7f000001;
42-
pub const INADDR_BROADCAST: u32 = 0xffffffff;
43-
pub const INADDR_NONE: u32 = 0xffffffff;
39+
pub use windows_sys::Win32::Networking::WinSock::{INADDR_ANY, INADDR_LOOPBACK, INADDR_BROADCAST, INADDR_NONE};
4440

4541
pub use windows_sys::Win32::Networking::WinSock::{
4642
AF_APPLETALK, AF_DECnet, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME,
@@ -2135,7 +2131,7 @@ mod _socket {
21352131
#[cfg(all(unix, not(target_os = "redox")))]
21362132
type IfIndex = c::c_uint;
21372133
#[cfg(windows)]
2138-
type IfIndex = u32; // NET_IFINDEX but windows-sys 0.59 doesn't have it
2134+
type IfIndex = u32; // NET_IFINDEX but windows-sys 0.59 doesn't have it
21392135

21402136
#[cfg(not(target_os = "redox"))]
21412137
#[pyfunction]

vm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ features = [
144144
"Win32_System_SystemInformation",
145145
"Win32_System_SystemServices",
146146
"Win32_System_Threading",
147+
"Win32_System_WindowsProgramming",
147148
"Win32_UI_Shell",
148149
"Win32_UI_WindowsAndMessaging",
149150
]

vm/src/stdlib/nt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub(crate) mod module {
150150
}
151151

152152
let h = unsafe { Threading::OpenProcess(Threading::PROCESS_ALL_ACCESS, 0, pid) };
153-
if h == 0 {
153+
if h == std::ptr::null_mut() {
154154
return Err(errno_err(vm));
155155
}
156156
let ret = unsafe { Threading::TerminateProcess(h, sig) };
@@ -172,7 +172,7 @@ pub(crate) mod module {
172172
_ => return Err(vm.new_value_error("bad file descriptor".to_owned())),
173173
};
174174
let h = unsafe { Console::GetStdHandle(stdhandle) };
175-
if h == 0 {
175+
if h == std::ptr::null_mut() {
176176
return Err(vm.new_os_error("handle cannot be retrieved".to_owned()));
177177
}
178178
if h == INVALID_HANDLE_VALUE {

vm/src/stdlib/winapi.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod _winapi {
7979

8080
#[pyfunction]
8181
fn CloseHandle(handle: HANDLE) -> WindowsSysResult<BOOL> {
82-
WindowsSysResult(unsafe { windows_sys::Win32::Foundation::CloseHandle(handle.0) })
82+
WindowsSysResult(unsafe { windows_sys::Win32::Foundation::CloseHandle(handle.0 as _) })
8383
}
8484

8585
#[pyfunction]
@@ -99,8 +99,8 @@ mod _winapi {
9999
let mut read = std::mem::MaybeUninit::<isize>::uninit();
100100
let mut write = std::mem::MaybeUninit::<isize>::uninit();
101101
WindowsSysResult(windows_sys::Win32::System::Pipes::CreatePipe(
102-
read.as_mut_ptr(),
103-
write.as_mut_ptr(),
102+
read.as_mut_ptr() as _,
103+
write.as_mut_ptr() as _,
104104
std::ptr::null(),
105105
size,
106106
))
@@ -122,10 +122,10 @@ mod _winapi {
122122
let target = unsafe {
123123
let mut target = std::mem::MaybeUninit::<isize>::uninit();
124124
WindowsSysResult(windows_sys::Win32::Foundation::DuplicateHandle(
125-
src_process.0,
126-
src.0,
127-
target_process.0,
128-
target.as_mut_ptr(),
125+
src_process.0 as _,
126+
src.0 as _,
127+
target_process.0 as _,
128+
target.as_mut_ptr() as _,
129129
access,
130130
inherit,
131131
options.unwrap_or(0),
@@ -151,7 +151,7 @@ mod _winapi {
151151
h: HANDLE,
152152
vm: &VirtualMachine,
153153
) -> PyResult<windows_sys::Win32::Storage::FileSystem::FILE_TYPE> {
154-
let file_type = unsafe { windows_sys::Win32::Storage::FileSystem::GetFileType(h.0) };
154+
let file_type = unsafe { windows_sys::Win32::Storage::FileSystem::GetFileType(h.0 as _) };
155155
if file_type == 0 && unsafe { windows_sys::Win32::Foundation::GetLastError() } != 0 {
156156
Err(errno_err(vm))
157157
} else {
@@ -274,8 +274,8 @@ mod _winapi {
274274
};
275275

276276
Ok((
277-
HANDLE(procinfo.hProcess),
278-
HANDLE(procinfo.hThread),
277+
HANDLE(procinfo.hProcess as _),
278+
HANDLE(procinfo.hThread as _),
279279
procinfo.dwProcessId,
280280
procinfo.dwThreadId,
281281
))
@@ -286,13 +286,13 @@ mod _winapi {
286286
desired_access: u32,
287287
inherit_handle: bool,
288288
process_id: u32,
289-
) -> windows_sys::Win32::Foundation::HANDLE {
289+
) -> isize {
290290
unsafe {
291291
windows_sys::Win32::System::Threading::OpenProcess(
292292
desired_access,
293293
BOOL::from(inherit_handle),
294294
process_id,
295-
)
295+
) as _
296296
}
297297
}
298298

@@ -438,7 +438,7 @@ mod _winapi {
438438

439439
#[pyfunction]
440440
fn WaitForSingleObject(h: HANDLE, ms: u32, vm: &VirtualMachine) -> PyResult<u32> {
441-
let ret = unsafe { windows_sys::Win32::System::Threading::WaitForSingleObject(h.0, ms) };
441+
let ret = unsafe { windows_sys::Win32::System::Threading::WaitForSingleObject(h.0 as _, ms) };
442442
if ret == windows_sys::Win32::Foundation::WAIT_FAILED {
443443
Err(errno_err(vm))
444444
} else {
@@ -451,7 +451,7 @@ mod _winapi {
451451
unsafe {
452452
let mut ec = std::mem::MaybeUninit::uninit();
453453
WindowsSysResult(windows_sys::Win32::System::Threading::GetExitCodeProcess(
454-
h.0,
454+
h.0 as _,
455455
ec.as_mut_ptr(),
456456
))
457457
.to_pyresult(vm)?;
@@ -462,7 +462,7 @@ mod _winapi {
462462
#[pyfunction]
463463
fn TerminateProcess(h: HANDLE, exit_code: u32) -> WindowsSysResult<BOOL> {
464464
WindowsSysResult(unsafe {
465-
windows_sys::Win32::System::Threading::TerminateProcess(h.0, exit_code)
465+
windows_sys::Win32::System::Threading::TerminateProcess(h.0 as _, exit_code)
466466
})
467467
}
468468

@@ -507,11 +507,11 @@ mod _winapi {
507507
// if handle.is_invalid() {
508508
// return Err(errno_err(vm));
509509
// }
510-
Ok(handle)
510+
Ok(handle as _)
511511
}
512512

513513
#[pyfunction]
514514
fn ReleaseMutex(handle: isize) -> WindowsSysResult<BOOL> {
515-
WindowsSysResult(unsafe { windows_sys::Win32::System::Threading::ReleaseMutex(handle) })
515+
WindowsSysResult(unsafe { windows_sys::Win32::System::Threading::ReleaseMutex(handle as _) })
516516
}
517517
}

vm/src/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl WindowsSysResultValue for RAW_HANDLE {
2323
*self == INVALID_HANDLE_VALUE
2424
}
2525
fn into_ok(self) -> Self::Ok {
26-
HANDLE(self)
26+
HANDLE(self as _)
2727
}
2828
}
2929

0 commit comments

Comments
 (0)