Rollup merge of #130381 - workingjubilee:sometimes-code-really-is-self-descriptive, r=Noratrieb

library: Compute Rust exception class from its string repr

Noticed this awkwardness while scanning through the code. I think we can do better than that.
This commit is contained in:
Matthias Krüger 2024-09-15 11:55:47 +02:00 committed by GitHub
commit 729aa49d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,7 +61,7 @@ struct Exception {
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let exception = Box::new(Exception { let exception = Box::new(Exception {
_uwe: uw::_Unwind_Exception { _uwe: uw::_Unwind_Exception {
exception_class: rust_exception_class(), exception_class: RUST_EXCEPTION_CLASS,
exception_cleanup: Some(exception_cleanup), exception_cleanup: Some(exception_cleanup),
private: [core::ptr::null(); uw::unwinder_private_data_size], private: [core::ptr::null(); uw::unwinder_private_data_size],
}, },
@ -84,7 +84,7 @@ extern "C" fn exception_cleanup(
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> { pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
let exception = ptr as *mut uw::_Unwind_Exception; let exception = ptr as *mut uw::_Unwind_Exception;
if (*exception).exception_class != rust_exception_class() { if (*exception).exception_class != RUST_EXCEPTION_CLASS {
uw::_Unwind_DeleteException(exception); uw::_Unwind_DeleteException(exception);
super::__rust_foreign_exception(); super::__rust_foreign_exception();
} }
@ -107,7 +107,4 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
// Rust's exception class identifier. This is used by personality routines to // Rust's exception class identifier. This is used by personality routines to
// determine whether the exception was thrown by their own runtime. // determine whether the exception was thrown by their own runtime.
fn rust_exception_class() -> uw::_Unwind_Exception_Class { const RUST_EXCEPTION_CLASS: uw::_Unwind_Exception_Class = u64::from_be_bytes(*b"MOZ\0RUST");
// M O Z \0 R U S T -- vendor, language
0x4d4f5a_00_52555354
}