dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
b8c242
From 3539a72c260063713e4ecba17966ba9a768d8af9 Mon Sep 17 00:00:00 2001
b8c242
From: Lennart Poettering <lennart@poettering.net>
b8c242
Date: Wed, 16 Jan 2019 00:13:38 +0100
b8c242
Subject: [PATCH] strv: rework FOREACH_STRING() macro
b8c242
b8c242
So it's apparently problematic that we use STRV_MAKE() (i.e. a compound
b8c242
initializer) outside of the {} block we use it in (and that includes
b8c242
outside of the ({}) block, too). Hence, let's rework the macro to not
b8c242
need that.
b8c242
b8c242
This also makes the macro shorter, which is definitely a good and more
b8c242
readable. Moreover, it will now complain if the iterator is a "char*"
b8c242
instead of a "const char*", which is good too.
b8c242
b8c242
Fixes: #11394
b8c242
(cherry picked from commit 66a64081f82dfad90f2f9394a477820a2e3e6510)
b8c242
b8c242
Related: #2017033
b8c242
---
b8c242
 src/basic/strv.h | 15 ++++-----------
b8c242
 1 file changed, 4 insertions(+), 11 deletions(-)
b8c242
b8c242
diff --git a/src/basic/strv.h b/src/basic/strv.h
b8c242
index c1e4c973b6..a09d76706d 100644
b8c242
--- a/src/basic/strv.h
b8c242
+++ b/src/basic/strv.h
b8c242
@@ -148,17 +148,10 @@ void strv_print(char **l);
b8c242
                 _found;                                         \
b8c242
         })
b8c242
 
b8c242
-#define FOREACH_STRING(x, ...)                               \
b8c242
-        for (char **_l = ({                                  \
b8c242
-                char **_ll = STRV_MAKE(__VA_ARGS__);         \
b8c242
-                x = _ll ? _ll[0] : NULL;                     \
b8c242
-                _ll;                                         \
b8c242
-        });                                                  \
b8c242
-        _l && *_l;                                           \
b8c242
-        x = ({                                               \
b8c242
-                _l ++;                                       \
b8c242
-                _l[0];                                       \
b8c242
-        }))
b8c242
+#define FOREACH_STRING(x, y, ...)                                       \
b8c242
+        for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__);        \
b8c242
+             x;                                                         \
b8c242
+             x = *(++_l))
b8c242
 
b8c242
 char **strv_reverse(char **l);
b8c242
 char **strv_shell_escape(char **l, const char *bad);