]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
introduce FOREACH_ELEMENT
authorMatteo Croce <teknoraver@meta.com>
Thu, 18 Apr 2024 12:24:03 +0000 (14:24 +0200)
committerMatteo Croce <teknoraver@meta.com>
Thu, 18 Apr 2024 15:39:34 +0000 (17:39 +0200)
Add a FOREACH_ELEMENT() macro which just passes ELEMENTSOF(v)
as third argument to FOREACH_ARRAY().

coccinelle/parsing_hacks.h
src/basic/macro.h

index 9e77e514dd034629df8d6857298b3c5d9a1c8103..f88dae0c86b65c8f5ffc51ac006bed12ce370030 100644 (file)
@@ -68,6 +68,7 @@
 /* Mark a couple of iterator explicitly as iterators, otherwise Coccinelle gets a bit confused. Coccinelle
  * can usually infer this information automagically, but in these specific cases it needs a bit of help. */
 #define FOREACH_ARRAY(i, array, num) YACFE_ITERATOR
+#define FOREACH_ELEMENT(i, array) YACFE_ITERATOR
 #define FOREACH_DIRENT_ALL(de, d, on_error) YACFE_ITERATOR
 #define FOREACH_STRING(x, y, ...) YACFE_ITERATOR
 #define HASHMAP_FOREACH(e, h) YACFE_ITERATOR
index d43c3cdd5ddde4cfd610773624003fc96a0704b1..19d5039fd3bf451dc2020eec27b2ba3ce03a4ea0 100644 (file)
@@ -275,6 +275,9 @@ static inline int __coverity_check_and_return__(int condition) {
 #define FOREACH_ARRAY(i, array, num)                                    \
         _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
 
+#define FOREACH_ELEMENT(i, array)                                 \
+        FOREACH_ARRAY(i, array, ELEMENTSOF(array))
+
 #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope)             \
         scope type *name##_ref(type *p) {                       \
                 if (!p)                                         \