Skip to content

Commit 06a4796

Browse files
committed
Add msvcrt.open_osfhandle
1 parent b1aa11b commit 06a4796

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Lib/asyncio/windows_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
import _winapi
1111
import itertools
12-
# XXX RustPython TODO: msvcrt
13-
# import msvcrt
12+
import msvcrt
1413
import os
1514
import socket
1615
import subprocess

vm/src/stdlib/msvcrt.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,29 @@ fn msvcrt_setmode(fd: i32, flags: i32, vm: &VirtualMachine) -> PyResult<i32> {
5959
}
6060
}
6161

62+
extern "C" {
63+
fn _open_osfhandle(osfhandle: isize, flags: i32) -> i32;
64+
}
65+
66+
fn msvcrt_open_osfhandle(handle: isize, flags: i32, vm: &VirtualMachine) -> PyResult<i32> {
67+
let ret = unsafe { suppress_iph!(_open_osfhandle(handle, flags)) };
68+
if ret == -1 {
69+
Err(errno_err(vm))
70+
} else {
71+
Ok(ret)
72+
}
73+
}
74+
6275
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
6376
let ctx = &vm.ctx;
64-
py_module!(vm, "_msvcrt", {
77+
py_module!(vm, "msvcrt", {
6578
"getch" => ctx.new_function(msvcrt_getch),
6679
"getwch" => ctx.new_function(msvcrt_getwch),
6780
"getche" => ctx.new_function(msvcrt_getche),
6881
"getwche" => ctx.new_function(msvcrt_getwche),
6982
"putch" => ctx.new_function(msvcrt_putch),
7083
"putwch" => ctx.new_function(msvcrt_putwch),
7184
"setmode" => ctx.new_function(msvcrt_setmode),
85+
"open_osfhandle" => ctx.new_function(msvcrt_open_osfhandle),
7286
})
7387
}

0 commit comments

Comments
 (0)