settings: Add l_settings_add_group
PATCH 1/2 settings: Add l_settings_add_group
l_settings_add_group creates a group in the l_settings object without adding any key/value pairs to it.
--- ell/ell.sym | 1 + ell/settings.c | 28 ++++++++++++++++++++++++++++ ell/settings.h | 2 ++ 3 files changed, 31 insertions(+)
ell/ell.sym +1 -0
@@ -443,6 +443,7 @@ global: l_settings_set_debug; l_settings_get_groups; l_settings_has_group; + l_settings_add_group; l_settings_get_keys; l_settings_has_key; l_settings_get_value;
ell/settings.c +28 -0
@@ -866,6 +866,34 @@ static bool validate_group_name(const char *group_name)return true; } +LIB_EXPORT bool l_settings_add_group(struct l_settings *settings, +const char *group_name) +{ +struct group_data *group; + +if (unlikely (!settings || !group_name)) +return false; + +if (!validate_group_name (group_name)) { +l_util_debug (settings->debug_handler, settings->debug_data, +"Invalid group name %s" , group_name); +return false; + } + + group =l_queue_find (settings->groups, group_match, group_name); +if (group) { +l_util_debug (settings->debug_handler, settings->debug_data, +"Group %s exists" , group_name); +return true; + } + + group = l_new(struct group_data, 1); + group->name =l_strdup (group_name); + group->settings =l_queue_new (); +l_queue_push_tail (settings->groups, group); +return true; +} +static bool validate_key (const char *key) {int i;
ell/settings.h +2 -0
@@ -54,6 +54,8 @@ char **l_settings_get_groups(const struct l_settings *settings);char **l_settings_get_keys (const struct l_settings *settings,const char *group_name); +bool l_settings_add_group (struct l_settings *settings,const char *group_name); +bool l_settings_has_group (const struct l_settings *settings,const char *group_name); bool l_settings_has_key(const struct l_settings *settings,
Signature · 1 line
2.27.0
PATCH 2/2 util: Add l_steal_ptr
Add the l_steal_ptr macro, similar to g_steal_pointer except for being a macro and taking the variable name as a parameter, rather than a pointer to that variable. From g_steal_pointer(pp) documentation:
Quoted 5 lines
Sets
pptoNULL, returning the value that was there before.Conceptually, this transfers the ownership of the pointer from the referenced variable to the "caller" of the macro (ie: "steals" the reference).
--- ell/util.h | 3 +++ 1 file changed, 3 insertions(+)
ell/util.h +3 -0
@@ -245,6 +245,9 @@ static inline void auto_free(void *a)l_free (*p); } +#define l_steal_ptr (ptr) \ + (__extension__ ({ typeof(ptr) _tmp = (ptr); (ptr) = NULL; _tmp; })) +/** * l_new: * @type: type of structure
Signature · 1 line
2.27.0
Denis Kenzior
AppliedRe: [PATCH 2/2] util: Add l_steal_ptr
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
Add the
l_steal_ptrmacro, similar tog_steal_pointerexcept for being a macro and taking the variable name as a parameter, rather than a pointer to that variable. Fromg_steal_pointer(pp)documentation:
Quoted 9 lines
Quoted 5 lines
Sets
pptoNULL, returning the value that was there before.Conceptually, this transfers the ownership of the pointer from the referenced variable to the "caller" of the macro (ie: "steals" the reference).
--- ell/util.h | 3 +++ 1 file changed, 3 insertions(+)
Applied, thanks.
Regards,
-Denis
Denis Kenzior
AppliedHi Andrew,
Quoted 8 lines · Andrew Zaborowski
l_settings_add_groupcreates a group in thel_settingsobject without adding any key/value pairs to it.--- ell/ell.sym | 1 + ell/settings.c | 28 ++++++++++++++++++++++++++++ ell/settings.h | 2 ++ 3 files changed, 31 insertions(+)
Applied, thanks.
Regards,
-Denis