From 1600f7d693c5fba1b279f8d96ec714c897e21799 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 25 Dec 2020 23:37:27 +0100 Subject: [PATCH] fix another comment, and make __rust_start_panic code a bit more semantically clear --- library/panic_unwind/src/lib.rs | 4 ++-- library/std/src/panicking.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 1ac050be3e434..9ce9c477ec0f0 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -105,7 +105,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any #[rustc_std_internal_symbol] #[unwind(allowed)] pub unsafe extern "C" fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32 { - let payload = (*payload).take_box(); + let payload = Box::from_raw((*payload).take_box()); - imp::panic(Box::from_raw(payload)) + imp::panic(payload) } diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 7f4b739cbf87a..6cd572cbe87c1 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -44,8 +44,9 @@ use realstd::io::set_output_capture; extern "C" { fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static); - /// `payload` is actually a `Box`, but we pass this by-reference because the other - /// end of this call does not depend on liballoc, and thus cannot use `Box`. + /// `payload` is passed through another layer of raw pointers as `&mut dyn Trait` is not + /// FFI-safe. `BoxMeUp` lazily performs allocation only when needed (this avoids allocations + /// when using the "abort" panic runtime). #[unwind(allowed)] fn __rust_start_panic(payload: *mut &mut dyn BoxMeUp) -> u32; }