summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-09-30 14:08:06 +0200
committerThomas Haller <thaller@redhat.com>2015-09-30 14:11:47 +0200
commit261dff429e109996a2d3ce4b1ae3acf701e80738 (patch)
tree4789a04d0b5a58862a78cb1b3c6eb52b345ad8d6
parentdf27e6d5fd50f8fc549fc07b65f2ce7e814bff1a (diff)
downloadNetworkManager-261dff429e109996a2d3ce4b1ae3acf701e80738.tar.gz
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.
-rw-r--r--include/nm-glib.h29
1 files changed, 29 insertions, 0 deletions
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