Skip to content

Commit e9b5568

Browse files
committed
Add os.[sg]et_handle_inheritable
1 parent 561cb78 commit e9b5568

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Lib/test/test_asyncore.py

-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ def test_connection_attributes(self):
723723
self.assertFalse(server.connected)
724724
self.assertFalse(server.accepting)
725725

726-
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON, Windows-only fail")
727726
def test_create_socket(self):
728727
s = asyncore.dispatcher()
729728
s.create_socket(self.family)

vm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ version = "0.3"
144144
features = [
145145
"winsock2", "handleapi", "ws2def", "std", "winbase", "wincrypt", "fileapi", "processenv",
146146
"namedpipeapi", "winnt", "processthreadsapi", "errhandlingapi", "winuser", "synchapi", "wincon",
147-
"impl-default",
147+
"impl-default", "vcruntime"
148148
]
149149

150150
[target.'cfg(target_arch = "wasm32")'.dependencies]

vm/src/stdlib/os.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -2765,7 +2765,6 @@ pub(crate) use posix::raw_set_inheritable;
27652765
mod nt {
27662766
use super::*;
27672767
use crate::builtins::list::PyListRef;
2768-
#[cfg(target_env = "msvc")]
27692768
use winapi::vc::vcruntime::intptr_t;
27702769

27712770
#[pyattr]
@@ -3114,6 +3113,34 @@ mod nt {
31143113
return Err(err.into_pyexception(vm));
31153114
}
31163115

3116+
#[pyfunction]
3117+
fn get_handle_inheritable(handle: intptr_t, vm: &VirtualMachine) -> PyResult<bool> {
3118+
let mut flags = 0;
3119+
if unsafe { winapi::um::handleapi::GetHandleInformation(handle as _, &mut flags) } == 0 {
3120+
Err(errno_err(vm))
3121+
} else {
3122+
Ok(flags & winapi::um::winbase::HANDLE_FLAG_INHERIT != 0)
3123+
}
3124+
}
3125+
3126+
#[pyfunction]
3127+
fn set_handle_inheritable(
3128+
handle: intptr_t,
3129+
inheritable: bool,
3130+
vm: &VirtualMachine,
3131+
) -> PyResult<()> {
3132+
use winapi::um::winbase::HANDLE_FLAG_INHERIT;
3133+
let flags = if inheritable { HANDLE_FLAG_INHERIT } else { 0 };
3134+
let res = unsafe {
3135+
winapi::um::handleapi::SetHandleInformation(handle as _, HANDLE_FLAG_INHERIT, flags)
3136+
};
3137+
if res == 0 {
3138+
Err(errno_err(vm))
3139+
} else {
3140+
Ok(())
3141+
}
3142+
}
3143+
31173144
pub(super) fn support_funcs() -> Vec<SupportFunc> {
31183145
Vec::new()
31193146
}

0 commit comments

Comments
 (0)