Skip to content

Commit

Permalink
Fix destructor return value in emcc.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Jan 13, 2020
1 parent 8f60db8 commit 4f163af
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/libpanic_unwind/emcc.rs
Expand Up @@ -76,12 +76,20 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
}
ptr::write(exception, Exception { data: Some(data) });
__cxa_throw(exception as *mut _, &EXCEPTION_TYPE_INFO, exception_cleanup);
}

extern "C" fn exception_cleanup(ptr: *mut libc::c_void) {
unsafe {
ptr::drop_in_place(ptr as *mut Exception);
super::__rust_drop_panic();
}
// On WASM and ARM, the destructor returns the pointer to the object.
cfg_if::cfg_if! {
if #[cfg(any(target_arch = "arm", target_arch = "wasm32"))] {
type DestructorRet = *mut libc::c_void;
} else {
type DestructorRet = ();
}
}
extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> DestructorRet {
unsafe {
ptr::drop_in_place(ptr as *mut Exception);
super::__rust_drop_panic();
}
}

Expand All @@ -104,7 +112,7 @@ extern "C" {
fn __cxa_throw(
thrown_exception: *mut libc::c_void,
tinfo: *const TypeInfo,
dest: extern "C" fn(*mut libc::c_void),
dest: extern "C" fn(*mut libc::c_void) -> DestructorRet,
) -> !;
fn __gxx_personality_v0(
version: c_int,
Expand Down

0 comments on commit 4f163af

Please sign in to comment.