mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add os.[sg]et_handle_inheritable
This commit is contained in:
1 parent
561cb78047
commit
e9b55686f4
3 files changed
+29
-3
No files matched your search
@@ -723,7 +723,6 @@ class BaseTestAPI:
|
||||
self.assertFalse(server.connected)
|
||||
self.assertFalse(server.accepting)
|
||||
|
||||
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, Windows-only fail")
|
||||
def test_create_socket(self):
|
||||
s = asyncore.dispatcher()
|
||||
s.create_socket(self.family)
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ version = "0.3"
|
||||
features = [
|
||||
"winsock2", "handleapi", "ws2def", "std", "winbase", "wincrypt", "fileapi", "processenv",
|
||||
"namedpipeapi", "winnt", "processthreadsapi", "errhandlingapi", "winuser", "synchapi", "wincon",
|
||||
"impl-default",
|
||||
"impl-default", "vcruntime"
|
||||
]
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
||||
+28
-1
@@ -2765,7 +2765,6 @@ pub(crate) use posix::raw_set_inheritable;
|
||||
mod nt {
|
||||
use super::*;
|
||||
use crate::builtins::list::PyListRef;
|
||||
#[cfg(target_env = "msvc")]
|
||||
use winapi::vc::vcruntime::intptr_t;
|
||||
|
||||
#[pyattr]
|
||||
@@ -3114,6 +3113,34 @@ mod nt {
|
||||
return Err(err.into_pyexception(vm));
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn get_handle_inheritable(handle: intptr_t, vm: &VirtualMachine) -> PyResult<bool> {
|
||||
let mut flags = 0;
|
||||
if unsafe { winapi::um::handleapi::GetHandleInformation(handle as _, &mut flags) } == 0 {
|
||||
Err(errno_err(vm))
|
||||
} else {
|
||||
Ok(flags & winapi::um::winbase::HANDLE_FLAG_INHERIT != 0)
|
||||
}
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn set_handle_inheritable(
|
||||
handle: intptr_t,
|
||||
inheritable: bool,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
use winapi::um::winbase::HANDLE_FLAG_INHERIT;
|
||||
let flags = if inheritable { HANDLE_FLAG_INHERIT } else { 0 };
|
||||
let res = unsafe {
|
||||
winapi::um::handleapi::SetHandleInformation(handle as _, HANDLE_FLAG_INHERIT, flags)
|
||||
};
|
||||
if res == 0 {
|
||||
Err(errno_err(vm))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn support_funcs() -> Vec<SupportFunc> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user