All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] settings: Add l_settings_add_group
@ 2021-04-26 16:06 Andrew Zaborowski
  2021-04-26 16:06 ` [PATCH 2/2] util: Add l_steal_ptr Andrew Zaborowski
  2021-04-26 20:28 ` [PATCH 1/2] settings: Add l_settings_add_group Denis Kenzior
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2021-04-26 16:06 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 2174 bytes --]

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(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 229a2a6..5568ac2 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -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;
diff --git a/ell/settings.c b/ell/settings.c
index 8db0942..3d3728c 100644
--- a/ell/settings.c
+++ b/ell/settings.c
@@ -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;
diff --git a/ell/settings.h b/ell/settings.h
index f95ed9b..be92d29 100644
--- a/ell/settings.h
+++ b/ell/settings.h
@@ -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,
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] util: Add l_steal_ptr
  2021-04-26 16:06 [PATCH 1/2] settings: Add l_settings_add_group Andrew Zaborowski
@ 2021-04-26 16:06 ` Andrew Zaborowski
  2021-04-26 16:43   ` Denis Kenzior
  2021-04-26 20:28 ` [PATCH 1/2] settings: Add l_settings_add_group Denis Kenzior
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Zaborowski @ 2021-04-26 16:06 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

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:

> Sets `pp` to `NULL`, 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(+)

diff --git a/ell/util.h b/ell/util.h
index 9400657..bdf6935 100644
--- a/ell/util.h
+++ b/ell/util.h
@@ -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
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] util: Add l_steal_ptr
  2021-04-26 16:06 ` [PATCH 2/2] util: Add l_steal_ptr Andrew Zaborowski
@ 2021-04-26 16:43   ` Denis Kenzior
  0 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2021-04-26 16:43 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

Hi Andrew,

On 4/26/21 11:06 AM, Andrew Zaborowski wrote:
> 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:
> 
>> Sets `pp` to `NULL`, 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] settings: Add l_settings_add_group
  2021-04-26 16:06 [PATCH 1/2] settings: Add l_settings_add_group Andrew Zaborowski
  2021-04-26 16:06 ` [PATCH 2/2] util: Add l_steal_ptr Andrew Zaborowski
@ 2021-04-26 20:28 ` Denis Kenzior
  1 sibling, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2021-04-26 20:28 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

Hi Andrew,

On 4/26/21 11:06 AM, Andrew Zaborowski wrote:
> 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(+)
> 

Applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-26 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 16:06 [PATCH 1/2] settings: Add l_settings_add_group Andrew Zaborowski
2021-04-26 16:06 ` [PATCH 2/2] util: Add l_steal_ptr Andrew Zaborowski
2021-04-26 16:43   ` Denis Kenzior
2021-04-26 20:28 ` [PATCH 1/2] settings: Add l_settings_add_group Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.