]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: make sure DNS_ANSWER_FOREACH() can be nested
authorLennart Poettering <lennart@poettering.net>
Wed, 2 Dec 2015 19:43:11 +0000 (20:43 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 2 Dec 2015 19:43:11 +0000 (20:43 +0100)
Change the iterator counter so that a different varable is used for each
invocation of the macro, so that it may be nested.

src/resolve/resolved-dns-answer.h
src/resolve/resolved-dns-question.h

index 8814919deb365fdbe5a6557aa8fa22f18839fbfc..89c254b02ef145eb319ba1ac5c8a00e68369aad7 100644 (file)
@@ -24,6 +24,7 @@
 typedef struct DnsAnswer DnsAnswer;
 typedef struct DnsAnswerItem DnsAnswerItem;
 
+#include "macro.h"
 #include "resolved-dns-rr.h"
 
 /* A simple array of resource records. We keep track of the
@@ -59,19 +60,23 @@ int dns_answer_reserve(DnsAnswer **a, unsigned n_free);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsAnswer*, dns_answer_unref);
 
-#define DNS_ANSWER_FOREACH(kk, a)                                       \
-        for (unsigned _i = ({                                           \
+#define _DNS_ANSWER_FOREACH(q, kk, a)                                   \
+        for (unsigned UNIQ_T(i, q) = ({                                 \
                                 (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \
                                 0;                                      \
-                           });                                          \
-             (a) && ((_i) < (a)->n_rrs);                                \
-             _i++, (kk) = (_i < (a)->n_rrs ? (a)->items[_i].rr : NULL))
+                        });                                             \
+             (a) && (UNIQ_T(i, q) < (a)->n_rrs);                        \
+             UNIQ_T(i, q)++, (kk) = (UNIQ_T(i, q) < (a)->n_rrs ? (a)->items[UNIQ_T(i, q)].rr : NULL))
 
-#define DNS_ANSWER_FOREACH_IFINDEX(kk, ifindex, a)                      \
-        for (unsigned _i = ({                                           \
+#define DNS_ANSWER_FOREACH(kk, a) _DNS_ANSWER_FOREACH(UNIQ, kk, a)
+
+#define _DNS_ANSWER_FOREACH_IFINDEX(q, kk, ifindex, a)                  \
+        for (unsigned UNIQ_T(i, q) = ({                                 \
                                 (kk) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].rr : NULL; \
                                 (ifindex) = ((a) && (a)->n_rrs > 0) ? (a)->items[0].ifindex : 0; \
                                 0;                                      \
-                           });                                          \
-             (a) && ((_i) < (a)->n_rrs);                                \
-             _i++, (kk) = ((_i < (a)->n_rrs) ? (a)->items[_i].rr : NULL), (ifindex) = ((_i < (a)->n_rrs) ? (a)->items[_i].ifindex : 0))
+                        });                                             \
+             (a) && (UNIQ_T(i, q) < (a)->n_rrs);                        \
+             UNIQ_T(i, q)++, (kk) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].rr : NULL), (ifindex) = ((UNIQ_T(i, q) < (a)->n_rrs) ? (a)->items[UNIQ_T(i, q)].ifindex : 0))
+
+#define DNS_ANSWER_FOREACH_IFINDEX(kk, ifindex, a) _DNS_ANSWER_FOREACH_IFINDEX(UNIQ, kk, ifindex, a)
index e77116c03a51e571f98e39ae7f0bc8d7b45a1d46..5ffb63e2504cd72718a1e65519535cbc8336532c 100644 (file)
 
 typedef struct DnsQuestion DnsQuestion;
 
+#include "macro.h"
 #include "resolved-dns-rr.h"
 
-/* A simple array of resources keys */
+/* A simple array of resource keys */
 
 struct DnsQuestion {
         unsigned n_ref;
@@ -55,10 +56,12 @@ const char *dns_question_first_name(DnsQuestion *q);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuestion*, dns_question_unref);
 
-#define DNS_QUESTION_FOREACH(key, q)                                    \
-        for (unsigned _i = ({                                           \
+#define _DNS_QUESTION_FOREACH(u, key, q)                                \
+        for (unsigned UNIQ_T(i, u) = ({                                 \
                                 (key) = ((q) && (q)->n_keys > 0) ? (q)->keys[0] : NULL; \
                                 0;                                      \
                         });                                             \
-             (q) && ((_i) < (q)->n_keys);                               \
-             _i++, (key) = (_i < (q)->n_keys ? (q)->keys[_i] : NULL))
+             (q) && (UNIQ_T(i, u) < (q)->n_keys);                       \
+             UNIQ_T(i, u)++, (key) = (UNIQ_T(i, u) < (q)->n_keys ? (q)->keys[UNIQ_T(i, u)] : NULL))
+
+#define DNS_QUESTION_FOREACH(key, q) _DNS_QUESTION_FOREACH(UNIQ, key, q)