[coreboot-gerrit] Patch set updated for coreboot: 5e9adb7 Make common macros double-evaluation-safe

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Tue Jun 2 12:32:07 CEST 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 5e9adb70a11205719b5028074eac16e345d6861f
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/include/stdlib.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/include/stdlib.h b/src/include/stdlib.h
index 37ed6ef..4acf1ed 100644
--- a/src/include/stdlib.h
+++ b/src/include/stdlib.h
@@ -25,9 +25,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); \
+})
 
 #define min(a,b) MIN((a),(b))
 #define max(a,b) MAX((a),(b))



More information about the coreboot-gerrit mailing list