Fix huge oops

Still crashes when reloading tho
This commit is contained in:
SoniEx2 2018-10-15 16:32:43 -03:00
parent d6971a712f
commit 872f4d72a7
2 changed files with 8 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hexchat-plugin" name = "hexchat-plugin"
version = "0.2.7" version = "0.2.8"
authors = ["SoniEx2 <endermoneymod@gmail.com>"] authors = ["SoniEx2 <endermoneymod@gmail.com>"]
description = "Lets you write HexChat plugins in Rust" description = "Lets you write HexChat plugins in Rust"
license = "AGPL-3.0+" license = "AGPL-3.0+"

View File

@ -1410,7 +1410,8 @@ pub unsafe fn hexchat_plugin_init<T>(plugin_handle: *mut libc::c_void,
} }
#[doc(hidden)] #[doc(hidden)]
pub unsafe fn hexchat_plugin_deinit<T>(plugin_handle: *mut libc::c_void) where T: Plugin { pub unsafe fn hexchat_plugin_deinit<T>(plugin_handle: *mut libc::c_void) -> libc::c_int where T: Plugin {
let mut safe_to_unload = 1;
// plugin_handle should never be null, but just in case. // plugin_handle should never be null, but just in case.
if !plugin_handle.is_null() { if !plugin_handle.is_null() {
let ph = plugin_handle as *mut internals::Ph; let ph = plugin_handle as *mut internals::Ph;
@ -1420,11 +1421,11 @@ pub unsafe fn hexchat_plugin_deinit<T>(plugin_handle: *mut libc::c_void) where T
let mut info: Option<PluginInfo> = None; let mut info: Option<PluginInfo> = None;
{ {
let mut ausinfo = ::std::panic::AssertUnwindSafe(&mut info); let mut ausinfo = ::std::panic::AssertUnwindSafe(&mut info);
catch_unwind(move || { safe_to_unload = if catch_unwind(move || {
let userdata = *pop_userdata(ph); let userdata = *pop_userdata(ph);
**ausinfo = Some(userdata.pluginfo); **ausinfo = Some(userdata.pluginfo);
userdata.plug.deinit(&mut PluginHandle { ph, info: userdata.pluginfo }); userdata.plug.deinit(&mut PluginHandle { ph, info: userdata.pluginfo });
}).ok(); }).is_ok() { 1 } else { 0 };
} }
if let Some(mut info) = info { if let Some(mut info) = info {
info.drop_info(); info.drop_info();
@ -1438,6 +1439,7 @@ pub unsafe fn hexchat_plugin_deinit<T>(plugin_handle: *mut libc::c_void) where T
} else { } else {
eprintln!("hexchat_plugin_deinit called with a null plugin_handle - broken hexchat"); eprintln!("hexchat_plugin_deinit called with a null plugin_handle - broken hexchat");
} }
safe_to_unload
} }
/// Exports a hexchat plugin. /// Exports a hexchat plugin.
@ -1453,8 +1455,8 @@ macro_rules! hexchat_plugin {
$crate::hexchat_plugin_init::<$t>(plugin_handle, plugin_name, plugin_desc, plugin_version, arg) $crate::hexchat_plugin_init::<$t>(plugin_handle, plugin_name, plugin_desc, plugin_version, arg)
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn hexchat_plugin_deinit(plugin_handle: *mut $crate::libc::c_void) { pub unsafe extern "C" fn hexchat_plugin_deinit(plugin_handle: *mut $crate::libc::c_void) -> $crate::libc::c_int {
$crate::hexchat_plugin_deinit::<$t>(plugin_handle); $crate::hexchat_plugin_deinit::<$t>(plugin_handle)
} }
// unlike what the documentation states, there's no need to define hexchat_plugin_get_info. // unlike what the documentation states, there's no need to define hexchat_plugin_get_info.
// so we don't. it'd be impossible to make it work well with rust anyway. // so we don't. it'd be impossible to make it work well with rust anyway.