diff mbox

[for-2.7,v4,03/36] glib-compat: add g_(s)list_free_full()

Message ID 20160805082421.21994-4-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Aug. 5, 2016, 8:23 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Those functions are only available since glib 2.28.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/glib-compat.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Markus Armbruster Aug. 5, 2016, 11:25 a.m. UTC | #1
marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Those functions are only available since glib 2.28.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/include/glib-compat.h b/include/glib-compat.h
index 01aa7b3..ff7eae5 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -260,4 +260,28 @@  static inline void g_hash_table_add(GHashTable *hash_table, gpointer key)
     } while (0)
 #endif
 
+#if !GLIB_CHECK_VERSION(2, 28, 0)
+static inline void g_list_free_full(GList *list, GDestroyNotify free_func)
+{
+    GList *l;
+
+    for (l = list; l; l = l->next) {
+        free_func(l->data);
+    }
+
+    g_list_free(list);
+}
+
+static inline void g_slist_free_full(GSList *list, GDestroyNotify free_func)
+{
+    GSList *l;
+
+    for (l = list; l; l = l->next) {
+        free_func(l->data);
+    }
+
+    g_slist_free(list);
+}
+#endif
+
 #endif