[coreboot-gerrit] Patch set updated for coreboot: Make common macros double-evaluation-safe
Patrick Georgi (pgeorgi@google.com)
gerrit at coreboot.org
Mon Sep 28 11:29:20 CET 2015
Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10395
-gerrit
commit 5bc00b2cc0a71f1c94646b00cef9d3a3fbe254ee
Author: Patrick Georgi <pgeorgi at chromium.org>
Date: Mon Jun 1 10:27:02 2015 +0200
Make common macros double-evaluation-safe
In the style of I4cc368a2f996, adapt more macros.
Change-Id: I948ac39a307a2f0703b3a5c611c6eccd1559ca1f
Signed-off-by: Patrick Georgi <pgeorgi at chromium.org>
---
src/commonlib/include/commonlib/helpers.h | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h
index 8f06093..966c6bd 100644
--- a/src/commonlib/include/commonlib/helpers.h
+++ b/src/commonlib/include/commonlib/helpers.h
@@ -24,9 +24,19 @@
typeof(b) _b = b; \
_a > _b ? _a : _b; \
})
-#define ABS(a) (((a) < 0) ? (-(a)) : (a))
-#define CEIL_DIV(a, b) (((a) + (b) - 1) / (b))
-#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
+#define ABS(a) ({ \
+ typeof(a) _a = a; \
+ _a < 0 ? -_a : _a; \
+})
+#define CEIL_DIV(a, b) ({ \
+ typeof(a) _a = a; \
+ typeof(b) _b = b; \
+ (((_a) + (_b) - 1) / (_b)); \
+})
+#define IS_POWER_OF_2(x) ({ \
+ typeof(x) _x = x; \
+ (((_x) & ((_x) - 1)) == 0); \
+})
/* Standard units. */
#define KiB (1<<10)
More information about the coreboot-gerrit
mailing list