diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-04 23:55:02 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-11-04 23:55:02 +0100 |
commit | 5e08f9876a471654a62eb818b2e4d1ef27f4648e (patch) | |
tree | 7372b19139010c9c3b4da244af04e789a55efa7b /src/core | |
parent | ee66fc3a855129b1682dd6c4844e7908a24a1347 (diff) | |
download | weechat-5e08f9876a471654a62eb818b2e4d1ef27f4648e.zip |
core: fix access to integer/long/time arrays in hdata, add support of static arrays in hdata
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-config-file.c | 2 | ||||
-rw-r--r-- | src/core/wee-hdata.c | 83 | ||||
-rw-r--r-- | src/core/wee-hdata.h | 2 |
3 files changed, 77 insertions, 10 deletions
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 27050c9ed..a5155d907 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -3310,7 +3310,7 @@ config_file_hdata_config_option_cb (const void *pointer, void *data, HDATA_VAR(struct t_config_option, parent_name, STRING, 0, NULL, NULL); HDATA_VAR(struct t_config_option, type, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_config_option, description, STRING, 0, NULL, NULL); - HDATA_VAR(struct t_config_option, string_values, STRING, 0, "*", NULL); + HDATA_VAR(struct t_config_option, string_values, STRING, 0, "*,*", NULL); HDATA_VAR(struct t_config_option, min, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_config_option, max, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_config_option, default_value, POINTER, 0, NULL, NULL); diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index d36100dbf..d1b800473 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -146,6 +146,7 @@ hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type, const char *hdata_name) { struct t_hdata_var *var; + const char *ptr_array_size; if (!hdata || !name) return; @@ -156,8 +157,20 @@ hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type, var->offset = offset; var->type = type; var->update_allowed = update_allowed; - var->array_size = (array_size && array_size[0]) ? strdup (array_size) : NULL; - var->hdata_name = (hdata_name && hdata_name[0]) ? strdup (hdata_name) : NULL; + ptr_array_size = array_size; + if (ptr_array_size && (strncmp (ptr_array_size, "*,", 2) == 0)) + { + var->array_pointer = 1; + ptr_array_size += 2; + } + else + { + var->array_pointer = 0; + } + var->array_size = (ptr_array_size && ptr_array_size[0]) ? + strdup (ptr_array_size) : NULL; + var->hdata_name = (hdata_name && hdata_name[0]) ? + strdup (hdata_name) : NULL; hashtable_set (hdata->hash_var, name, var); } } @@ -704,9 +717,16 @@ hdata_char (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return (*((char **)(pointer + var->offset)))[index]; + { + if (var->array_pointer) + return (*((char **)(pointer + var->offset)))[index]; + else + return ((char *)(pointer + var->offset))[index]; + } else + { return *((char *)(pointer + var->offset)); + } } return '\0'; @@ -731,9 +751,16 @@ hdata_integer (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return ((int *)(pointer + var->offset))[index]; + { + if (var->array_pointer) + return (*((int **)(pointer + var->offset)))[index]; + else + return ((int *)(pointer + var->offset))[index]; + } else + { return *((int *)(pointer + var->offset)); + } } return 0; @@ -758,9 +785,16 @@ hdata_long (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return ((long *)(pointer + var->offset))[index]; + { + if (var->array_pointer) + return (*((long **)(pointer + var->offset)))[index]; + else + return ((long *)(pointer + var->offset))[index]; + } else + { return *((long *)(pointer + var->offset)); + } } return 0; @@ -785,9 +819,19 @@ hdata_string (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return (*((char ***)(pointer + var->offset)))[index]; + { + if (var->array_pointer) + return (*((char ***)(pointer + var->offset)))[index]; + else + { + /* we can not index a static array of strings */ + return NULL; + } + } else + { return *((char **)(pointer + var->offset)); + } } return NULL; @@ -812,9 +856,16 @@ hdata_pointer (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return (*((void ***)(pointer + var->offset)))[index]; + { + if (var->array_pointer) + return (*((void ***)(pointer + var->offset)))[index]; + else + return ((void **)(pointer + var->offset))[index]; + } else + { return *((void **)(pointer + var->offset)); + } } return NULL; @@ -839,9 +890,16 @@ hdata_time (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return ((time_t *)(pointer + var->offset))[index]; + { + if (var->array_pointer) + return (*((time_t **)(pointer + var->offset)))[index]; + else + return ((time_t *)(pointer + var->offset))[index]; + } else + { return *((time_t *)(pointer + var->offset)); + } } return 0; @@ -866,9 +924,16 @@ hdata_hashtable (struct t_hdata *hdata, void *pointer, const char *name) if (var && (var->offset >= 0)) { if (var->array_size && (index >= 0)) - return (*((struct t_hashtable ***)(pointer + var->offset)))[index]; + { + if (var->array_pointer) + return (*((struct t_hashtable ***)(pointer + var->offset)))[index]; + else + return ((struct t_hashtable **)(pointer + var->offset))[index]; + } else + { return *((struct t_hashtable **)(pointer + var->offset)); + } } return NULL; diff --git a/src/core/wee-hdata.h b/src/core/wee-hdata.h index 5f4c3789f..24eb6eb8a 100644 --- a/src/core/wee-hdata.h +++ b/src/core/wee-hdata.h @@ -36,6 +36,8 @@ struct t_hdata_var char type; /* type */ char update_allowed; /* update allowed? */ char *array_size; /* array size */ + char array_pointer; /* pointer to dynamically allocated */ + /* array? */ char *hdata_name; /* hdata name */ }; |