forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinapi.rs
More file actions
30 lines (26 loc) · 946 Bytes
/
winapi.rs
File metadata and controls
30 lines (26 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#![allow(non_snake_case)]
use winapi::shared::winerror;
use winapi::um::winnt::HANDLE;
use winapi::um::{handleapi, winbase};
use super::os;
use crate::pyobject::{PyObjectRef, PyResult};
use crate::VirtualMachine;
fn winapi_CloseHandle(handle: usize, vm: &VirtualMachine) -> PyResult<()> {
let res = unsafe { handleapi::CloseHandle(handle as HANDLE) };
if res == 0 {
Err(os::errno_err(vm))
} else {
Ok(())
}
}
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
py_module!(vm, "_winapi", {
"CloseHandle" => ctx.new_function(winapi_CloseHandle),
"WAIT_OBJECT_0" => ctx.new_int(winbase::WAIT_OBJECT_0),
"WAIT_ABANDONED" => ctx.new_int(winbase::WAIT_ABANDONED),
"WAIT_ABANDONED_0" => ctx.new_int(winbase::WAIT_ABANDONED_0),
"WAIT_TIMEOUT" => ctx.new_int(winerror::WAIT_TIMEOUT),
"INFINITE" => ctx.new_int(winbase::INFINITE),
})
}