Skip to content

Commit 1b98124

Browse files
committed
Simplify exception cleanup for libunwind-style unwinding
1 parent bd03606 commit 1b98124

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libpanic_unwind/gcc.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use unwind as uw;
5757
#[repr(C)]
5858
struct Exception {
5959
_uwe: uw::_Unwind_Exception,
60-
cause: Option<Box<dyn Any + Send>>,
60+
cause: Box<dyn Any + Send>,
6161
}
6262

6363
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
@@ -67,7 +67,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6767
exception_cleanup,
6868
private: [0; uw::unwinder_private_data_size],
6969
},
70-
cause: Some(data),
70+
cause: data,
7171
});
7272
let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception;
7373
return uw::_Unwind_RaiseException(exception_param) as u32;
@@ -87,10 +87,8 @@ pub fn payload() -> *mut u8 {
8787
}
8888

8989
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
90-
let my_ep = ptr as *mut Exception;
91-
let cause = (*my_ep).cause.take();
92-
uw::_Unwind_DeleteException(ptr as *mut _);
93-
cause.unwrap()
90+
let exception = Box::from_raw(ptr as *mut Exception);
91+
exception.cause
9492
}
9593

9694
// Rust's exception class identifier. This is used by personality routines to

0 commit comments

Comments
 (0)