8000 winapi suppliment (#6338) · RustPython/RustPython@f4b8b01 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4b8b01

Browse files
authored
winapi suppliment (#6338)
* winapi.ExitProcess * Fix winapi Handle * msvcrt.GetErrorMode * windows stats * unmark tests
1 parent a14dd59 commit f4b8b01

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

Lib/test/test_faulthandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ def test_enable_single_thread(self):
374374
'Segmentation fault',
375375
all_threads=False)
376376

377-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AttributeError: module 'msvcrt' has no attribute 'GetErrorMode'")
378377
@skip_segfault_on_android
379378
def test_disable(self):
380379
code = """

Lib/test/test_shutil.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ def test_copytree_dirs_exist_ok(self):
739739
with self.assertRaises(FileExistsError):
740740
shutil.copytree(src_dir, dst_dir, dirs_exist_ok=False)
741741

742-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
743742
@os_helper.skip_unless_symlink
744743
def test_copytree_symlinks(self):
745744
tmp_dir = self.mkdtemp()
@@ -1007,7 +1006,6 @@ def test_copytree_dangling_symlinks(self):
10071006
shutil.copytree(src_dir, dst_dir, symlinks=True)
10081007
self.assertIn('test.txt', os.listdir(dst_dir))
10091008

1010-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
10111009
@os_helper.skip_unless_symlink
10121010
def test_copytree_symlink_dir(self):
10131011
src_dir = self.mkdtemp()

Lib/test/test_subprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,6 @@ def _test_bufsize_equal_one(self, line, expected, universal_newlines):
13371337
self.assertEqual(p.returncode, 0)
13381338
self.assertEqual(read_line, expected)
13391339

1340-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
13411340
def test_bufsize_equal_one_text_mode(self):
13421341
# line is flushed in text mode with bufsize=1.
13431342
# we should get the full line in return

crates/vm/src/stdlib/msvcrt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ mod msvcrt {
109109
.map_err(|e| e.into_pyexception(vm))
110110
}
111111

112+
#[allow(non_snake_case)]
113+
#[pyfunction]
114+
fn GetErrorMode() -> u32 {
115+
unsafe { suppress_iph!(Debug::GetErrorMode()) }
116+
}
117+
112118
#[allow(non_snake_case)]
113119
#[pyfunction]
114120
fn SetErrorMode(mode: Debug::THREAD_ERROR_MODE, _: &VirtualMachine) -> u32 {

crates/vm/src/stdlib/stat.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ mod stat {
237237
FILE_ATTRIBUTE_TEMPORARY, FILE_ATTRIBUTE_VIRTUAL,
238238
};
239239

240+
// Windows reparse point tags
241+
#[cfg(windows)]
242+
#[pyattr]
243+
pub const IO_REPARSE_TAG_SYMLINK: u32 = 0xA000000C;
244+
#[cfg(windows)]
245+
#[pyattr]
246+
pub const IO_REPARSE_TAG_MOUNT_POINT: u32 = 0xA0000003;
247+
#[cfg(windows)]
248+
#[pyattr]
249+
pub const IO_REPARSE_TAG_APPEXECLINK: u32 = 0x8000001B;
250+
240251
// Unix file flags (if on Unix)
241252

242253
#[pyattr]

crates/vm/src/stdlib/winapi.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod _winapi {
1919
Win32::Foundation::{HANDLE, HINSTANCE, MAX_PATH},
2020
core::PCWSTR,
2121
};
22-
use windows_sys::Win32::Foundation::{BOOL, HANDLE as RAW_HANDLE};
22+
use windows_sys::Win32::Foundation::{BOOL, INVALID_HANDLE_VALUE};
2323

2424
#[pyattr]
2525
use windows_sys::Win32::{
@@ -87,8 +87,18 @@ mod _winapi {
8787
#[pyfunction]
8888
fn GetStdHandle(
8989
std_handle: windows_sys::Win32::System::Console::STD_HANDLE,
90-
) -> WindowsSysResult<RAW_HANDLE> {
91-
WindowsSysResult(unsafe { windows_sys::Win32::System::Console::GetStdHandle(std_handle) })
90+
vm: &VirtualMachine,
91+
) -> PyResult<Option<HANDLE>> {
92+
let handle = unsafe { windows_sys::Win32::System::Console::GetStdHandle(std_handle) };
93+
if handle == INVALID_HANDLE_VALUE {
94+
return Err(errno_err(vm));
95+
}
96+
Ok(if handle.is_null() {
97+
// NULL handle - return None
98+
None
99+
} else {
100+
Some(HANDLE(handle as isize))
101+
})
92102
}
93103

94104
#[pyfunction]
@@ -114,7 +124,8 @@ mod _winapi {
114124

115125
#[pyfunction]
116126
fn DuplicateHandle(
117-
(src_process, src): (HANDLE, HANDLE),
127+
src_process: HANDLE,
128+
src: HANDLE,
118129
target_process: HANDLE,
119130
access: u32,
120131
inherit: BOOL,
@@ -294,6 +305,11 @@ mod _winapi {
294305
}
295306
}
296307

308+
#[pyfunction]
309+
fn ExitProcess(exit_code: u32) {
310+
unsafe { windows_sys::Win32::System::Threading::ExitProcess(exit_code) }
311+
}
312+
297313
#[pyfunction]
298314
fn NeedCurrentDirectoryForExePath(exe_name: PyStrRef) -> bool {
299315
let exe_name = exe_name.as_str().to_wide_with_nul();

0 commit comments

Comments
 (0)
0