Skip to content

Commit 4f163af

Browse files
committed
Fix destructor return value in emcc.rs
1 parent 8f60db8 commit 4f163af

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/libpanic_unwind/emcc.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,20 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
7676
}
7777
ptr::write(exception, Exception { data: Some(data) });
7878
__cxa_throw(exception as *mut _, &EXCEPTION_TYPE_INFO, exception_cleanup);
79+
}
7980

80-
extern "C" fn exception_cleanup(ptr: *mut libc::c_void) {
81-
unsafe {
82-
ptr::drop_in_place(ptr as *mut Exception);
83-
super::__rust_drop_panic();
84-
}
81+
// On WASM and ARM, the destructor returns the pointer to the object.
82+
cfg_if::cfg_if! {
83+
if #[cfg(any(target_arch = "arm", target_arch = "wasm32"))] {
84+
type DestructorRet = *mut libc::c_void;
85+
} else {
86+
type DestructorRet = ();
87+
}
88+
}
89+
extern "C" fn exception_cleanup(ptr: *mut libc::c_void) -> DestructorRet {
90+
unsafe {
91+
ptr::drop_in_place(ptr as *mut Exception);
92+
super::__rust_drop_panic();
8593
}
8694
}
8795

@@ -104,7 +112,7 @@ extern "C" {
104112
fn __cxa_throw(
105113
thrown_exception: *mut libc::c_void,
106114
tinfo: *const TypeInfo,
107-
dest: extern "C" fn(*mut libc::c_void),
115+
dest: extern "C" fn(*mut libc::c_void) -> DestructorRet,
108116
) -> !;
109117
fn __gxx_personality_v0(
110118
version: c_int,

0 commit comments

Comments
 (0)