chore: stop using static mut (#11088)

This commit is contained in:
DaniPopes
2024-09-21 17:16:25 +02:00
committed by GitHub
parent f141a74f8b
commit c36b2f75b3

View File

@ -44,18 +44,14 @@ macro_rules! raw_errln {
/// Signal handler installed for SIGSEGV /// Signal handler installed for SIGSEGV
extern "C" fn print_stack_trace(_: libc::c_int) { extern "C" fn print_stack_trace(_: libc::c_int) {
const MAX_FRAMES: usize = 256; const MAX_FRAMES: usize = 256;
// Reserve data segment so we don't have to malloc in a signal handler, which might fail let mut stack_trace: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
static mut STACK_TRACE: [*mut libc::c_void; MAX_FRAMES] = [ptr::null_mut(); MAX_FRAMES];
#[allow(static_mut_refs)]
// TODO: remove static mut; this will become a hard error in edition 2024
let stack = unsafe { let stack = unsafe {
// Collect return addresses // Collect return addresses
let depth = libc::backtrace(STACK_TRACE.as_mut_ptr(), MAX_FRAMES as i32); let depth = libc::backtrace(stack_trace.as_mut_ptr(), MAX_FRAMES as i32);
if depth == 0 { if depth == 0 {
return return
} }
&STACK_TRACE.as_slice()[0..(depth as _)] &stack_trace[0..depth as usize]
}; };
// Just a stack trace is cryptic. Explain what we're doing. // Just a stack trace is cryptic. Explain what we're doing.