From 87eaadf84215ef31e453d26c4935f82ec7ab1ef0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 3 Dec 2013 16:41:06 +0100 Subject: [PATCH] macro: better make IN_SET() macro use const arrays Conflicts: src/shared/macro.h (cherry-picked from 059d9fbb) Resolves: #1147524 --- src/shared/macro.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/shared/macro.h b/src/shared/macro.h index d4f92b6..27a02d4 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -287,4 +287,18 @@ do { \ #define SET_FLAG(v, flag, b) \ (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag)) +#define IN_SET(x, ...) \ + ({ \ + const typeof(x) _x = (x); \ + unsigned _i; \ + bool _found = false; \ + for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \ + if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \ + _found = true; \ + break; \ + } \ + _found; \ + }) + + #include "log.h"