MCPcopy Index your code
hub / github.com/RustPython/RustPython / valid_signals

Function valid_signals

crates/vm/src/stdlib/_signal.rs:568–608  ·  view source on GitHub ↗
(vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

566 /// CPython: signal_valid_signals (signalmodule.c)
567 #[pyfunction]
568 fn valid_signals(vm: &VirtualMachine) -> PyResult {
569 use crate::PyPayload;
570 use crate::builtins::PySet;
571 let set = PySet::default().into_ref(&vm.ctx);
572 #[cfg(unix)]
573 {
574 // Use sigfillset to get all valid signals
575 let mut mask: libc::sigset_t = unsafe { core::mem::zeroed() };
576 // SAFETY: mask is a valid pointer
577 if unsafe { libc::sigfillset(&mut mask) } != 0 {
578 return Err(vm.new_os_error("sigfillset failed".to_owned()));
579 }
580 // Convert the filled mask to a Python set
581 for signum in 1..signal::NSIG {
582 if unsafe { libc::sigismember(&mask, signum as i32) } == 1 {
583 set.add(vm.ctx.new_int(signum as i32).into(), vm)?;
584 }
585 }
586 }
587 #[cfg(windows)]
588 {
589 // Windows only supports a limited set of signals
590 for &signum in &[
591 libc::SIGINT,
592 libc::SIGILL,
593 libc::SIGFPE,
594 libc::SIGSEGV,
595 libc::SIGTERM,
596 SIGBREAK,
597 libc::SIGABRT,
598 ] {
599 set.add(vm.ctx.new_int(signum).into(), vm)?;
600 }
601 }
602 #[cfg(not(any(unix, windows)))]
603 {
604 // Empty set for platforms without signal support (e.g., WASM)
605 let _ = &set;
606 }
607 Ok(set.into())
608 }
609
610 #[cfg(unix)]
611 fn sigset_to_pyset(mask: &libc::sigset_t, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 6

new_os_errorMethod · 0.80
ErrClass · 0.50
into_refMethod · 0.45
to_ownedMethod · 0.45
addMethod · 0.45
new_intMethod · 0.45

Tested by

no test coverage detected