]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Add helpers for auto-freeing GSList filled with strings
authorPeter Krempa <pkrempa@redhat.com>
Thu, 4 Feb 2021 16:58:23 +0000 (17:58 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2021 16:05:32 +0000 (17:05 +0100)
glib's 'g_autoslist()' doesn't support lists of 'char *' strings. Add a
type alias 'virGSListString' so that we can register an 'autoptr'
function for it for simple usage of GSList with strings.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/meson.build
src/util/virglibutil.c [new file with mode: 0644]
src/util/virglibutil.h [new file with mode: 0644]

index 837986845f35e87879b9fc8149da9d64b32c925f..55d04f662f13e31373cf4a9b649237a8ea3108b8 100644 (file)
@@ -2304,6 +2304,10 @@ virGICVersionTypeFromString;
 virGICVersionTypeToString;
 
 
+# util/virglibutil.h
+virGSListStringFree;
+
+
 # util/virhash.h
 virHashAddEntry;
 virHashAtomicNew;
index e89d32c33d9389becf89d53b63d5ca3b08c9f63b..0080825bd071edd2f87f2bb4665fdb735947e1de 100644 (file)
@@ -35,6 +35,7 @@ util_sources = [
   'virgdbus.c',
   'virgettext.c',
   'virgic.c',
+  'virglibutil.c',
   'virhash.c',
   'virhashcode.c',
   'virhook.c',
diff --git a/src/util/virglibutil.c b/src/util/virglibutil.c
new file mode 100644 (file)
index 0000000..8d93e27
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * virglibutil.c: Utilities helping with glib usage
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "virglibutil.h"
+
+void
+virGSListStringFree(GSList *l)
+{
+    g_slist_free_full(l, g_free);
+}
diff --git a/src/util/virglibutil.h b/src/util/virglibutil.h
new file mode 100644 (file)
index 0000000..2bff69f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * virglibutil.h: Utilities helping with glib usage
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "internal.h"
+
+void
+virGSListStringFree(GSList *l);
+
+typedef GSList virGSListString;
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virGSListString, virGSListStringFree);