Skip to content

Commit d01909a

Browse files
committed
replace handleapi to windows-sys
1 parent ee128ea commit d01909a

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ features = [
142142
[target.'cfg(windows)'.dependencies.winapi]
143143
version = "0.3.9"
144144
features = [
145-
"winsock2", "handleapi", "std", "winbase",
145+
"winsock2", "std", "winbase",
146146
"winnt",
147147
"impl-default",
148148
]

vm/src/stdlib/nt.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ pub(crate) mod module {
2929
mem::MaybeUninit,
3030
os::windows::ffi::{OsStrExt, OsStringExt},
3131
};
32-
use winapi::um;
3332
use windows_sys::Win32::{
34-
Foundation::{CloseHandle, INVALID_HANDLE_VALUE},
33+
Foundation::{self, INVALID_HANDLE_VALUE},
3534
Storage::FileSystem,
3635
System::{Console, Threading},
3736
};
@@ -41,12 +40,11 @@ pub(crate) mod module {
4140

4241
#[pyfunction]
4342
pub(super) fn access(path: OsPath, mode: u8, vm: &VirtualMachine) -> PyResult<bool> {
44-
use um::winnt;
4543
let attr = unsafe { FileSystem::GetFileAttributesW(path.to_widecstring(vm)?.as_ptr()) };
4644
Ok(attr != FileSystem::INVALID_FILE_ATTRIBUTES
4745
&& (mode & 2 == 0
48-
|| attr & winnt::FILE_ATTRIBUTE_READONLY == 0
49-
|| attr & winnt::FILE_ATTRIBUTE_DIRECTORY != 0))
46+
|| attr & FileSystem::FILE_ATTRIBUTE_READONLY == 0
47+
|| attr & FileSystem::FILE_ATTRIBUTE_DIRECTORY != 0))
5048
}
5149

5250
#[derive(FromArgs)]
@@ -155,7 +153,7 @@ pub(crate) mod module {
155153
}
156154
let ret = unsafe { Threading::TerminateProcess(h, sig) };
157155
let res = if ret == 0 { Err(errno_err(vm)) } else { Ok(()) };
158-
unsafe { CloseHandle(h) };
156+
unsafe { Foundation::CloseHandle(h) };
159157
res
160158
}
161159

@@ -369,20 +367,24 @@ pub(crate) mod module {
369367
}
370368

371369
#[pyfunction]
372-
fn get_handle_inheritable(handle: isize, vm: &VirtualMachine) -> PyResult<bool> {
370+
fn get_handle_inheritable(handle: intptr_t, vm: &VirtualMachine) -> PyResult<bool> {
373371
let mut flags = 0;
374-
if unsafe { um::handleapi::GetHandleInformation(handle as _, &mut flags) } == 0 {
372+
if unsafe { Foundation::GetHandleInformation(handle as _, &mut flags) } == 0 {
375373
Err(errno_err(vm))
376374
} else {
377-
Ok(flags & um::winbase::HANDLE_FLAG_INHERIT != 0)
375+
Ok(flags & Foundation::HANDLE_FLAG_INHERIT != 0)
378376
}
379377
}
380378

381-
pub fn raw_set_handle_inheritable(handle: isize, inheritable: bool) -> io::Result<()> {
382-
use um::winbase::HANDLE_FLAG_INHERIT;
383-
let flags = if inheritable { HANDLE_FLAG_INHERIT } else { 0 };
384-
let res =
385-
unsafe { um::handleapi::SetHandleInformation(handle as _, HANDLE_FLAG_INHERIT, flags) };
379+
pub fn raw_set_handle_inheritable(handle: intptr_t, inheritable: bool) -> io::Result<()> {
380+
let flags = if inheritable {
381+
Foundation::HANDLE_FLAG_INHERIT
382+
} else {
383+
0
384+
};
385+
let res = unsafe {
386+
Foundation::SetHandleInformation(handle as _, Foundation::HANDLE_FLAG_INHERIT, flags)
387+
};
386388
if res == 0 {
387389
Err(errno())
388390
} else {
@@ -410,7 +412,7 @@ pub(crate) mod module {
410412
let [] = dir_fd.0;
411413
let _ = mode;
412414
let wide = path.to_widecstring(vm)?;
413-
let res = unsafe { um::fileapi::CreateDirectoryW(wide.as_ptr(), std::ptr::null_mut()) };
415+
let res = unsafe { FileSystem::CreateDirectoryW(wide.as_ptr(), std::ptr::null_mut()) };
414416
if res == 0 {
415417
return Err(errno_err(vm));
416418
}

vm/src/stdlib/os.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,17 +1200,18 @@ pub(super) mod _os {
12001200
let res = unsafe { suppress_iph!(libc::lseek(fd, position, how)) };
12011201
#[cfg(windows)]
12021202
let res = unsafe {
1203-
use winapi::um::{fileapi, winnt};
1203+
use winapi::um::winnt;
1204+
use windows_sys::Win32::Storage::FileSystem;
12041205
let handle = Fd(fd).to_raw_handle().map_err(|e| e.into_pyexception(vm))?;
12051206
let mut li = winnt::LARGE_INTEGER::default();
12061207
*li.QuadPart_mut() = position;
1207-
let ret = fileapi::SetFilePointer(
1208-
handle,
1208+
let ret = FileSystem::SetFilePointer(
1209+
handle as _,
12091210
li.u().LowPart as _,
12101211
&mut li.u_mut().HighPart,
12111212
how as _,
12121213
);
1213-
if ret == fileapi::INVALID_SET_FILE_POINTER {
1214+
if ret == FileSystem::INVALID_SET_FILE_POINTER {
12141215
-1
12151216
} else {
12161217
li.u_mut().LowPart = ret;
@@ -1357,10 +1358,8 @@ pub(super) mod _os {
13571358
#[cfg(windows)]
13581359
{
13591360
use std::{fs::OpenOptions, os::windows::prelude::*};
1360-
use winapi::{
1361-
shared::minwindef::{DWORD, FILETIME},
1362-
um::fileapi::SetFileTime,
1363-
};
1361+
use winapi::shared::minwindef::DWORD;
1362+
use windows_sys::Win32::{Foundation::FILETIME, Storage::FileSystem};
13641363

13651364
let [] = dir_fd.0;
13661365

@@ -1382,8 +1381,9 @@ pub(super) mod _os {
13821381
.open(path)
13831382
.map_err(|err| err.into_pyexception(vm))?;
13841383

1385-
let ret =
1386-
unsafe { SetFileTime(f.as_raw_handle() as _, std::ptr::null(), &acc, &modif) };
1384+
let ret = unsafe {
1385+
FileSystem::SetFileTime(f.as_raw_handle() as _, std::ptr::null(), &acc, &modif)
1386+
};
13871387

13881388
if ret == 0 {
13891389
Err(io::Error::last_os_error().into_pyexception(vm))

0 commit comments

Comments
 (0)