Skip to content

Commit ee128ea

Browse files
committed
replace errorhandling to windows-sys
1 parent 6df9732 commit ee128ea

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

vm/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ features = [
128128
"Win32_Security",
129129
"Win32_Storage_FileSystem",
130130
"Win32_System_Console",
131+
"Win32_System_Diagnostics_Debug",
131132
"Win32_System_LibraryLoader",
132133
"Win32_System_Memory",
133134
"Win32_System_Pipes",
@@ -142,8 +143,8 @@ features = [
142143
version = "0.3.9"
143144
features = [
144145
"winsock2", "handleapi", "std", "winbase",
145-
"winnt", "errhandlingapi",
146-
"impl-default", "vcruntime",
146+
"winnt",
147+
"impl-default",
147148
]
148149

149150
[target.'cfg(target_arch = "wasm32")'.dependencies]

vm/src/stdlib/msvcrt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ mod msvcrt {
99
PyRef, PyResult, VirtualMachine,
1010
};
1111
use itertools::Itertools;
12-
use winapi::{
13-
shared::minwindef::UINT,
14-
um::{handleapi::INVALID_HANDLE_VALUE, winnt::HANDLE},
12+
use windows_sys::Win32::{
13+
Foundation::{HANDLE, INVALID_HANDLE_VALUE},
14+
System::Diagnostics::Debug,
1515
};
1616

1717
#[pyattr]
@@ -111,7 +111,7 @@ mod msvcrt {
111111

112112
#[allow(non_snake_case)]
113113
#[pyfunction]
114-
fn SetErrorMode(mode: UINT, _: &VirtualMachine) -> UINT {
115-
unsafe { suppress_iph!(winapi::um::errhandlingapi::SetErrorMode(mode)) }
114+
fn SetErrorMode(mode: Debug::THREAD_ERROR_MODE, _: &VirtualMachine) -> u32 {
115+
unsafe { suppress_iph!(Debug::SetErrorMode(mode)) }
116116
}
117117
}

vm/src/stdlib/nt.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ pub(crate) mod module {
2323
},
2424
PyResult, TryFromObject, VirtualMachine,
2525
};
26+
use libc::intptr_t;
2627
use std::{
2728
env, fs, io,
2829
mem::MaybeUninit,
2930
os::windows::ffi::{OsStrExt, OsStringExt},
3031
};
31-
use winapi::{um, vc::vcruntime::intptr_t};
32+
use winapi::um;
3233
use windows_sys::Win32::{
3334
Foundation::{CloseHandle, INVALID_HANDLE_VALUE},
35+
Storage::FileSystem,
3436
System::{Console, Threading},
3537
};
3638

@@ -39,9 +41,9 @@ pub(crate) mod module {
3941

4042
#[pyfunction]
4143
pub(super) fn access(path: OsPath, mode: u8, vm: &VirtualMachine) -> PyResult<bool> {
42-
use um::{fileapi, winnt};
43-
let attr = unsafe { fileapi::GetFileAttributesW(path.to_widecstring(vm)?.as_ptr()) };
44-
Ok(attr != fileapi::INVALID_FILE_ATTRIBUTES
44+
use um::winnt;
45+
let attr = unsafe { FileSystem::GetFileAttributesW(path.to_widecstring(vm)?.as_ptr()) };
46+
Ok(attr != FileSystem::INVALID_FILE_ATTRIBUTES
4547
&& (mode & 2 == 0
4648
|| attr & winnt::FILE_ATTRIBUTE_READONLY == 0
4749
|| attr & winnt::FILE_ATTRIBUTE_DIRECTORY != 0))
@@ -252,7 +254,7 @@ pub(crate) mod module {
252254
let wpath = path.to_widecstring(vm)?;
253255
let mut buffer = vec![0u16; winapi::shared::minwindef::MAX_PATH];
254256
let ret = unsafe {
255-
um::fileapi::GetFullPathNameW(
257+
FileSystem::GetFullPathNameW(
256258
wpath.as_ptr(),
257259
buffer.len() as _,
258260
buffer.as_mut_ptr(),
@@ -265,7 +267,7 @@ pub(crate) mod module {
265267
if ret as usize > buffer.len() {
266268
buffer.resize(ret as usize, 0);
267269
let ret = unsafe {
268-
um::fileapi::GetFullPathNameW(
270+
FileSystem::GetFullPathNameW(
269271
wpath.as_ptr(),
270272
buffer.len() as _,
271273
buffer.as_mut_ptr(),
@@ -286,7 +288,7 @@ pub(crate) mod module {
286288
let buflen = std::cmp::max(wide.len(), winapi::shared::minwindef::MAX_PATH);
287289
let mut buffer = vec![0u16; buflen];
288290
let ret = unsafe {
289-
um::fileapi::GetVolumePathNameW(wide.as_ptr(), buffer.as_mut_ptr(), buflen as _)
291+
FileSystem::GetVolumePathNameW(wide.as_ptr(), buffer.as_mut_ptr(), buflen as _)
290292
};
291293
if ret == 0 {
292294
return Err(errno_err(vm));
@@ -335,17 +337,17 @@ pub(crate) mod module {
335337

336338
#[pyfunction]
337339
fn _getdiskusage(path: OsPath, vm: &VirtualMachine) -> PyResult<(u64, u64)> {
338-
use um::fileapi::GetDiskFreeSpaceExW;
339-
use winapi::shared::{ntdef::ULARGE_INTEGER, winerror};
340+
use winapi::shared::winerror;
341+
use FileSystem::GetDiskFreeSpaceExW;
340342

341343
let wpath = path.to_widecstring(vm)?;
342-
let mut _free_to_me = ULARGE_INTEGER::default();
343-
let mut total = ULARGE_INTEGER::default();
344-
let mut free = ULARGE_INTEGER::default();
344+
let mut _free_to_me: u64 = 0;
345+
let mut total: u64 = 0;
346+
let mut free: u64 = 0;
345347
let ret =
346348
unsafe { GetDiskFreeSpaceExW(wpath.as_ptr(), &mut _free_to_me, &mut total, &mut free) };
347349
if ret != 0 {
348-
return Ok(unsafe { (*total.QuadPart(), *free.QuadPart()) });
350+
return Ok((total, free));
349351
}
350352
let err = io::Error::last_os_error();
351353
if err.raw_os_error() == Some(winerror::ERROR_DIRECTORY as i32) {
@@ -359,15 +361,15 @@ pub(crate) mod module {
359361
return if ret == 0 {
360362
Err(errno_err(vm))
361363
} else {
362-
Ok(unsafe { (*total.QuadPart(), *free.QuadPart()) })
364+
Ok((total, free))
363365
};
364366
}
365367
}
366368
Err(err.to_pyexception(vm))
367369
}
368370

369371
#[pyfunction]
370-
fn get_handle_inheritable(handle: intptr_t, vm: &VirtualMachine) -> PyResult<bool> {
372+
fn get_handle_inheritable(handle: isize, vm: &VirtualMachine) -> PyResult<bool> {
371373
let mut flags = 0;
372374
if unsafe { um::handleapi::GetHandleInformation(handle as _, &mut flags) } == 0 {
373375
Err(errno_err(vm))
@@ -376,7 +378,7 @@ pub(crate) mod module {
376378
}
377379
}
378380

379-
pub fn raw_set_handle_inheritable(handle: intptr_t, inheritable: bool) -> io::Result<()> {
381+
pub fn raw_set_handle_inheritable(handle: isize, inheritable: bool) -> io::Result<()> {
380382
use um::winbase::HANDLE_FLAG_INHERIT;
381383
let flags = if inheritable { HANDLE_FLAG_INHERIT } else { 0 };
382384
let res =

0 commit comments

Comments
 (0)