macro: support the case that the number of elements has const qualifier

Follow-up for 5716c27e1f.

Addresses https://github.com/systemd/systemd/pull/26303#issuecomment-1460712007.
This commit is contained in:
Yu Watanabe
2023-03-09 08:41:43 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent 00aba43fe6
commit b9872fe1dd
+6 -4
View File
@@ -297,12 +297,14 @@ static inline int __coverity_check_and_return__(int condition) {
p != (typeof(p)) POINTER_MAX; \
p = *(++_l))
#define _FOREACH_ARRAY(i, array, num, m, s) \
for (typeof(num) m = (num); m > 0; m = 0) \
for (typeof(array[0]) *s = (array), *i = s; s && i < s + m; i++)
#define _FOREACH_ARRAY(i, array, num, m, end) \
for (typeof(array[0]) *i = (array), *end = ({ \
typeof(num) m = (num); \
(i && m > 0) ? i + m : NULL; \
}); end && i < end; i++)
#define FOREACH_ARRAY(i, array, num) \
_FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(s, UNIQ))
_FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ))
#define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \
static inline void name(type *p) { \