chiark / gitweb /
macro: make sure we can use IN_SET() also with complex function calls as first argument
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Mar 2014 21:26:22 +0000 (22:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Mar 2014 21:26:22 +0000 (22:26 +0100)
src/shared/macro.h
src/test/test-util.c

index 08a036b3b95d497743d5d95cf9396b74498d3b61..d53b07fea5cdc02c45a7d5367df8cb76ec96e574 100644 (file)
@@ -324,13 +324,14 @@ do {                                                                    \
 #define SET_FLAG(v, flag, b) \
         (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
 
-#define IN_SET(x, ...)                                                  \
+#define IN_SET(x, y, ...)                                               \
         ({                                                              \
-                const typeof(x) _x = (x);                               \
+                const typeof(y) _y = (y);                               \
+                const typeof(_y) _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) { \
+                for (_i = 0; _i < 1 + sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
+                        if (((const typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
                                 _found = true;                          \
                                 break;                                  \
                         }                                               \
index 1de06dbda84e7c3ca0a2dcd34a47aba47041abd3..229f49288998ef027510d11f0dc6b4b25afb27d7 100644 (file)
@@ -574,7 +574,6 @@ static void test_fstab_node_to_udev_node(void) {
         assert_se(streq(n, "/dev/disk/by-partuuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
         free(n);
 
-
         n = fstab_node_to_udev_node("PONIES=awesome");
         puts(n);
         assert_se(streq(n, "PONIES=awesome"));