Skip to content

Commit cefd5fa

Browse files
committed
Align _winapi module with CPython
- Rename winapi.rs to _winapi.rs with #[path] attribute - Rename CreateMutex to CreateMutexW - Add missing constants: ERROR_ACCESS_DENIED, ERROR_PRIVILEGE_NOT_HELD, PROCESS_ALL_ACCESS, 10 STARTF_ constants, LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_NAME_USER_DEFAULT, COPY_FILE_DIRECTORY - Fix OpenMutexW return type and ReleaseMutex param type to use WinHandle
1 parent 13e5d02 commit cefd5fa

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ mod _winapi {
2020
#[pyattr]
2121
use windows_sys::Win32::{
2222
Foundation::{
23-
DUPLICATE_CLOSE_SOURCE, DUPLICATE_SAME_ACCESS, ERROR_ALREADY_EXISTS, ERROR_BROKEN_PIPE,
24-
ERROR_IO_PENDING, ERROR_MORE_DATA, ERROR_NETNAME_DELETED, ERROR_NO_DATA,
25-
ERROR_NO_SYSTEM_RESOURCES, ERROR_OPERATION_ABORTED, ERROR_PIPE_BUSY,
26-
ERROR_PIPE_CONNECTED, ERROR_SEM_TIMEOUT, GENERIC_READ, GENERIC_WRITE, STILL_ACTIVE,
27-
WAIT_ABANDONED, WAIT_ABANDONED_0, WAIT_OBJECT_0, WAIT_TIMEOUT,
23+
DUPLICATE_CLOSE_SOURCE, DUPLICATE_SAME_ACCESS, ERROR_ACCESS_DENIED,
24+
ERROR_ALREADY_EXISTS, ERROR_BROKEN_PIPE, ERROR_IO_PENDING, ERROR_MORE_DATA,
25+
ERROR_NETNAME_DELETED, ERROR_NO_DATA, ERROR_NO_SYSTEM_RESOURCES,
26+
ERROR_OPERATION_ABORTED, ERROR_PIPE_BUSY, ERROR_PIPE_CONNECTED,
27+
ERROR_PRIVILEGE_NOT_HELD, ERROR_SEM_TIMEOUT, GENERIC_READ, GENERIC_WRITE,
28+
STILL_ACTIVE, WAIT_ABANDONED, WAIT_ABANDONED_0, WAIT_OBJECT_0, WAIT_TIMEOUT,
2829
},
2930
Globalization::{
3031
LCMAP_FULLWIDTH, LCMAP_HALFWIDTH, LCMAP_HIRAGANA, LCMAP_KATAKANA,
@@ -103,9 +104,12 @@ mod _winapi {
103104
ABOVE_NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS,
104105
CREATE_BREAKAWAY_FROM_JOB, CREATE_DEFAULT_ERROR_MODE, CREATE_NEW_CONSOLE,
105106
CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, DETACHED_PROCESS, HIGH_PRIORITY_CLASS,
106-
IDLE_PRIORITY_CLASS, INFINITE, NORMAL_PRIORITY_CLASS, PROCESS_DUP_HANDLE,
107-
REALTIME_PRIORITY_CLASS, STARTF_FORCEOFFFEEDBACK, STARTF_FORCEONFEEDBACK,
108-
STARTF_USESHOWWINDOW, STARTF_USESTDHANDLES,
107+
IDLE_PRIORITY_CLASS, INFINITE, NORMAL_PRIORITY_CLASS, PROCESS_ALL_ACCESS,
108+
PROCESS_DUP_HANDLE, REALTIME_PRIORITY_CLASS, STARTF_FORCEOFFFEEDBACK,
109+
STARTF_FORCEONFEEDBACK, STARTF_PREVENTPINNING, STARTF_RUNFULLSCREEN,
110+
STARTF_TITLEISAPPID, STARTF_TITLEISLINKNAME, STARTF_UNTRUSTEDSOURCE,
111+
STARTF_USECOUNTCHARS, STARTF_USEFILLATTRIBUTE, STARTF_USEHOTKEY,
112+
STARTF_USEPOSITION, STARTF_USESHOWWINDOW, STARTF_USESIZE, STARTF_USESTDHANDLES,
109113
},
110114
},
111115
UI::WindowsAndMessaging::SW_HIDE,
@@ -117,6 +121,9 @@ mod _winapi {
117121
#[pyattr]
118122
const INVALID_HANDLE_VALUE: isize = -1;
119123

124+
#[pyattr]
125+
const COPY_FILE_DIRECTORY: u32 = 0x00000080;
126+
120127
#[pyfunction]
121128
fn CloseHandle(handle: WinHandle) -> WindowsSysResult<i32> {
122129
WindowsSysResult(unsafe { windows_sys::Win32::Foundation::CloseHandle(handle.0) })
@@ -678,7 +685,7 @@ mod _winapi {
678685
inherit_handle: bool,
679686
name: PyStrRef,
680687
vm: &VirtualMachine,
681-
) -> PyResult<isize> {
688+
) -> PyResult<WinHandle> {
682689
let name_wide = name.as_wtf8().to_wide_with_nul();
683690
let handle = unsafe {
684691
windows_sys::Win32::System::Threading::OpenMutexW(
@@ -690,20 +697,28 @@ mod _winapi {
690697
if handle.is_null() {
691698
return Err(vm.new_last_os_error());
692699
}
693-
Ok(handle as _)
700+
Ok(WinHandle(handle))
694701
}
695702

696703
#[pyfunction]
697-
fn ReleaseMutex(handle: isize) -> WindowsSysResult<i32> {
704+
fn ReleaseMutex(handle: WinHandle) -> WindowsSysResult<i32> {
698705
WindowsSysResult(unsafe {
699-
windows_sys::Win32::System::Threading::ReleaseMutex(handle as _)
706+
windows_sys::Win32::System::Threading::ReleaseMutex(handle.0)
700707
})
701708
}
702709

703710
// LOCALE_NAME_INVARIANT is an empty string in Windows API
704711
#[pyattr]
705712
const LOCALE_NAME_INVARIANT: &str = "";
706713

714+
#[pyattr]
715+
const LOCALE_NAME_SYSTEM_DEFAULT: &str = "!x-sys-default-locale";
716+
717+
#[pyattr(name = "LOCALE_NAME_USER_DEFAULT")]
718+
fn locale_name_user_default(vm: &VirtualMachine) -> PyObjectRef {
719+
vm.ctx.none()
720+
}
721+
707722
/// LCMapStringEx - Map a string to another string using locale-specific rules
708723
/// This is used by ntpath.normcase() for proper Windows case conversion
709724
#[pyfunction]
@@ -1445,7 +1460,7 @@ mod _winapi {
14451460

14461461
/// CreateMutexW - Create or open a named or unnamed mutex object.
14471462
#[pyfunction]
1448-
fn CreateMutex(
1463+
fn CreateMutexW(
14491464
security_attributes: isize,
14501465
initial_owner: bool,
14511466
name: Option<PyStrRef>,

crates/vm/src/stdlib/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mod _wmi;
6464
pub(crate) mod signal;
6565
pub mod sys;
6666
#[cfg(all(feature = "host_env", windows))]
67+
#[path = "_winapi.rs"]
6768
mod winapi;
6869
#[cfg(all(feature = "host_env", windows))]
6970
mod winreg;

0 commit comments

Comments
 (0)