From c7e6573eb41ef91b29fb45aff04404ab4161f21a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 28 Jan 2020 16:50:18 +0100 Subject: [PATCH] shared: add nm_g_variant_lookup() and nm_g_variant_lookup_value() helpers It's often convenient to accept %NULL as dictionary argument. --- shared/nm-glib-aux/nm-shared-utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index d1257242f..5b56713bc 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -1051,6 +1051,24 @@ nm_g_variant_unref_floating (GVariant *var) g_variant_unref (var); } +#define nm_g_variant_lookup(dictionary, ...) \ + ({ \ + GVariant *const _dictionary = (dictionary); \ + \ + ( _dictionary \ + && g_variant_lookup (_dictionary, __VA_ARGS__)); \ + }) + +static inline GVariant * +nm_g_variant_lookup_value (GVariant *dictionary, + const char *key, + const GVariantType *expected_type) +{ + return dictionary + ? g_variant_lookup_value (dictionary, key, expected_type) + : NULL; +} + static inline void nm_g_source_destroy_and_unref (GSource *source) {