Open uselessgoddess opened 2 years ago
All panics must be catch and unwind otherwise it is UB. I recommend use catch_unwind with the following if let:
catch_unwind
if let
let result = panic::catch_unwind(|| { // ffi function call }); if let Err(err) = result { // if `err` panic in `Drop` we will be sad forget(err); }
You can create macro or function to resolve it In currently implementation:
macro
#[ffi::specialize_for( . . . )] unsafe fn drop_links<T: LinkType>(this: *mut c_void) { let links: &mut WrappedLinks<T> = unnull_or_panic(this); drop_in_place(links); }
We can split to:
unsafe fn drop_links_impl<T: LinkType>(this: *mut c_void) { // impl } #[ffi::specialize_for( . . . )] unsafe fn drop_links<T: LinkType>(this: *mut c_void) { catch_unwind(/* some */) }
Or add this behavior to ffi::specialize_for
ffi::specialize_for
Also check out unwind_api RFC – advanced
unwind_api RFC
In my new PR(#10) I try use log-panics crate
log-panics
All panics must be catch and unwind otherwise it is UB. I recommend use
catch_unwind
with the followingif let
:You can create
macro
or function to resolve it In currently implementation:We can split to:
Or add this behavior to
ffi::specialize_for