Skip to content

Commit 4992e7e

Browse files
committed
use _get_osfhandle
1 parent 5dd4b2f commit 4992e7e

File tree

1 file changed

+5
-13
lines changed
  • crates/vm/src/stdlib

1 file changed

+5
-13
lines changed

crates/vm/src/stdlib/nt.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,12 @@ pub(crate) mod module {
205205
) -> PyResult<_os::TerminalSizeData> {
206206
let fd = fd.unwrap_or(1); // default to stdout
207207

208-
// For standard streams, use GetStdHandle which returns proper console handles
209-
// For other fds, use _get_osfhandle to convert
210-
let h = match fd {
211-
0 => unsafe { Console::GetStdHandle(Console::STD_INPUT_HANDLE) },
212-
1 => unsafe { Console::GetStdHandle(Console::STD_OUTPUT_HANDLE) },
213-
2 => unsafe { Console::GetStdHandle(Console::STD_ERROR_HANDLE) },
214-
_ => {
215-
let borrowed = unsafe { crt_fd::Borrowed::borrow_raw(fd) };
216-
let handle = crt_fd::as_handle(borrowed).map_err(|e| e.to_pyexception(vm))?;
217-
handle.as_raw_handle() as _
218-
}
219-
};
208+
// Use _get_osfhandle for all fds
209+
let borrowed = unsafe { crt_fd::Borrowed::borrow_raw(fd) };
210+
let handle = crt_fd::as_handle(borrowed).map_err(|e| e.to_pyexception(vm))?;
211+
let h = handle.as_raw_handle() as Foundation::HANDLE;
220212

221-
if h.is_null() || h == INVALID_HANDLE_VALUE {
213+
if h == INVALID_HANDLE_VALUE {
222214
return Err(errno_err(vm));
223215
}
224216

0 commit comments

Comments
 (0)