summaryrefslogtreecommitdiff
path: root/src/plugins/alias
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2016-03-21 18:11:21 +0100
committerSébastien Helleu <flashcode@flashtux.org>2016-03-21 18:11:21 +0100
commitcf6aca1619c32422a43fa3d82e0674f6b7b49fe9 (patch)
tree65392ef12eab877f544fe306fe0abb98214ddebd /src/plugins/alias
parent6d764b64c50adb19309a9de14bfeafac648ab47a (diff)
downloadweechat-cf6aca1619c32422a43fa3d82e0674f6b7b49fe9.zip
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
Diffstat (limited to 'src/plugins/alias')
-rw-r--r--src/plugins/alias/alias-command.c6
-rw-r--r--src/plugins/alias/alias-completion.c12
-rw-r--r--src/plugins/alias/alias-config.c76
-rw-r--r--src/plugins/alias/alias-info.c14
-rw-r--r--src/plugins/alias/alias.c8
5 files changed, 71 insertions, 45 deletions
diff --git a/src/plugins/alias/alias-command.c b/src/plugins/alias/alias-command.c
index 59975387d..f492faaa5 100644
--- a/src/plugins/alias/alias-command.c
+++ b/src/plugins/alias/alias-command.c
@@ -76,7 +76,8 @@ alias_command_add (const char *alias_name, const char *command,
*/
int
-alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
+alias_command_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
char *ptr_alias_name;
@@ -85,6 +86,7 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
int alias_found, i;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) buffer;
@@ -287,5 +289,5 @@ alias_command_init ()
" || add %(alias) %(commands)|%(alias_value)"
" || addcompletion %- %(alias) %(commands)|%(alias_value)"
" || del %(alias)|%*",
- &alias_command_cb, NULL);
+ &alias_command_cb, NULL, NULL);
}
diff --git a/src/plugins/alias/alias-completion.c b/src/plugins/alias/alias-completion.c
index 42e3a553e..fd90b1c5d 100644
--- a/src/plugins/alias/alias-completion.c
+++ b/src/plugins/alias/alias-completion.c
@@ -32,13 +32,15 @@
*/
int
-alias_completion_alias_cb (void *data, const char *completion_item,
+alias_completion_alias_cb (const void *pointer, void *data,
+ const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) completion_item;
(void) buffer;
@@ -58,7 +60,8 @@ alias_completion_alias_cb (void *data, const char *completion_item,
*/
int
-alias_completion_alias_value_cb (void *data, const char *completion_item,
+alias_completion_alias_value_cb (const void *pointer, void *data,
+ const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
@@ -68,6 +71,7 @@ alias_completion_alias_value_cb (void *data, const char *completion_item,
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) completion_item;
(void) buffer;
@@ -110,7 +114,7 @@ void
alias_completion_init ()
{
weechat_hook_completion ("alias", N_("list of aliases"),
- &alias_completion_alias_cb, NULL);
+ &alias_completion_alias_cb, NULL, NULL);
weechat_hook_completion ("alias_value", N_("value of alias"),
- &alias_completion_alias_value_cb, NULL);
+ &alias_completion_alias_value_cb, NULL, NULL);
}
diff --git a/src/plugins/alias/alias-config.c b/src/plugins/alias/alias-config.c
index 9a2128b39..1ad8780c3 100644
--- a/src/plugins/alias/alias-config.c
+++ b/src/plugins/alias/alias-config.c
@@ -78,11 +78,13 @@ char *alias_default_completion[][2] =
*/
void
-alias_config_cmd_change_cb (void *data, struct t_config_option *option)
+alias_config_cmd_change_cb (const void *pointer, void *data,
+ struct t_config_option *option)
{
struct t_config_option *ptr_option_completion;
/* make C compiler happy */
+ (void) pointer;
(void) data;
ptr_option_completion = weechat_config_search_option (alias_config_file,
@@ -100,12 +102,14 @@ alias_config_cmd_change_cb (void *data, struct t_config_option *option)
*/
void
-alias_config_cmd_delete_cb (void *data, struct t_config_option *option)
+alias_config_cmd_delete_cb (const void *pointer, void *data,
+ struct t_config_option *option)
{
struct t_config_option *ptr_option_completion;
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
ptr_option_completion = weechat_config_search_option (alias_config_file,
@@ -125,11 +129,13 @@ alias_config_cmd_delete_cb (void *data, struct t_config_option *option)
*/
void
-alias_config_completion_change_cb (void *data, struct t_config_option *option)
+alias_config_completion_change_cb (const void *pointer, void *data,
+ struct t_config_option *option)
{
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
ptr_alias = alias_search (weechat_config_option_get_pointer (option, "name"));
@@ -145,11 +151,13 @@ alias_config_completion_change_cb (void *data, struct t_config_option *option)
*/
void
-alias_config_completion_delete_cb (void *data, struct t_config_option *option)
+alias_config_completion_delete_cb (const void *pointer, void *data,
+ struct t_config_option *option)
{
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
ptr_alias = alias_search (weechat_config_option_get_pointer (option, "name"));
@@ -164,9 +172,11 @@ alias_config_completion_delete_cb (void *data, struct t_config_option *option)
*/
int
-alias_config_reload (void *data, struct t_config_file *config_file)
+alias_config_reload (const void *pointer, void *data,
+ struct t_config_file *config_file)
{
/* make C compiler happy */
+ (void) pointer;
(void) data;
weechat_config_section_free_options (alias_config_section_cmd);
@@ -181,13 +191,14 @@ alias_config_reload (void *data, struct t_config_file *config_file)
*/
int
-alias_config_cmd_write_default_cb (void *data,
+alias_config_cmd_write_default_cb (const void *pointer, void *data,
struct t_config_file *config_file,
const char *section_name)
{
int i;
/* make C compiler happy */
+ (void) pointer;
(void) data;
if (!weechat_config_write_line (config_file, section_name, NULL))
@@ -214,9 +225,9 @@ alias_config_cmd_new_option (const char *name, const char *command)
weechat_config_new_option (alias_config_file, alias_config_section_cmd,
name, "string", NULL,
NULL, 0, 0, NULL, command, 0,
- NULL, NULL,
- &alias_config_cmd_change_cb, NULL,
- &alias_config_cmd_delete_cb, NULL);
+ NULL, NULL, NULL,
+ &alias_config_cmd_change_cb, NULL, NULL,
+ &alias_config_cmd_delete_cb, NULL, NULL);
}
/*
@@ -224,7 +235,7 @@ alias_config_cmd_new_option (const char *name, const char *command)
*/
int
-alias_config_cmd_create_option_cb (void *data,
+alias_config_cmd_create_option_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name, const char *value)
@@ -233,6 +244,7 @@ alias_config_cmd_create_option_cb (void *data,
int rc;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) config_file;
(void) section;
@@ -266,13 +278,14 @@ alias_config_cmd_create_option_cb (void *data,
*/
int
-alias_config_completion_write_default_cb (void *data,
+alias_config_completion_write_default_cb (const void *pointer, void *data,
struct t_config_file *config_file,
const char *section_name)
{
int i;
/* make C compiler happy */
+ (void) pointer;
(void) data;
if (!weechat_config_write_line (config_file, section_name, NULL))
@@ -300,9 +313,9 @@ alias_config_completion_new_option (const char *name, const char *completion)
alias_config_section_completion,
name, "string", NULL,
NULL, 0, 0, NULL, completion, 0,
- NULL, NULL,
- &alias_config_completion_change_cb, NULL,
- &alias_config_completion_delete_cb, NULL);
+ NULL, NULL, NULL,
+ &alias_config_completion_change_cb, NULL, NULL,
+ &alias_config_completion_delete_cb, NULL, NULL);
}
/*
@@ -310,7 +323,7 @@ alias_config_completion_new_option (const char *name, const char *completion)
*/
int
-alias_config_completion_create_option_cb (void *data,
+alias_config_completion_create_option_cb (const void *pointer, void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
@@ -319,6 +332,7 @@ alias_config_completion_create_option_cb (void *data,
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) config_file;
(void) section;
@@ -357,18 +371,19 @@ alias_config_init ()
struct t_config_section *ptr_section;
alias_config_file = weechat_config_new (ALIAS_CONFIG_NAME,
- &alias_config_reload, NULL);
+ &alias_config_reload, NULL, NULL);
if (!alias_config_file)
return 0;
/* cmd */
- ptr_section = weechat_config_new_section (alias_config_file, "cmd",
- 1, 1,
- NULL, NULL,
- NULL, NULL,
- &alias_config_cmd_write_default_cb, NULL,
- &alias_config_cmd_create_option_cb, NULL,
- NULL, NULL);
+ ptr_section = weechat_config_new_section (
+ alias_config_file, "cmd",
+ 1, 1,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ &alias_config_cmd_write_default_cb, NULL, NULL,
+ &alias_config_cmd_create_option_cb, NULL, NULL,
+ NULL, NULL, NULL);
if (!ptr_section)
{
weechat_config_free (alias_config_file);
@@ -377,13 +392,14 @@ alias_config_init ()
alias_config_section_cmd = ptr_section;
/* completion */
- ptr_section = weechat_config_new_section (alias_config_file, "completion",
- 1, 1,
- NULL, NULL,
- NULL, NULL,
- &alias_config_completion_write_default_cb, NULL,
- &alias_config_completion_create_option_cb, NULL,
- NULL, NULL);
+ ptr_section = weechat_config_new_section (
+ alias_config_file, "completion",
+ 1, 1,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ &alias_config_completion_write_default_cb, NULL, NULL,
+ &alias_config_completion_create_option_cb, NULL, NULL,
+ NULL, NULL, NULL);
if (!ptr_section)
{
weechat_config_free (alias_config_file);
diff --git a/src/plugins/alias/alias-info.c b/src/plugins/alias/alias-info.c
index 600f0c8c2..484c6082b 100644
--- a/src/plugins/alias/alias-info.c
+++ b/src/plugins/alias/alias-info.c
@@ -30,28 +30,30 @@
*/
struct t_infolist *
-alias_info_infolist_alias_cb (void *data, const char *infolist_name,
- void *pointer, const char *arguments)
+alias_info_infolist_alias_cb (const void *pointer, void *data,
+ const char *infolist_name,
+ void *obj_pointer, const char *arguments)
{
struct t_infolist *ptr_infolist;
struct t_alias *ptr_alias;
/* make C compiler happy */
+ (void) pointer;
(void) data;
(void) infolist_name;
(void) arguments;
- if (pointer && !alias_valid (pointer))
+ if (obj_pointer && !alias_valid (obj_pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (!ptr_infolist)
return NULL;
- if (pointer)
+ if (obj_pointer)
{
/* build list with only one alias */
- if (!alias_add_to_infolist (ptr_infolist, pointer))
+ if (!alias_add_to_infolist (ptr_infolist, obj_pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
@@ -90,5 +92,5 @@ alias_info_init ()
"alias", N_("list of aliases"),
N_("alias pointer (optional)"),
N_("alias name (wildcard \"*\" is allowed) (optional)"),
- &alias_info_infolist_alias_cb, NULL);
+ &alias_info_infolist_alias_cb, NULL, NULL);
}
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index db02f987c..961748757 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -337,7 +337,8 @@ alias_run_command (struct t_gui_buffer **buffer, const char *command)
*/
int
-alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
+alias_cb (const void *pointer, void *data,
+ struct t_gui_buffer *buffer, int argc, char **argv,
char **argv_eol)
{
struct t_alias *ptr_alias;
@@ -346,9 +347,10 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv,
int some_args_replaced, length1, length2;
/* make C compiler happy */
+ (void) data;
(void) argv;
- ptr_alias = (struct t_alias *)data;
+ ptr_alias = (struct t_alias *)pointer;
if (ptr_alias->running)
{
@@ -545,7 +547,7 @@ alias_hook_command (struct t_alias *alias)
alias->command,
NULL, NULL,
(str_completion) ? str_completion : alias->completion,
- &alias_cb, alias);
+ &alias_cb, alias, NULL);
if (str_priority_name)
free (str_priority_name);