Skip to content

Commit 9acfc46

Browse files
committed
use _get_osfhandle
1 parent 7384782 commit 9acfc46

File tree

1 file changed

+4
-16
lines changed
  • crates/vm/src/stdlib

1 file changed

+4
-16
lines changed

crates/vm/src/stdlib/nt.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,10 @@ 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-
};
220-
221-
if h.is_null() || h == INVALID_HANDLE_VALUE {
222-
return Err(errno_err(vm));
223-
}
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;
224212

225213
let mut csbi = MaybeUninit::uninit();
226214
let ret = unsafe { Console::GetConsoleScreenBufferInfo(h, csbi.as_mut_ptr()) };

0 commit comments

Comments
 (0)