Skip to content

Commit ac33c4a

Browse files
committed
fix wasm32 build
1 parent cf3ad0a commit ac33c4a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

crates/stdlib/src/faulthandler.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod decl {
99
};
1010
#[cfg(any(unix, windows))]
1111
use rustpython_common::os::{get_errno, set_errno};
12-
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicUsize, Ordering};
12+
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
1313
use std::sync::{Arc, Condvar, Mutex};
1414
use std::thread;
1515
use std::time::Duration;
@@ -68,15 +68,23 @@ mod decl {
6868
// 1. Signal handlers run in a single-threaded context (from the OS perspective)
6969
// 2. FAULTHANDLER_HANDLERS is only modified during enable/disable operations
7070
// 3. This matches CPython's faulthandler.c implementation
71+
#[cfg(unix)]
7172
static mut FAULTHANDLER_HANDLERS: [FaultHandler; FAULTHANDLER_NSIGNALS] = [
72-
#[cfg(unix)]
7373
FaultHandler::new(libc::SIGBUS, "Bus error"),
7474
FaultHandler::new(libc::SIGILL, "Illegal instruction"),
7575
FaultHandler::new(libc::SIGFPE, "Floating-point exception"),
7676
FaultHandler::new(libc::SIGABRT, "Aborted"),
7777
FaultHandler::new(libc::SIGSEGV, "Segmentation fault"),
7878
];
7979

80+
#[cfg(windows)]
81+
static mut FAULTHANDLER_HANDLERS: [FaultHandler; FAULTHANDLER_NSIGNALS] = [
82+
FaultHandler::new(libc::SIGILL, "Illegal instruction"),
83+
FaultHandler::new(libc::SIGFPE, "Floating-point exception"),
84+
FaultHandler::new(libc::SIGABRT, "Aborted"),
85+
FaultHandler::new(libc::SIGSEGV, "Segmentation fault"),
86+
];
87+
8088
/// fatal_error state
8189
struct FatalErrorState {
8290
enabled: AtomicBool,
@@ -106,6 +114,7 @@ mod decl {
106114
// Frame snapshot for signal-safe traceback (RustPython-specific)
107115

108116
/// Frame information snapshot for signal-safe access
117+
#[cfg(any(unix, windows))]
109118
#[derive(Clone, Copy)]
110119
struct FrameSnapshot {
111120
filename: [u8; 256],
@@ -115,6 +124,7 @@ mod decl {
115124
funcname_len: usize,
116125
}
117126

127+
#[cfg(any(unix, windows))]
118128
impl FrameSnapshot {
119129
const EMPTY: Self = Self {
120130
filename: [0; 256],
@@ -125,12 +135,15 @@ mod decl {
125135
};
126136
}
127137

138+
#[cfg(any(unix, windows))]
128139
const MAX_SNAPSHOT_FRAMES: usize = 100;
129140

130141
/// Signal-safe global storage for frame snapshots
142+
#[cfg(any(unix, windows))]
131143
static mut FRAME_SNAPSHOTS: [FrameSnapshot; MAX_SNAPSHOT_FRAMES] =
132144
[FrameSnapshot::EMPTY; MAX_SNAPSHOT_FRAMES];
133-
static SNAPSHOT_COUNT: AtomicUsize = AtomicUsize::new(0);
145+
#[cfg(any(unix, windows))]
146+
static SNAPSHOT_COUNT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
134147

135148
// Signal-safe output functions
136149

@@ -698,6 +711,9 @@ mod decl {
698711
drop(guard); // Release lock before I/O
699712

700713
// Timeout occurred, dump traceback
714+
#[cfg(target_arch = "wasm32")]
715+
let _ = (exit, fd, &header);
716+
701717
#[cfg(not(target_arch = "wasm32"))]
702718
{
703719
let header_bytes = header.as_bytes();

0 commit comments

Comments
 (0)