From 6ce60768df1139af138c566f4e884f4b7c173cd5 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 25 Mar 2018 01:45:53 -0300 Subject: Less UB? Huge overhaul. --- src/internals.rs | 167 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 83 deletions(-) (limited to 'src/internals.rs') diff --git a/src/internals.rs b/src/internals.rs index 8a881e0..71ac93f 100644 --- a/src/internals.rs +++ b/src/internals.rs @@ -19,6 +19,7 @@ //! //! This also includes the hexchat_plugin struct, from hexchat-plugin.h. Note that we use the //! struct even on non-Windows platforms because it's a lot easier that way. Should be safe, tho. + use libc; // apparently this is the right way to do these @@ -54,85 +55,85 @@ pub type HexchatPlugin = Ph; #[repr(C)] pub struct Ph { - pub hexchat_hook_command: Option libc::c_int>, + callback: unsafe extern "C" fn(word: *const *const libc::c_char, word_eol: *const *const libc::c_char, user_data: *mut libc::c_void) -> libc::c_int, help_text: *const libc::c_char, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_hook_server: Option *const HexchatHook, + pub hexchat_hook_server: unsafe extern "C" fn(ph: *mut HexchatPlugin, name: *const libc::c_char, pri: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_hook_print: Option *const HexchatHook, + pub hexchat_hook_print: unsafe extern "C" fn(ph: *mut HexchatPlugin, name: *const libc::c_char, pri: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_hook_timer: Option *const HexchatHook, + pub hexchat_hook_timer: unsafe extern "C" fn(ph: *mut HexchatPlugin, timeout: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_hook_fd: Option *const HexchatHook, + pub hexchat_hook_fd: unsafe extern "C" fn(ph: *mut HexchatPlugin, fd: libc::c_int, flags: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_unhook: Option *const libc::c_void>, - pub hexchat_print: Option, - pub hexchat_printf: Option, - pub hexchat_command: Option, - pub hexchat_commandf: Option, - pub hexchat_nickcmp: Option *const HexchatHook, + pub hexchat_unhook: unsafe extern "C" fn(ph: *mut HexchatPlugin, + hook: *const HexchatHook) -> *const libc::c_void, + pub hexchat_print: unsafe extern "C" fn(ph: *mut HexchatPlugin, + text: *const libc::c_char), + pub hexchat_printf_do_not_use: unsafe extern "C" fn(ph: *mut HexchatPlugin, + format: *const libc::c_char, ...), + pub hexchat_command: unsafe extern "C" fn(ph: *mut HexchatPlugin, + command: *const libc::c_char), + pub hexchat_commandf_do_not_use: unsafe extern "C" fn(ph: *mut HexchatPlugin, + format: *const libc::c_char, ...), + pub hexchat_nickcmp: unsafe extern "C" fn(ph: *mut HexchatPlugin, s1: *const libc::c_char, - s2: *const libc::c_char) -> libc::c_int>, - pub hexchat_set_context: Option libc::c_int>, - pub hexchat_find_context: Option libc::c_int, + pub hexchat_set_context: unsafe extern "C" fn(ph: *mut HexchatPlugin, + ctx: *const HexchatContext) -> libc::c_int, + pub hexchat_find_context: unsafe extern "C" fn(ph: *mut HexchatPlugin, servname: *const libc::c_char, - channel: *const libc::c_char) -> *const HexchatContext>, - pub hexchat_get_context: Option *const HexchatContext>, - pub hexchat_get_info: Option *const libc::c_char>, - pub hexchat_get_prefs: Option *const HexchatContext, + pub hexchat_get_context: unsafe extern "C" fn(ph: *mut HexchatPlugin) -> *const HexchatContext, + pub hexchat_get_info: unsafe extern "C" fn(ph: *mut HexchatPlugin, + id: *const libc::c_char) -> *const libc::c_char, + pub hexchat_get_prefs: unsafe extern "C" fn(ph: *mut HexchatPlugin, name: *const libc::c_char, string: *mut *const libc::c_char, - integer: *mut libc::c_int) -> libc::c_int>, - pub hexchat_list_get: Option *const HexchatList>, - pub hexchat_list_free: Option, - pub hexchat_list_fields: Option *const *const libc::c_char>, - pub hexchat_list_next: Option libc::c_int>, - pub hexchat_list_str: Option libc::c_int, + pub hexchat_list_get: unsafe extern "C" fn(ph: *mut HexchatPlugin, + name: *const libc::c_char) -> *const HexchatList, + pub hexchat_list_free: unsafe extern "C" fn(ph: *mut HexchatPlugin, + xlist: *const HexchatList), + pub hexchat_list_fields: unsafe extern "C" fn(ph: *mut HexchatPlugin, + name: *const libc::c_char) -> *const *const libc::c_char, + pub hexchat_list_next: unsafe extern "C" fn(ph: *mut HexchatPlugin, + xlist: *const HexchatList) -> libc::c_int, + pub hexchat_list_str: unsafe extern "C" fn(ph: *mut HexchatPlugin, xlist: *const HexchatList, - name: *const libc::c_char) -> *const libc::c_char>, - pub hexchat_list_int: Option *const libc::c_char, + pub hexchat_list_int: unsafe extern "C" fn(ph: *mut HexchatPlugin, xlist: *const HexchatList, - name: *const libc::c_char) -> libc::c_int>, - pub hexchat_plugingui_add: Option libc::c_int, + pub hexchat_plugingui_add: unsafe extern "C" fn(ph: *mut HexchatPlugin, filename: *const libc::c_char, name: *const libc::c_char, desc: *const libc::c_char, version: *const libc::c_char, - reserved: *mut char) -> *const PluginGuiHandle>, - pub hexchat_plugingui_remove: Option, - pub hexchat_emit_print: Option libc::c_int>, + reserved: *mut char) -> *const PluginGuiHandle, + pub hexchat_plugingui_remove: unsafe extern "C" fn(ph: *mut HexchatPlugin, + handle: *const PluginGuiHandle), + pub hexchat_emit_print: unsafe extern "C" fn(ph: *mut HexchatPlugin, + event_name: *const libc::c_char, ...) -> libc::c_int, // this is VERY NAUGHTY. // TODO see if hexchat's gonna provide a proper userdata field at some point. // it appears this function isn't used anywhere by hexchat so we reuse its pointer. @@ -140,57 +141,57 @@ pub struct Ph { // another option would've been to use one of the printf functions. // TODO test this on platforms hexchat doesn't build on, like AVR. pub userdata: *mut libc::c_void, - /*pub hexchat_read_fd: Option libc::c_int>,*/ - pub hexchat_list_time: Option libc::c_int,*/ + pub hexchat_list_time: unsafe extern "C" fn(ph: *mut HexchatPlugin, xlist: *const HexchatList, - name: *const libc::c_char) -> libc::time_t>, - pub hexchat_gettext: Option *const libc::c_char>, - pub hexchat_send_modes: Option libc::time_t, + pub hexchat_gettext: unsafe extern "C" fn(ph: *mut HexchatPlugin, + msgid: *const libc::c_char) -> *const libc::c_char, + pub hexchat_send_modes: unsafe extern "C" fn(ph: *mut HexchatPlugin, targets: *mut *const libc::c_char, ntargets: libc::c_int, modes_per_line: libc::c_int, sign: libc::c_char, - mode: libc::c_char)>, - pub hexchat_strip: Option *const libc::c_char>, - pub hexchat_free: Option, - pub hexchat_pluginpref_set_str: Option *const libc::c_char, + pub hexchat_free: unsafe extern "C" fn(ph: *mut HexchatPlugin, + ptr: *const libc::c_void), + pub hexchat_pluginpref_set_str: unsafe extern "C" fn(ph: *mut HexchatPlugin, var: *const libc::c_char, - value: *const libc::c_char) -> libc::c_int>, - pub hexchat_pluginpref_get_str: Option libc::c_int, + pub hexchat_pluginpref_get_str: unsafe extern "C" fn(ph: *mut HexchatPlugin, var: *const libc::c_char, - dest: *mut char) -> libc::c_int>, - pub hexchat_pluginpref_set_int: Option libc::c_int, + pub hexchat_pluginpref_set_int: unsafe extern "C" fn(ph: *mut HexchatPlugin, var: *const libc::c_char, - value: libc::c_int) -> libc::c_int>, - pub hexchat_pluginpref_get_int: Option libc::c_int>, - pub hexchat_pluginpref_delete: Option libc::c_int>, - pub hexchat_pluginpref_list: Option libc::c_int>, - pub hexchat_hook_server_attrs: Option libc::c_int, + pub hexchat_pluginpref_get_int: unsafe extern "C" fn(ph: *mut HexchatPlugin, + var: *const libc::c_char) -> libc::c_int, + pub hexchat_pluginpref_delete: unsafe extern "C" fn(ph: *mut HexchatPlugin, + var: *const libc::c_char) -> libc::c_int, + pub hexchat_pluginpref_list: unsafe extern "C" fn(ph: *mut HexchatPlugin, + dest: *mut char) -> libc::c_int, + pub hexchat_hook_server_attrs: unsafe extern "C" fn(ph: *mut HexchatPlugin, name: *const libc::c_char, pri: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_hook_print_attrs: Option *const HexchatHook, + pub hexchat_hook_print_attrs: unsafe extern "C" fn(ph: *mut HexchatPlugin, name: *const libc::c_char, pri: libc::c_int, /* CALLBACK */ callback: Option libc::c_int>, - userdata: *mut libc::c_void) -> *const HexchatHook>, - pub hexchat_emit_print_attrs: Option libc::c_int>, - pub hexchat_event_attrs_create: Option *mut HexchatEventAttrs>, - pub hexchat_event_attrs_free: Option, + userdata: *mut libc::c_void) -> *const HexchatHook, + pub hexchat_emit_print_attrs: unsafe extern "C" fn(ph: *mut HexchatPlugin, attrs: *const HexchatEventAttrs, + event_name: *const libc::c_char, ...) -> libc::c_int, + pub hexchat_event_attrs_create: unsafe extern "C" fn(ph: *mut HexchatPlugin) -> *mut HexchatEventAttrs, + pub hexchat_event_attrs_free: unsafe extern "C" fn(ph: *mut HexchatPlugin, + attrs: *const HexchatEventAttrs), } -- cgit 1.4.1