diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-04-22 19:36:44 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-04-22 19:36:44 -0300 |
commit | 1bc1a2e4fe227f2b4904ee6552693049d14f3803 (patch) | |
tree | 0dfcad8cd12ed1f1e6c559c1c42d3eeaa28f5334 | |
parent | 85e7a543c9c5729752ad0cc83a51806f77a3fb65 (diff) |
Make Context UnwindSafe+RefUnwindSafe
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/lib.rs | 25 |
2 files changed, 20 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml index 4c06152..abf0eff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ nul_in_strip = [] [dependencies] libc = "0.2" +impl_trait = "0.1" diff --git a/src/lib.rs b/src/lib.rs index ac8ef85..cae6363 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,6 +183,8 @@ * -[ ] ??? */ +#[macro_use] +extern crate impl_trait; #[doc(hidden)] pub extern crate libc; @@ -280,6 +282,11 @@ pub unsafe trait Plugin<'ph> { /// Called to deinitialize the plugin. /// /// This is always called immediately prior to Drop::drop. + /// + /// # A note about unwinding + /// + /// Panics in deinit will prevent the plugin from being correctly unloaded! + /// Be careful! fn deinit(self: Pin<&mut Self>, ph: &mut PluginHandle<'ph>) { let _ = ph; } @@ -447,12 +454,18 @@ impl<'ph> Drop for PluginEntryHandle<'ph> { } } -impl<'ph> Drop for Context<'ph> { - fn drop(&mut self) { - // check if we need to clean anything up - if self.ctx.strong_count() == 1 && self.ctx.weak_count() == 1 { - let strong = self.ctx.upgrade().unwrap(); - self.contexts.borrow_mut().remove(&strong); +impl_trait! { + impl<'ph> Context<'ph> { + impl trait UnwindSafe {} + impl trait RefUnwindSafe {} + impl trait Drop { + fn drop(&mut self) { + // check if we need to clean anything up + if self.ctx.strong_count() == 1 && self.ctx.weak_count() == 1 { + let strong = self.ctx.upgrade().unwrap(); + self.contexts.borrow_mut().remove(&strong); + } + } } } } |