|
|
84b277 |
From 28a4b5dd0895ba41d1327dcaf824f8adffea73f7 Mon Sep 17 00:00:00 2001
|
|
|
84b277 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
84b277 |
Date: Wed, 12 Mar 2014 22:26:22 +0100
|
|
|
84b277 |
Subject: [PATCH] macro: make sure we can use IN_SET() also with complex
|
|
|
84b277 |
function calls as first argument
|
|
|
84b277 |
|
|
|
84b277 |
(cherry-picked from dc36d78e)
|
|
|
84b277 |
|
|
|
84b277 |
Resolves: #1147524
|
|
|
84b277 |
---
|
|
|
84b277 |
src/shared/macro.h | 9 +++++----
|
|
|
84b277 |
src/test/test-util.c | 1 -
|
|
|
84b277 |
2 files changed, 5 insertions(+), 5 deletions(-)
|
|
|
84b277 |
|
|
|
84b277 |
diff --git a/src/shared/macro.h b/src/shared/macro.h
|
|
|
84b277 |
index 27a02d4..21039eb 100644
|
|
|
84b277 |
--- a/src/shared/macro.h
|
|
|
84b277 |
+++ b/src/shared/macro.h
|
|
|
84b277 |
@@ -287,13 +287,14 @@ do { \
|
|
|
84b277 |
#define SET_FLAG(v, flag, b) \
|
|
|
84b277 |
(v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
|
|
|
84b277 |
|
|
|
84b277 |
-#define IN_SET(x, ...) \
|
|
|
84b277 |
+#define IN_SET(x, y, ...) \
|
|
|
84b277 |
({ \
|
|
|
84b277 |
- const typeof(x) _x = (x); \
|
|
|
84b277 |
+ const typeof(y) _y = (y); \
|
|
|
84b277 |
+ const typeof(_y) _x = (x); \
|
|
|
84b277 |
unsigned _i; \
|
|
|
84b277 |
bool _found = false; \
|
|
|
84b277 |
- for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
|
|
|
84b277 |
- if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
|
|
|
84b277 |
+ for (_i = 0; _i < 1 + sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
|
|
|
84b277 |
+ if (((const typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
|
|
|
84b277 |
_found = true; \
|
|
|
84b277 |
break; \
|
|
|
84b277 |
} \
|
|
|
84b277 |
diff --git a/src/test/test-util.c b/src/test/test-util.c
|
|
|
84b277 |
index c5762ed..8527f13 100644
|
|
|
84b277 |
--- a/src/test/test-util.c
|
|
|
84b277 |
+++ b/src/test/test-util.c
|
|
|
84b277 |
@@ -571,7 +571,6 @@ static void test_fstab_node_to_udev_node(void) {
|
|
|
84b277 |
assert_se(streq(n, "/dev/disk/by-partuuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
|
|
|
84b277 |
free(n);
|
|
|
84b277 |
|
|
|
84b277 |
-
|
|
|
84b277 |
n = fstab_node_to_udev_node("PONIES=awesome");
|
|
|
84b277 |
puts(n);
|
|
|
84b277 |
assert_se(streq(n, "PONIES=awesome"));
|