summary refs log tree commit diff stats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-17 18:11:31 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-17 18:11:31 -0300
commitf12d9429c55e151bfbc9f7b5d23159a904d8ba79 (patch)
tree33761304584a5d4b4a4548300dbd1e50fb39e99c /src/lib.rs
parente9b6186a1d5bf4fe342c89c256dfa27c30e16b0a (diff)
Fix leaking HookHandles
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 4bd5de3..a2b43b3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -355,7 +355,7 @@ pub struct EventAttrs<'a> {
 
 /// A hook handle, used to enable unhooking.
 #[must_use = "Hooks must be stored somewhere and are automatically unhooked on Drop"]
-pub struct HookHandle<'ph, 'f> where 'ph: 'f {
+pub struct HookHandle<'ph, 'f> where 'f: 'ph {
     ph: LtPhPtr<'ph>,
     hh: *const internals::HexchatHook,
     freed: Rc<Cell<bool>>,
@@ -395,7 +395,7 @@ impl<F> InvalidContextError<F> {
     }
 }
 
-impl<'ph, 'f> HookHandle<'ph, 'f> where 'ph: 'f {
+impl<'ph, 'f> HookHandle<'ph, 'f> where 'f: 'ph {
     /// If this is a timer hook, returns whether the hook has expired.
     ///
     /// Otherwise, returns false.
@@ -417,7 +417,7 @@ impl<'ph, 'f> HookHandle<'ph, 'f> where 'ph: 'f {
     }
 }
 
-impl<'ph, 'f> Drop for HookHandle<'ph, 'f> where 'ph: 'f {
+impl<'ph, 'f> Drop for HookHandle<'ph, 'f> where 'f: 'ph {
     fn drop(&mut self) {
         if self.freed.get() {
             // already free'd.
@@ -697,7 +697,7 @@ impl<'ph> PluginHandle<'ph> {
     ///     ]
     /// }
     /// ```
-    pub fn hook_command<'f, F>(&self, cmd: &str, pri: i32, help: Option<&str>, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_command<'f, F>(&self, cmd: &str, pri: i32, help: Option<&str>, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         unsafe extern "C" fn callback(word: *const *const c_char, word_eol: *const *const c_char, ud: *mut c_void) -> c_int {
             let f: Rc<HookUd> = rc_clone_from_raw(ud as *const HookUd);
@@ -747,12 +747,12 @@ impl<'ph> PluginHandle<'ph> {
     ///     ]
     /// }
     /// ```
-    pub fn hook_server<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_server<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         self.hook_server_attrs(cmd, pri, move |ph, w, we, _| cb(ph, w, we))
     }
     /// Sets a server hook, with attributes.
-    pub fn hook_server_attrs<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_server_attrs<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         unsafe extern "C" fn callback(word: *const *const c_char, word_eol: *const *const c_char, attrs: *const RawAttrs, ud: *mut c_void) -> c_int {
             let f: Rc<HookUd> = rc_clone_from_raw(ud as *const HookUd);
@@ -804,7 +804,7 @@ impl<'ph> PluginHandle<'ph> {
     ///     ]
     /// }
     /// ```
-    pub fn hook_print<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_print<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         // hmm, is there any way to avoid this code duplication?
         // hook_print is special because dummy prints (keypresses, Close Context) are handled
@@ -857,7 +857,7 @@ impl<'ph> PluginHandle<'ph> {
     ///     ]
     /// }
     /// ```
-    pub fn hook_print_attrs<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_print_attrs<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         unsafe extern "C" fn callback(word: *const *const c_char, attrs: *const RawAttrs, ud: *mut c_void) -> c_int {
             let f: Rc<HookUd> = rc_clone_from_raw(ud as *const HookUd);
@@ -904,7 +904,7 @@ impl<'ph> PluginHandle<'ph> {
     ///     ]
     /// }
     /// ```
-    pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe, 'f: 'ph {
         assert_eq!(self.data.ph, self.plugin, "PluginEntryHandle can't have hooks");
         unsafe extern "C" fn callback(ud: *mut c_void) -> c_int {
             let f: Rc<HookUd> = rc_clone_from_raw(ud as *const HookUd);
@@ -1369,37 +1369,37 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> {
     /// Sets a command hook.
     ///
     /// See [`PluginHandle::hook_command`].
-    pub fn hook_command<'f, F>(&self, cmd: &str, pri: i32, help: Option<&str>, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_command<'f, F>(&self, cmd: &str, pri: i32, help: Option<&str>, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_command(cmd, pri, help, cb)
     }
     /// Sets a server hook.
     ///
     /// See [`PluginHandle::hook_server`].
-    pub fn hook_server<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_server<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_server(cmd, pri, cb)
     }
     /// Sets a server hook with attributes.
     ///
     /// See [`PluginHandle::hook_server_attrs`].
-    pub fn hook_server_attrs<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_server_attrs<'f, F>(&self, cmd: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, WordEol, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_server_attrs(cmd, pri, cb)
     }
     /// Sets a print hook.
     ///
     /// See [`PluginHandle::hook_print`].
-    pub fn hook_print<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_print<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_print(name, pri, cb)
     }
     /// Sets a print hook with attributes.
     ///
     /// See [`PluginHandle::hook_print_attrs`].
-    pub fn hook_print_attrs<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_print_attrs<'f, F>(&self, name: &str, pri: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>, Word, EventAttrs) -> Eat + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_print_attrs(name, pri, cb)
     }
     /// Sets a timer hook.
     ///
     /// See [`PluginHandle::hook_timer`].
-    pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe, 'ph: 'f {
+    pub fn hook_timer<'f, F>(&self, timeout: i32, cb: F) -> HookHandle<'ph, 'f> where F: Fn(&mut PluginHandle<'ph>) -> bool + 'f + RefUnwindSafe, 'f: 'ph {
         self.ph.hook_timer(timeout, cb)
     }
     /// Returns context and client information.