dryang / rpms / systemd

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