Skip to content

Commit efbb6cf

Browse files
committed
use _get_osfhandle
1 parent 93c3cfd commit efbb6cf

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

Lib/test/test_subprocess.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,8 +1772,6 @@ def test_run_with_pathlike_path_and_arguments(self):
17721772
res = subprocess.run(args)
17731773
self.assertEqual(res.returncode, 57)
17741774

1775-
# TODO: RUSTPYTHON
1776-
@unittest.expectedFailure
17771775
@unittest.skipUnless(mswindows, "Maybe test trigger a leak on Ubuntu")
17781776
def test_run_with_an_empty_env(self):
17791777
# gh-105436: fix subprocess.run(..., env={}) broken on Windows

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)