From 261dff429e109996a2d3ce4b1ae3acf701e80738 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Sep 2015 14:08:06 +0200 Subject: [PATCH] glib-compat: add compatibility function for g_hash_table_insert() and g_hash_table_add() They have a different name, because we don't want to do the extra work unless explicitly requested. --- include/nm-glib.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/nm-glib.h b/include/nm-glib.h index 9a5bc058e2..7e42016b94 100644 --- a/include/nm-glib.h +++ b/include/nm-glib.h @@ -185,6 +185,35 @@ nm_g_hash_table_replace (GHashTable *hash, gpointer key, gpointer value) #endif } +static inline gboolean +nm_g_hash_table_insert (GHashTable *hash, gpointer key, gpointer value) +{ + /* glib 2.40 added a return value indicating whether the key already existed + * (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */ +#if GLIB_CHECK_VERSION(2, 40, 0) + return g_hash_table_insert (hash, key, value); +#else + gboolean contained = g_hash_table_contains (hash, key); + + g_hash_table_insert (hash, key, value); + return !contained; +#endif +} + +static inline gboolean +nm_g_hash_table_add (GHashTable *hash, gpointer key) +{ + /* glib 2.40 added a return value indicating whether the key already existed + * (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */ +#if GLIB_CHECK_VERSION(2, 40, 0) + return g_hash_table_add (hash, key); +#else + gboolean contained = g_hash_table_contains (hash, key); + + g_hash_table_add (hash, key); + return !contained; +#endif +} #if !GLIB_CHECK_VERSION(2, 40, 0) || defined (NM_GLIB_COMPAT_H_TEST) static inline void