Skip to content

Commit

Permalink
chore: restore windows-sys 0.52 compatibility
Browse files Browse the repository at this point in the history
windows-sys 0.59 changed `HANDLE` from `isize` to `*mut c_void`. This
only matters in two places that check for null. Doing that check in
terms of std's `RawHandle` before converting to the windows-sys type
makes the code compatible with either version.
  • Loading branch information
hanna-kruppe committed Jan 11, 2025
1 parent d2ff8f2 commit 6e1f38e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/anstyle-query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pre-release-replacements = [
]

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = ["Win32_System_Console", "Win32_Foundation"] }
windows-sys = { version = ">=0.52.0, <=0.59.*", features = ["Win32_System_Console", "Win32_Foundation"] }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/anstyle-query/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ mod windows_console {

fn enable_vt(handle: RawHandle) -> std::io::Result<()> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
if handle.is_null() {
return Err(std::io::Error::new(
std::io::ErrorKind::BrokenPipe,
"console is detached",
));
}
let handle: HANDLE = std::mem::transmute(handle);

let mut dwmode: CONSOLE_MODE = 0;
if windows_sys::Win32::System::Console::GetConsoleMode(handle, &mut dwmode) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion crates/anstyle-wincon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ anstyle = { version = "1.0.0", path = "../anstyle" }
lexopt = "0.3.0"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59.0", features = ["Win32_System_Console", "Win32_Foundation"] }
windows-sys = { version = ">=0.52.0, <=0.59.*", features = ["Win32_System_Console", "Win32_Foundation"] }

[lints]
workspace = true
4 changes: 2 additions & 2 deletions crates/anstyle-wincon/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ mod inner {
handle: RawHandle,
) -> Result<CONSOLE_SCREEN_BUFFER_INFO, IoError> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
if handle.is_null() {
return Err(IoError::BrokenPipe);
}
let handle: HANDLE = std::mem::transmute(handle);

let mut info: CONSOLE_SCREEN_BUFFER_INFO = std::mem::zeroed();
if windows_sys::Win32::System::Console::GetConsoleScreenBufferInfo(handle, &mut info)
Expand All @@ -150,10 +150,10 @@ mod inner {
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> Result<(), IoError> {
unsafe {
let handle: HANDLE = std::mem::transmute(handle);
if handle.is_null() {
return Err(IoError::BrokenPipe);
}
let handle: HANDLE = std::mem::transmute(handle);

if windows_sys::Win32::System::Console::SetConsoleTextAttribute(handle, attributes) != 0
{
Expand Down

0 comments on commit 6e1f38e

Please sign in to comment.