|
|
c313de |
From b9490d128b1a65d4d1ca273ddd54c696fa62ad73 Mon Sep 17 00:00:00 2001
|
|
|
c313de |
Message-Id: <b9490d128b1a65d4d1ca273ddd54c696fa62ad73@dist-git>
|
|
|
c313de |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
c313de |
Date: Fri, 21 Jun 2019 09:26:01 +0200
|
|
|
c313de |
Subject: [PATCH] util: string: Introduce macro for automatic string lists
|
|
|
c313de |
MIME-Version: 1.0
|
|
|
c313de |
Content-Type: text/plain; charset=UTF-8
|
|
|
c313de |
Content-Transfer-Encoding: 8bit
|
|
|
c313de |
|
|
|
c313de |
Similar to VIR_AUTOPTR, VIR_AUTOSTRINGLIST defines a list of strings
|
|
|
c313de |
which will be freed if the pointer is leaving scope.
|
|
|
c313de |
|
|
|
c313de |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
c313de |
Reviewed-by: Erik Skultety <eskultet@redhat.com>
|
|
|
c313de |
(cherry picked from commit daefda165b28b399478137c75b5466f865c65be5)
|
|
|
c313de |
|
|
|
c313de |
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
|
|
|
c313de |
|
|
|
c313de |
Conflicts:
|
|
|
c313de |
src/util/virstring.h
|
|
|
c313de |
- different header file guard
|
|
|
c313de |
- no AUTOPTR for string lists
|
|
|
c313de |
|
|
|
c313de |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c313de |
Message-Id: <7f1e7edf9c9a096fde1a2adf37090f8190e99be2.1561068591.git.jdenemar@redhat.com>
|
|
|
c313de |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c313de |
---
|
|
|
c313de |
src/libvirt_private.syms | 1 +
|
|
|
c313de |
src/util/virstring.c | 10 ++++++++++
|
|
|
c313de |
src/util/virstring.h | 10 ++++++++++
|
|
|
c313de |
3 files changed, 21 insertions(+)
|
|
|
c313de |
|
|
|
c313de |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
c313de |
index a20e0593f0..06374deaae 100644
|
|
|
c313de |
--- a/src/libvirt_private.syms
|
|
|
c313de |
+++ b/src/libvirt_private.syms
|
|
|
c313de |
@@ -2923,6 +2923,7 @@ virStringHasControlChars;
|
|
|
c313de |
virStringIsEmpty;
|
|
|
c313de |
virStringIsPrintable;
|
|
|
c313de |
virStringListAdd;
|
|
|
c313de |
+virStringListAutoFree;
|
|
|
c313de |
virStringListFree;
|
|
|
c313de |
virStringListFreeCount;
|
|
|
c313de |
virStringListGetFirstWithPrefix;
|
|
|
c313de |
diff --git a/src/util/virstring.c b/src/util/virstring.c
|
|
|
c313de |
index 15f367af7c..0f13b6c664 100644
|
|
|
c313de |
--- a/src/util/virstring.c
|
|
|
c313de |
+++ b/src/util/virstring.c
|
|
|
c313de |
@@ -332,6 +332,16 @@ void virStringListFree(char **strings)
|
|
|
c313de |
}
|
|
|
c313de |
|
|
|
c313de |
|
|
|
c313de |
+void virStringListAutoFree(char ***strings)
|
|
|
c313de |
+{
|
|
|
c313de |
+ if (!*strings)
|
|
|
c313de |
+ return;
|
|
|
c313de |
+
|
|
|
c313de |
+ virStringListFree(*strings);
|
|
|
c313de |
+ *strings = NULL;
|
|
|
c313de |
+}
|
|
|
c313de |
+
|
|
|
c313de |
+
|
|
|
c313de |
/**
|
|
|
c313de |
* virStringListFreeCount:
|
|
|
c313de |
* @strings: array of strings to free
|
|
|
c313de |
diff --git a/src/util/virstring.h b/src/util/virstring.h
|
|
|
c313de |
index 607ae66e99..e68b9eec79 100644
|
|
|
c313de |
--- a/src/util/virstring.h
|
|
|
c313de |
+++ b/src/util/virstring.h
|
|
|
c313de |
@@ -53,6 +53,7 @@ int virStringListCopy(char ***dst,
|
|
|
c313de |
const char **src);
|
|
|
c313de |
|
|
|
c313de |
void virStringListFree(char **strings);
|
|
|
c313de |
+void virStringListAutoFree(char ***strings);
|
|
|
c313de |
void virStringListFreeCount(char **strings,
|
|
|
c313de |
size_t count);
|
|
|
c313de |
|
|
|
c313de |
@@ -309,4 +310,13 @@ int virStringParsePort(const char *str,
|
|
|
c313de |
unsigned int *port)
|
|
|
c313de |
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
|
|
c313de |
|
|
|
c313de |
+/**
|
|
|
c313de |
+ * VIR_AUTOSTRINGLIST:
|
|
|
c313de |
+ *
|
|
|
c313de |
+ * Declares a NULL-terminated list of strings which will be automatically freed
|
|
|
c313de |
+ * when the pointer goes out of scope.
|
|
|
c313de |
+ */
|
|
|
c313de |
+# define VIR_AUTOSTRINGLIST \
|
|
|
c313de |
+ __attribute__((cleanup(virStringListAutoFree))) char **
|
|
|
c313de |
+
|
|
|
c313de |
#endif /* __VIR_STRING_H__ */
|
|
|
c313de |
--
|
|
|
c313de |
2.22.0
|
|
|
c313de |
|