Skip to content

Commit b200f0e

Browse files
authored
Replace windows to windows-sys (RustPython#6356)
1 parent 7157697 commit b200f0e

6 files changed

Lines changed: 109 additions & 119 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vm/Cargo.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ num_cpus = "1.17.0"
112112
[target.'cfg(windows)'.dependencies]
113113
junction = { workspace = true }
114114

115-
[target.'cfg(windows)'.dependencies.windows]
116-
version = "0.52.0"
117-
features = [
118-
"Win32_Foundation",
119-
"Win32_System_LibraryLoader",
120-
"Win32_System_Threading",
121-
"Win32_System_Time",
122-
"Win32_UI_Shell",
123-
]
124-
125115
[target.'cfg(windows)'.dependencies.windows-sys]
126116
workspace = true
127117
features = [
@@ -143,6 +133,7 @@ features = [
143133
"Win32_System_SystemInformation",
144134
"Win32_System_SystemServices",
145135
"Win32_System_Threading",
136+
"Win32_System_Time",
146137
"Win32_System_WindowsProgramming",
147138
"Win32_UI_Shell",
148139
"Win32_UI_WindowsAndMessaging",

crates/vm/src/stdlib/nt.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,26 @@ pub(crate) mod module {
552552
String::from_utf16(wstr).map_err(|e| vm.new_unicode_decode_error(e.to_string()))
553553
}
554554

555-
let wbuf = windows::core::PCWSTR::from_raw(backslashed.as_ptr());
556-
let (root, path) = match unsafe { windows::Win32::UI::Shell::PathCchSkipRoot(wbuf) } {
557-
Ok(end) => {
558-
assert!(!end.is_null());
559-
let len: usize = unsafe { end.as_ptr().offset_from(wbuf.as_ptr()) }
560-
.try_into()
561-
.expect("len must be non-negative");
562-
assert!(
563-
len < backslashed.len(), // backslashed is null-terminated
564-
"path: {:?} {} < {}",
565-
std::path::PathBuf::from(std::ffi::OsString::from_wide(&backslashed)),
566-
len,
567-
backslashed.len()
568-
);
569-
(from_utf16(&orig[..len], vm)?, from_utf16(&orig[len..], vm)?)
570-
}
571-
Err(_) => ("".to_owned(), from_utf16(&orig, vm)?),
555+
let mut end: *const u16 = std::ptr::null();
556+
let hr = unsafe {
557+
windows_sys::Win32::UI::Shell::PathCchSkipRoot(backslashed.as_ptr(), &mut end)
558+
};
559+
let (root, path) = if hr == 0 {
560+
// S_OK
561+
assert!(!end.is_null());
562+
let len: usize = unsafe { end.offset_from(backslashed.as_ptr()) }
563+
.try_into()
564+
.expect("len must be non-negative");
565+
assert!(
566+
len < backslashed.len(), // backslashed is null-terminated
567+
"path: {:?} {} < {}",
568+
std::path::PathBuf::from(std::ffi::OsString::from_wide(&backslashed)),
569+
len,
570+
backslashed.len()
571+
);
572+
(from_utf16(&orig[..len], vm)?, from_utf16(&orig[len..], vm)?)
573+
} else {
574+
("".to_owned(), from_utf16(&orig, vm)?)
572575
};
573576
Ok((root, path))
574577
}

crates/vm/src/stdlib/time.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mod decl {
4646
use std::time::Duration;
4747
#[cfg(target_env = "msvc")]
4848
#[cfg(not(target_arch = "wasm32"))]
49-
use windows::Win32::System::Time;
49+
use windows_sys::Win32::System::Time::{GetTimeZoneInformation, TIME_ZONE_INFORMATION};
5050

5151
#[allow(dead_code)]
5252
pub(super) const SEC_TO_MS: i64 = 1000;
@@ -186,10 +186,9 @@ mod decl {
186186

187187
#[cfg(target_env = "msvc")]
188188
#[cfg(not(target_arch = "wasm32"))]
189-
fn get_tz_info() -> Time::TIME_ZONE_INFORMATION {
190-
let mut info = Time::TIME_ZONE_INFORMATION::default();
191-
let info_ptr = &mut info as *mut Time::TIME_ZONE_INFORMATION;
192-
let _ = unsafe { Time::GetTimeZoneInformation(info_ptr) };
189+
fn get_tz_info() -> TIME_ZONE_INFORMATION {
190+
let mut info: TIME_ZONE_INFORMATION = unsafe { std::mem::zeroed() };
191+
unsafe { GetTimeZoneInformation(&mut info) };
193192
info
194193
}
195194

0 commit comments

Comments
 (0)