mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
core: add pointer in some callbacks (closes #406)
This pointer is the first argument received by callbacks, and the existing argument "data" is now automatically freed by WeeChat when the object containing the callback is removed. With this new pointer, the linked list of callbacks in scripts has been removed. This will improve speed of scripts (using a lot of hooks), reduce memory used by scripts and reduce time to unload scripts. Following functions are affected in the C API: * exec_on_files * config_new * config_new_section * config_new_option * hook_command * hook_command_run * hook_timer * hook_fd * hook_process * hook_process_hashtable * hook_connect * hook_print * hook_signal * hook_hsignal * hook_config * hook_completion * hook_modifier * hook_info * hook_info_hashtable * hook_infolist * hook_hdata * hook_focus * unhook_all_plugin * buffer_new * bar_item_new * upgrade_new * upgrade_read
This commit is contained in:
@@ -35,13 +35,15 @@
|
||||
*/
|
||||
|
||||
int
|
||||
exec_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
|
||||
exec_buffer_input_cb (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer,
|
||||
const char *input_data)
|
||||
{
|
||||
char **argv, **argv_eol;
|
||||
int argc;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
/* close buffer */
|
||||
@@ -70,12 +72,14 @@ exec_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
|
||||
*/
|
||||
|
||||
int
|
||||
exec_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
|
||||
exec_buffer_close_cb (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer)
|
||||
{
|
||||
const char *full_name;
|
||||
struct t_exec_cmd *ptr_exec_cmd;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
/* kill any command whose output is on this buffer */
|
||||
@@ -153,8 +157,8 @@ exec_buffer_new (const char *name, int free_content, int clear_buffer,
|
||||
}
|
||||
|
||||
new_buffer = weechat_buffer_new (name,
|
||||
&exec_buffer_input_cb, NULL,
|
||||
&exec_buffer_close_cb, NULL);
|
||||
&exec_buffer_input_cb, NULL, NULL,
|
||||
&exec_buffer_close_cb, NULL, NULL);
|
||||
|
||||
/* failed to create buffer ? then return */
|
||||
if (!new_buffer)
|
||||
|
||||
@@ -458,8 +458,7 @@ exec_command_run (struct t_gui_buffer *buffer,
|
||||
process_options = weechat_hashtable_new (32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
NULL, NULL);
|
||||
if (!process_options)
|
||||
{
|
||||
exec_free (new_exec_cmd);
|
||||
@@ -570,7 +569,8 @@ exec_command_run (struct t_gui_buffer *buffer,
|
||||
process_options,
|
||||
cmd_options.timeout * 1000,
|
||||
&exec_process_cb,
|
||||
new_exec_cmd);
|
||||
new_exec_cmd,
|
||||
NULL);
|
||||
|
||||
if (new_exec_cmd->hook)
|
||||
{
|
||||
@@ -605,7 +605,8 @@ exec_command_run (struct t_gui_buffer *buffer,
|
||||
*/
|
||||
|
||||
int
|
||||
exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
exec_command_exec (const void *pointer, void *data,
|
||||
struct t_gui_buffer *buffer, int argc,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
int i, length, count;
|
||||
@@ -613,6 +614,7 @@ exec_command_exec (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
struct t_exec_cmd *ptr_exec_cmd, *ptr_next_exec_cmd;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
@@ -878,5 +880,5 @@ exec_command_init ()
|
||||
" || -killall"
|
||||
" || -set %(exec_commands_ids) stdin|stdin_close|signal"
|
||||
" || -del %(exec_commands_ids)|-all %(exec_commands_ids)|%*",
|
||||
&exec_command_exec, NULL);
|
||||
&exec_command_exec, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
*/
|
||||
|
||||
int
|
||||
exec_completion_commands_ids_cb (void *data, const char *completion_item,
|
||||
exec_completion_commands_ids_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
@@ -40,6 +41,7 @@ exec_completion_commands_ids_cb (void *data, const char *completion_item,
|
||||
char str_number[32];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
@@ -69,5 +71,5 @@ exec_completion_init ()
|
||||
{
|
||||
weechat_hook_completion ("exec_commands_ids",
|
||||
N_("ids (numbers and names) of executed commands"),
|
||||
&exec_completion_commands_ids_cb, NULL);
|
||||
&exec_completion_commands_ids_cb, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -49,10 +49,11 @@ int exec_config_cmd_num_options = 0;
|
||||
*/
|
||||
|
||||
void
|
||||
exec_config_change_command_default_options (void *data,
|
||||
exec_config_change_command_default_options (const void *pointer, void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
@@ -69,9 +70,11 @@ exec_config_change_command_default_options (void *data,
|
||||
*/
|
||||
|
||||
int
|
||||
exec_config_reload_cb (void *data, struct t_config_file *config_file)
|
||||
exec_config_reload_cb (const void *pointer, void *data,
|
||||
struct t_config_file *config_file)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
|
||||
return weechat_config_reload (config_file);
|
||||
@@ -91,16 +94,18 @@ exec_config_init ()
|
||||
struct t_config_section *ptr_section;
|
||||
|
||||
exec_config_file = weechat_config_new (EXEC_CONFIG_NAME,
|
||||
&exec_config_reload_cb, NULL);
|
||||
&exec_config_reload_cb, NULL, NULL);
|
||||
if (!exec_config_file)
|
||||
return 0;
|
||||
|
||||
/* command */
|
||||
ptr_section = weechat_config_new_section (exec_config_file, "command",
|
||||
0, 0,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
if (!ptr_section)
|
||||
{
|
||||
weechat_config_free (exec_config_file);
|
||||
@@ -113,22 +118,26 @@ exec_config_init ()
|
||||
N_("default options for command /exec (see /help exec); example: "
|
||||
"\"-nosh -bg\" to run all commands in background (no output), and "
|
||||
"without using the shell"),
|
||||
NULL, 0, 0, "", NULL, 0, NULL, NULL,
|
||||
&exec_config_change_command_default_options, NULL, NULL, NULL);
|
||||
NULL, 0, 0, "", NULL, 0,
|
||||
NULL, NULL, NULL,
|
||||
&exec_config_change_command_default_options, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
exec_config_command_purge_delay = weechat_config_new_option (
|
||||
exec_config_file, ptr_section,
|
||||
"purge_delay", "integer",
|
||||
N_("delay for purging finished commands (in seconds, 0 = purge "
|
||||
"commands immediately, -1 = never purge)"),
|
||||
NULL, -1, 36000 * 24 * 30, "0", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
/* color */
|
||||
ptr_section = weechat_config_new_section (exec_config_file, "color",
|
||||
0, 0,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
if (!ptr_section)
|
||||
{
|
||||
weechat_config_free (exec_config_file);
|
||||
@@ -140,13 +149,13 @@ exec_config_init ()
|
||||
"flag_running", "color",
|
||||
N_("text color for a running command flag in list of commands"),
|
||||
NULL, 0, 0, "lightgreen", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
exec_config_color_flag_finished = weechat_config_new_option (
|
||||
exec_config_file, ptr_section,
|
||||
"flag_finished", "color",
|
||||
N_("text color for a finished command flag in list of commands"),
|
||||
NULL, 0, 0, "lightred", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
+13
-10
@@ -175,14 +175,15 @@ exec_add ()
|
||||
*/
|
||||
|
||||
int
|
||||
exec_timer_delete_cb (void *data, int remaining_calls)
|
||||
exec_timer_delete_cb (const void *pointer, void *data, int remaining_calls)
|
||||
{
|
||||
struct t_exec_cmd *exec_cmd, *ptr_exec_cmd;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) remaining_calls;
|
||||
|
||||
exec_cmd = (struct t_exec_cmd *)data;
|
||||
exec_cmd = (struct t_exec_cmd *)pointer;
|
||||
if (!exec_cmd)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
@@ -424,8 +425,7 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
|
||||
hashtable = weechat_hashtable_new (32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL,
|
||||
NULL);
|
||||
NULL, NULL);
|
||||
if (hashtable)
|
||||
{
|
||||
weechat_hashtable_set (hashtable, "command", exec_cmd->command);
|
||||
@@ -526,7 +526,7 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
|
||||
{
|
||||
weechat_hook_timer (1 + (1000 * weechat_config_integer (exec_config_command_purge_delay)),
|
||||
0, 1,
|
||||
&exec_timer_delete_cb, exec_cmd);
|
||||
&exec_timer_delete_cb, exec_cmd, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,16 +535,17 @@ exec_end_command (struct t_exec_cmd *exec_cmd, int return_code)
|
||||
*/
|
||||
|
||||
int
|
||||
exec_process_cb (void *data, const char *command, int return_code,
|
||||
const char *out, const char *err)
|
||||
exec_process_cb (const void *pointer, void *data, const char *command,
|
||||
int return_code, const char *out, const char *err)
|
||||
{
|
||||
struct t_exec_cmd *ptr_exec_cmd;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) command;
|
||||
|
||||
ptr_exec_cmd = (struct t_exec_cmd *)data;
|
||||
ptr_exec_cmd = (struct t_exec_cmd *)pointer;
|
||||
if (!ptr_exec_cmd)
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
@@ -681,10 +682,12 @@ exec_print_log ()
|
||||
*/
|
||||
|
||||
int
|
||||
exec_debug_dump_cb (void *data, const char *signal, const char *type_data,
|
||||
exec_debug_dump_cb (const void *pointer, void *data,
|
||||
const char *signal, const char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
@@ -725,7 +728,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
exec_config_read ();
|
||||
|
||||
/* hook some signals */
|
||||
weechat_hook_signal ("debug_dump", &exec_debug_dump_cb, NULL);
|
||||
weechat_hook_signal ("debug_dump", &exec_debug_dump_cb, NULL, NULL);
|
||||
|
||||
/* hook completions */
|
||||
exec_completion_init ();
|
||||
|
||||
@@ -80,7 +80,8 @@ extern int exec_cmds_count;
|
||||
extern int exec_search_color (const char *color);
|
||||
extern struct t_exec_cmd *exec_search_by_id (const char *id);
|
||||
extern struct t_exec_cmd *exec_add ();
|
||||
extern int exec_process_cb (void *data, const char *command, int return_code,
|
||||
extern int exec_process_cb (const void *pointer, void *data,
|
||||
const char *command, int return_code,
|
||||
const char *out, const char *err);
|
||||
extern void exec_free (struct t_exec_cmd *exec_cmd);
|
||||
extern void exec_free_all ();
|
||||
|
||||
Reference in New Issue
Block a user