1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 08:43:13 +02:00

api: add argument "flags" in function hdata_new_list

This commit is contained in:
Sébastien Helleu
2014-05-24 18:03:14 +02:00
parent 3092c09bc9
commit 7aaf3be15b
25 changed files with 236 additions and 91 deletions
+2 -2
View File
@@ -2718,8 +2718,8 @@ config_file_hdata_config_file_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_config_file, last_section, POINTER, 0, NULL, "config_section");
HDATA_VAR(struct t_config_file, prev_config, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_config_file, next_config, POINTER, 0, NULL, hdata_name);
HDATA_LIST(config_files);
HDATA_LIST(last_config_file);
HDATA_LIST(config_files, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_config_file, 0);
}
return hdata;
}
+112 -9
View File
@@ -72,6 +72,21 @@ hdata_free_var (struct t_hashtable *hashtable,
}
}
/*
* Frees a hdata list.
*/
void
hdata_free_list (struct t_hashtable *hashtable,
const void *key, void *value)
{
/* make C compiler happy */
(void) hashtable;
(void) key;
free (value);
}
/*
* Creates a new hdata.
*
@@ -111,6 +126,7 @@ hdata_new (struct t_weechat_plugin *plugin, const char *hdata_name,
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
new_hdata->hash_list->callback_free_value = &hdata_free_list;
hashtable_set (weechat_hdata, hdata_name, new_hdata);
new_hdata->create_allowed = create_allowed;
new_hdata->delete_allowed = delete_allowed;
@@ -153,12 +169,21 @@ hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type,
*/
void
hdata_new_list (struct t_hdata *hdata, const char *name, void *pointer)
hdata_new_list (struct t_hdata *hdata, const char *name, void *pointer,
int flags)
{
struct t_hdata_list *list;
if (!hdata || !name)
return;
hashtable_set (hdata->hash_list, name, pointer);
list = malloc (sizeof (*list));
if (list)
{
list->pointer = pointer;
list->flags = flags;
hashtable_set (hdata->hash_list, name, list);
}
}
/*
@@ -399,20 +424,20 @@ hdata_get_var_at_offset (struct t_hdata *hdata, void *pointer, int offset)
void *
hdata_get_list (struct t_hdata *hdata, const char *name)
{
void *ptr_value;
struct t_hdata_list *ptr_list;
if (!hdata || !name)
return NULL;
ptr_value = hashtable_get (hdata->hash_list, name);
if (ptr_value)
return *((void **)ptr_value);
ptr_list = hashtable_get (hdata->hash_list, name);
if (ptr_list)
return *((void **)(ptr_list->pointer));
return NULL;
}
/*
* Checks if a pointer is valid for a given hdata/list.
* Checks if a pointer is in the list.
*
* Returns:
* 1: pointer exists in list
@@ -420,15 +445,16 @@ hdata_get_list (struct t_hdata *hdata, const char *name)
*/
int
hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer)
hdata_check_pointer_in_list (struct t_hdata *hdata, void *list, void *pointer)
{
void *ptr_current;
if (!hdata || !list || !pointer)
if (!hdata || !pointer)
return 0;
if (pointer == list)
return 1;
ptr_current = list;
while (ptr_current)
{
@@ -440,6 +466,83 @@ hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer)
return 0;
}
/*
* Checks if a pointer is in a list with flag "check_pointers".
*/
void
hdata_check_pointer_map_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
void **pointers, *pointer, **num_lists, **found;
struct t_hdata *ptr_hdata;
struct t_hdata_list *ptr_list;
/* make C compiler happy */
(void) hashtable;
(void) key;
pointers = (void **)data;
ptr_hdata = pointers[0];
pointer = pointers[1];
num_lists = &pointers[2];
found = &pointers[3];
/* pointer already found in another list? just exit */
if (*found)
return;
ptr_list = (struct t_hdata_list *)value;
if (!ptr_list || !(ptr_list->flags & WEECHAT_HDATA_LIST_CHECK_POINTERS))
return;
*found = (void *)((unsigned long int)hdata_check_pointer_in_list (
ptr_hdata,
*((void **)(ptr_list->pointer)),
pointer));
(*num_lists)++;
}
/*
* Checks if a pointer is valid for a given hdata/list.
*
* If argument "list" is NULL, the check is made with all lists in hdata
* that have flag "check_pointers". If no list is defined with this flag,
* the pointer is considered valid (so this function returns 1); if the
* pointer is not found in any list, this function returns 0.
*
* Returns:
* 1: pointer exists in the given list (or a list with check_pointers flag)
* 0: pointer does not exist
*/
int
hdata_check_pointer (struct t_hdata *hdata, void *list, void *pointer)
{
void *pointers[4];
if (!hdata || !pointer)
return 0;
if (list)
{
/* search pointer in the given list */
return hdata_check_pointer_in_list (hdata, list, pointer);
}
else
{
/* search pointer in all lists with flag "check_pointers" */
pointers[0] = hdata;
pointers[1] = pointer;
pointers[2] = 0; /* number of lists with flag check_pointers */
pointers[3] = 0; /* pointer found? (0/1) */
hashtable_map (hdata->hash_list,
&hdata_check_pointer_map_cb,
pointers);
return ((pointers[2] == 0) || pointers[3]) ? 1 : 0;
}
}
/*
* Moves pointer to another element in list.
*/
+9 -2
View File
@@ -25,7 +25,8 @@
hdata_new_var (hdata, #__name, offsetof (__struct, __name), \
WEECHAT_HDATA_##__type, __update_allowed, \
__array_size, __hdata_name)
#define HDATA_LIST(__name) hdata_new_list (hdata, #__name, &(__name));
#define HDATA_LIST(__name, __flags) \
hdata_new_list (hdata, #__name, &(__name), __flags);
struct t_hdata_var
{
@@ -36,6 +37,12 @@ struct t_hdata_var
char *hdata_name; /* hdata name */
};
struct t_hdata_list
{
void *pointer; /* list pointer */
int flags; /* flags for list */
};
struct t_hdata
{
char *name; /* name of hdata */
@@ -79,7 +86,7 @@ extern void hdata_new_var (struct t_hdata *hdata, const char *name, int offset,
int type, int update_allowed, const char *array_size,
const char *hdata_name);
extern void hdata_new_list (struct t_hdata *hdata, const char *name,
void *pointer);
void *pointer, int flags);
extern int hdata_get_var_offset (struct t_hdata *hdata, const char *name);
extern int hdata_get_var_type (struct t_hdata *hdata, const char *name);
extern const char *hdata_get_var_type_string (struct t_hdata *hdata,
+2 -2
View File
@@ -636,8 +636,8 @@ proxy_hdata_proxy_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_proxy, options, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_proxy, prev_proxy, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_proxy, next_proxy, POINTER, 0, NULL, hdata_name);
HDATA_LIST(weechat_proxies);
HDATA_LIST(last_weechat_proxy);
HDATA_LIST(weechat_proxies, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_weechat_proxy, 0);
}
return hdata;
}
+2 -2
View File
@@ -2174,8 +2174,8 @@ gui_bar_item_hdata_bar_item_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_bar_item, build_callback_data, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_bar_item, prev_item, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_bar_item, next_item, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_bar_items);
HDATA_LIST(last_gui_bar_item);
HDATA_LIST(gui_bar_items, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_bar_item, 0);
}
return hdata;
}
+2 -2
View File
@@ -2280,8 +2280,8 @@ gui_bar_hdata_bar_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_bar, bar_refresh_needed, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_bar, prev_bar, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_bar, next_bar, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_bars);
HDATA_LIST(last_gui_bar);
HDATA_LIST(gui_bars, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_bar, 0);
}
return hdata;
}
+5 -5
View File
@@ -4024,9 +4024,9 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_buffer, local_variables, HASHTABLE, 0, NULL, NULL);
HDATA_VAR(struct t_gui_buffer, prev_buffer, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_buffer, next_buffer, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_buffers);
HDATA_LIST(last_gui_buffer);
HDATA_LIST(gui_buffer_last_displayed);
HDATA_LIST(gui_buffers, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_buffer, 0);
HDATA_LIST(gui_buffer_last_displayed, 0);
}
return hdata;
}
@@ -4074,8 +4074,8 @@ gui_buffer_hdata_buffer_visited_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_buffer_visited, buffer, POINTER, 0, NULL, "buffer");
HDATA_VAR(struct t_gui_buffer_visited, prev_buffer, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_buffer_visited, next_buffer, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_buffers_visited);
HDATA_LIST(last_gui_buffer_visited);
HDATA_LIST(gui_buffers_visited, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_buffer_visited, 0);
}
return hdata;
}
+2 -2
View File
@@ -516,8 +516,8 @@ gui_filter_hdata_filter_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_filter, regex_message, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_filter, prev_filter, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_filter, next_filter, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_filters);
HDATA_LIST(last_gui_filter);
HDATA_LIST(gui_filters, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_filter, 0);
}
return hdata;
}
+2 -2
View File
@@ -291,8 +291,8 @@ gui_history_hdata_history_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_history, text, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_history, prev_history, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_history, next_history, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_history);
HDATA_LIST(last_gui_history);
HDATA_LIST(gui_history, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_history, 0);
}
return hdata;
}
+2 -2
View File
@@ -540,8 +540,8 @@ gui_hotlist_hdata_hotlist_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_hotlist, count, INTEGER, 0, GUI_HOTLIST_NUM_PRIORITIES_STR, NULL);
HDATA_VAR(struct t_gui_hotlist, prev_hotlist, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_hotlist, next_hotlist, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_hotlist);
HDATA_LIST(last_gui_hotlist);
HDATA_LIST(gui_hotlist, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_hotlist, 0);
}
return hdata;
}
+4 -4
View File
@@ -1871,22 +1871,22 @@ gui_key_hdata_key_cb (void *data, const char *hdata_name)
"gui_keys%s%s",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
hdata_new_list(hdata, str_list, &gui_keys[i]);
hdata_new_list(hdata, str_list, &gui_keys[i], 0);
snprintf (str_list, sizeof (str_list),
"last_gui_key%s%s",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
hdata_new_list(hdata, str_list, &last_gui_key[i]);
hdata_new_list(hdata, str_list, &last_gui_key[i], 0);
snprintf (str_list, sizeof (str_list),
"gui_default_keys%s%s",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
hdata_new_list(hdata, str_list, &gui_default_keys[i]);
hdata_new_list(hdata, str_list, &gui_default_keys[i], 0);
snprintf (str_list, sizeof (str_list),
"last_gui_default_key%s%s",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : "_",
(i == GUI_KEY_CONTEXT_DEFAULT) ? "" : gui_key_context_string[i]);
hdata_new_list(hdata, str_list, &last_gui_default_key[i]);
hdata_new_list(hdata, str_list, &last_gui_default_key[i], 0);
}
}
return hdata;
+3 -3
View File
@@ -954,9 +954,9 @@ gui_layout_hdata_layout_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_layout, internal_id_current_window, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_layout, prev_layout, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_layout, next_layout, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_layouts);
HDATA_LIST(last_gui_layout);
HDATA_LIST(gui_layout_current);
HDATA_LIST(gui_layouts, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_layout, 0);
HDATA_LIST(gui_layout_current, 0);
}
return hdata;
}
+4 -4
View File
@@ -1760,9 +1760,9 @@ gui_window_hdata_window_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_window, ptr_tree, POINTER, 0, NULL, "window_tree");
HDATA_VAR(struct t_gui_window, prev_window, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_window, next_window, POINTER, 0, NULL, hdata_name);
HDATA_LIST(gui_windows);
HDATA_LIST(last_gui_window);
HDATA_LIST(gui_current_window);
HDATA_LIST(gui_windows, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_gui_window, 0);
HDATA_LIST(gui_current_window, 0);
}
return hdata;
}
@@ -1817,7 +1817,7 @@ gui_window_hdata_window_tree_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_window_tree, child1, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_window_tree, child2, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_window_tree, window, POINTER, 0, NULL, "window");
HDATA_LIST(gui_windows_tree);
HDATA_LIST(gui_windows_tree, 0);
}
return hdata;
}
+2 -2
View File
@@ -326,8 +326,8 @@ irc_ignore_hdata_ignore_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_ignore, channel, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_ignore, prev_ignore, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_irc_ignore, next_ignore, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(irc_ignore_list);
WEECHAT_HDATA_LIST(last_irc_ignore);
WEECHAT_HDATA_LIST(irc_ignore_list, WEECHAT_HDATA_LIST_CHECK_POINTERS);
WEECHAT_HDATA_LIST(last_irc_ignore, 0);
}
return hdata;
}
+2 -2
View File
@@ -1007,8 +1007,8 @@ irc_redirect_hdata_redirect_pattern_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_redirect_pattern, cmd_extra, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_redirect_pattern, prev_redirect, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_irc_redirect_pattern, next_redirect, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(irc_redirect_patterns);
WEECHAT_HDATA_LIST(last_irc_redirect_pattern);
WEECHAT_HDATA_LIST(irc_redirect_patterns, WEECHAT_HDATA_LIST_CHECK_POINTERS);
WEECHAT_HDATA_LIST(last_irc_redirect_pattern, 0);
}
return hdata;
}
+2 -2
View File
@@ -4904,8 +4904,8 @@ irc_server_hdata_server_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_server, last_channel, POINTER, 0, NULL, "irc_channel");
WEECHAT_HDATA_VAR(struct t_irc_server, prev_server, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_irc_server, next_server, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(irc_servers);
WEECHAT_HDATA_LIST(last_irc_server);
WEECHAT_HDATA_LIST(irc_servers, WEECHAT_HDATA_LIST_CHECK_POINTERS);
WEECHAT_HDATA_LIST(last_irc_server, 0);
}
return hdata;
}
+3 -2
View File
@@ -1380,8 +1380,9 @@ plugin_script_hdata_script (struct t_weechat_plugin *weechat_plugin,
WEECHAT_HDATA_VAR(struct t_plugin_script, unloading, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_plugin_script, prev_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_plugin_script, next_script, POINTER, 0, NULL, hdata_name);
weechat_hdata_new_list (hdata, "scripts", scripts);
weechat_hdata_new_list (hdata, "last_script", last_script);
weechat_hdata_new_list (hdata, "scripts", scripts,
WEECHAT_HDATA_LIST_CHECK_POINTERS);
weechat_hdata_new_list (hdata, "last_script", last_script, 0);
}
return hdata;
}
+2 -2
View File
@@ -1247,8 +1247,8 @@ plugin_hdata_plugin_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_weechat_plugin, debug, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_weechat_plugin, prev_plugin, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_weechat_plugin, next_plugin, POINTER, 0, NULL, hdata_name);
HDATA_LIST(weechat_plugins);
HDATA_LIST(last_weechat_plugin);
HDATA_LIST(weechat_plugins, WEECHAT_HDATA_LIST_CHECK_POINTERS);
HDATA_LIST(last_weechat_plugin, 0);
}
return hdata;
}
+2 -2
View File
@@ -1520,8 +1520,8 @@ script_repo_hdata_script_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_script_repo, install_order, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_script_repo, prev_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_VAR(struct t_script_repo, next_script, POINTER, 0, NULL, hdata_name);
WEECHAT_HDATA_LIST(scripts_repo);
WEECHAT_HDATA_LIST(last_script_repo);
WEECHAT_HDATA_LIST(scripts_repo, WEECHAT_HDATA_LIST_CHECK_POINTERS);
WEECHAT_HDATA_LIST(last_script_repo, 0);
}
return hdata;
}
+9 -6
View File
@@ -57,7 +57,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20140313-01"
#define WEECHAT_PLUGIN_API_VERSION "20140524-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -125,6 +125,9 @@ struct timeval;
#define WEECHAT_HDATA_HASHTABLE 7
#define WEECHAT_HDATA_SHARED_STRING 8
/* flags for hdata lists */
#define WEECHAT_HDATA_LIST_CHECK_POINTERS 1
/* buffer hotlist */
#define WEECHAT_HOTLIST_LOW "0"
#define WEECHAT_HOTLIST_MESSAGE "1"
@@ -879,7 +882,7 @@ struct t_weechat_plugin
int type, int update_allowed, const char *array_size,
const char *hdata_name);
void (*hdata_new_list) (struct t_hdata *hdata, const char *name,
void *pointer);
void *pointer, int flags);
struct t_hdata *(*hdata_get) (struct t_weechat_plugin *plugin,
const char *hdata_name);
int (*hdata_get_var_offset) (struct t_hdata *hdata, const char *name);
@@ -1685,10 +1688,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_hdata_new_var (hdata, #__name, offsetof (__struct, __name), \
WEECHAT_HDATA_##__type, __update_allowed, \
__array_size, __hdata_name)
#define weechat_hdata_new_list(__hdata, __name, __pointer) \
weechat_plugin->hdata_new_list(__hdata, __name, __pointer)
#define WEECHAT_HDATA_LIST(__name) \
weechat_hdata_new_list (hdata, #__name, &(__name));
#define weechat_hdata_new_list(__hdata, __name, __pointer, __flags) \
weechat_plugin->hdata_new_list(__hdata, __name, __pointer, __flags)
#define WEECHAT_HDATA_LIST(__name, __flags) \
weechat_hdata_new_list (hdata, #__name, &(__name), __flags);
#define weechat_hdata_get(__hdata_name) \
weechat_plugin->hdata_get(weechat_plugin, __hdata_name)
#define weechat_hdata_get_var_offset(__hdata, __name) \