diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-11-28 17:49:36 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-11-28 17:49:36 +0100 |
commit | 288034f83ff33696a9f2be2a4f7cf1efd8c84449 (patch) | |
tree | 15391a3b860bb96b051c31fd1cfd855b235a9b8b /src | |
parent | b4bd4876fdd59807279de5a2e4ca71c9376c4bcd (diff) | |
download | weechat-288034f83ff33696a9f2be2a4f7cf1efd8c84449.zip |
Use of only one pointer to value for plugin list variables
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/plugin-list.c | 56 | ||||
-rw-r--r-- | src/plugins/plugin-list.h | 5 |
2 files changed, 33 insertions, 28 deletions
diff --git a/src/plugins/plugin-list.c b/src/plugins/plugin-list.c index 47bf4843f..8a1c56809 100644 --- a/src/plugins/plugin-list.c +++ b/src/plugins/plugin-list.c @@ -110,10 +110,8 @@ plugin_list_new_var_int (struct t_plugin_list_item *item, { new_var->name = strdup (name); new_var->type = PLUGIN_LIST_VAR_INTEGER; - new_var->value_int = value; - new_var->value_string = NULL; - new_var->value_pointer = NULL; - new_var->value_time = 0; + new_var->value = malloc (sizeof (int)); + *((int *)new_var->value) = value; new_var->prev_var = item->last_var; new_var->next_var = NULL; @@ -145,9 +143,7 @@ plugin_list_new_var_string (struct t_plugin_list_item *item, { new_var->name = strdup (name); new_var->type = PLUGIN_LIST_VAR_STRING; - new_var->value_int = 0; - new_var->value_string = (value) ? strdup (value) : NULL; - new_var->value_time = 0; + new_var->value = (value) ? strdup (value) : NULL; new_var->prev_var = item->last_var; new_var->next_var = NULL; @@ -179,10 +175,7 @@ plugin_list_new_var_pointer (struct t_plugin_list_item *item, { new_var->name = strdup (name); new_var->type = PLUGIN_LIST_VAR_POINTER; - new_var->value_int = 0; - new_var->value_string = NULL; - new_var->value_pointer = pointer; - new_var->value_time = 0; + new_var->value = pointer; new_var->prev_var = item->last_var; new_var->next_var = NULL; @@ -214,10 +207,8 @@ plugin_list_new_var_time (struct t_plugin_list_item *item, { new_var->name = strdup (name); new_var->type = PLUGIN_LIST_VAR_TIME; - new_var->value_int = 0; - new_var->value_string = NULL; - new_var->value_pointer = NULL; - new_var->value_time = time; + new_var->value = malloc (sizeof (time_t)); + *((time_t *)new_var->value) = time; new_var->prev_var = item->last_var; new_var->next_var = NULL; @@ -359,7 +350,7 @@ plugin_list_get_int (struct t_plugin_list *list, char *var) if (string_strcasecmp (ptr_var->name, var) == 0) { if (ptr_var->type == PLUGIN_LIST_VAR_INTEGER) - return ptr_var->value_int; + return *((int *)ptr_var->value); else return 0; } @@ -386,7 +377,7 @@ plugin_list_get_string (struct t_plugin_list *list, char *var) if (string_strcasecmp (ptr_var->name, var) == 0) { if (ptr_var->type == PLUGIN_LIST_VAR_STRING) - return ptr_var->value_string; + return (char *)ptr_var->value; else return NULL; } @@ -413,7 +404,7 @@ plugin_list_get_pointer (struct t_plugin_list *list, char *var) if (string_strcasecmp (ptr_var->name, var) == 0) { if (ptr_var->type == PLUGIN_LIST_VAR_POINTER) - return ptr_var->value_pointer; + return ptr_var->value; else return NULL; } @@ -440,7 +431,7 @@ plugin_list_get_time (struct t_plugin_list *list, char *var) if (string_strcasecmp (ptr_var->name, var) == 0) { if (ptr_var->type == PLUGIN_LIST_VAR_TIME) - return ptr_var->value_time; + return *((time_t *)ptr_var->value); else return 0; } @@ -477,8 +468,13 @@ plugin_list_var_free (struct t_plugin_list_item *item, /* free data */ if (var->name) free (var->name); - if (var->value_string) - free (var->value_string); + if (((var->type == PLUGIN_LIST_VAR_INTEGER) + || (var->type == PLUGIN_LIST_VAR_STRING) + || (var->type == PLUGIN_LIST_VAR_TIME)) + && var->value) + { + free (var->value); + } item->vars = new_vars; } @@ -589,9 +585,21 @@ plugin_list_print_log () log_printf (" [var (addr:0x%X)]\n", ptr_var); log_printf (" name . . . . . . . . : '%s'\n", ptr_var->name); log_printf (" type . . . . . . . . : %d\n", ptr_var->type); - log_printf (" value_int. . . . . . : %d\n", ptr_var->value_int); - log_printf (" value_string . . . . : '%s'\n", ptr_var->value_string); - log_printf (" value_time . . . . . : %ld\n", ptr_var->value_time); + switch (ptr_var->type) + { + case PLUGIN_LIST_VAR_INTEGER: + log_printf (" value (int). . . . . : %d\n", *((int *)ptr_var->value)); + break; + case PLUGIN_LIST_VAR_STRING: + log_printf (" value (string) . . . : '%s'\n", (char *)ptr_var->value); + break; + case PLUGIN_LIST_VAR_POINTER: + log_printf (" value (pointer). . . : 0x%X\n", ptr_var->value); + break; + case PLUGIN_LIST_VAR_TIME: + log_printf (" value (time) . . . . : %ld\n", *((time_t *)ptr_var->value)); + break; + } log_printf (" prev_var . . . . . . : 0x%X\n", ptr_var->prev_var); log_printf (" next_var . . . . . . : 0x%X\n", ptr_var->next_var); } diff --git a/src/plugins/plugin-list.h b/src/plugins/plugin-list.h index 0c15606ea..05ef7204f 100644 --- a/src/plugins/plugin-list.h +++ b/src/plugins/plugin-list.h @@ -34,10 +34,7 @@ struct t_plugin_list_var { char *name; /* variable name */ enum t_plugin_var_type type; /* type: integer, string, time */ - int value_int; /* integer value */ - char *value_string; /* string value */ - void *value_pointer; /* pointer value */ - time_t value_time; /* time value */ + void *value; /* pointer to value */ struct t_plugin_list_var *prev_var; /* link to previous variable */ struct t_plugin_list_var *next_var; /* link to next variable */ }; |