Skip to content

Commit d18d35f

Browse files
authored
cleanup the signals module (RustPython#8076)
1 parent ac3d442 commit d18d35f

2 files changed

Lines changed: 107 additions & 114 deletions

File tree

crates/vm/src/signal.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
#![cfg_attr(target_os = "wasi", allow(dead_code))]
21
use crate::{PyObjectRef, PyResult, VirtualMachine};
32
use alloc::fmt;
43
use core::cell::{Cell, RefCell};
5-
#[cfg(windows)]
6-
use core::sync::atomic::AtomicIsize;
74
use core::sync::atomic::{AtomicBool, Ordering};
85
use std::sync::mpsc;
96

10-
pub(crate) const NSIG: usize = 64;
7+
#[cfg(windows)]
8+
use core::sync::atomic::AtomicIsize;
119

12-
pub(crate) fn new_signal_handlers() -> Box<RefCell<[Option<PyObjectRef>; NSIG]>> {
13-
Box::new(const { RefCell::new([const { None }; NSIG]) })
14-
}
1510
static ANY_TRIGGERED: AtomicBool = AtomicBool::new(false);
16-
// hack to get around const array repeat expressions, rust issue #79270
17-
#[allow(
11+
12+
pub(crate) const NSIG: usize = 64;
13+
14+
#[expect(
1815
clippy::declare_interior_mutable_const,
1916
reason = "workaround for const array repeat limitation (rust issue #79270)"
2017
)]
2118
const ATOMIC_FALSE: AtomicBool = AtomicBool::new(false);
19+
2220
pub(crate) static TRIGGERS: [AtomicBool; NSIG] = [ATOMIC_FALSE; NSIG];
2321

2422
#[cfg(windows)]
2523
static SIGINT_EVENT: AtomicIsize = AtomicIsize::new(0);
2624

25+
pub(crate) fn new_signal_handlers() -> Box<RefCell<[Option<PyObjectRef>; NSIG]>> {
26+
Box::new(const { RefCell::new([const { None }; NSIG]) })
27+
}
28+
2729
thread_local! {
2830
/// Prevent recursive signal handler invocation. When a Python signal
2931
/// handler is running, new signals are deferred until it completes.
@@ -50,6 +52,7 @@ pub fn check_signals(vm: &VirtualMachine) -> PyResult<()> {
5052
if !ANY_TRIGGERED.load(Ordering::Relaxed) {
5153
return Ok(());
5254
}
55+
5356
// Atomic RMW only when a signal is actually pending.
5457
if !ANY_TRIGGERED.swap(false, Ordering::Acquire) {
5558
return Ok(());
@@ -99,8 +102,7 @@ pub(crate) fn is_triggered() -> bool {
99102

100103
/// Reset all signal trigger state after fork in child process.
101104
/// Stale triggers from the parent must not fire in the child.
102-
#[cfg(unix)]
103-
#[cfg(feature = "host_env")]
105+
#[cfg(all(unix, feature = "host_env"))]
104106
pub(crate) fn clear_after_fork() {
105107
ANY_TRIGGERED.store(false, Ordering::Release);
106108
for trigger in &TRIGGERS {

0 commit comments

Comments
 (0)