[coreboot-gerrit] New patch to review for coreboot: commonlib/helpers.h: handle interaction with other environments
Aaron Durbin (adurbin@chromium.org)
gerrit at coreboot.org
Thu Oct 1 22:58:31 CET 2015
Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11773
-gerrit
commit 68266e90a38bb22518362a7325893f911d28d33c
Author: Aaron Durbin <adurbin at chromium.org>
Date: Thu Oct 1 14:20:57 2015 -0500
commonlib/helpers.h: handle interaction with other environments
There are compiler settings and interactions with other
header files that should be handled. First use __typeof__
instead of typeof because 'std' modes don't accept typeof.
The __typeof__ variant works equally well on clang. The
other change is to guard the helper macros so as not to
trigger redefinition errors.
BUG=chrome-os-partner:44827
BRANCH=None
TEST=Built cbfstool including commonlib/helpers.h
Change-Id: I58890477cb17df14a9fa8b7af752a7c70769cf36
Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
src/commonlib/include/commonlib/helpers.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h
index 6ad767e..0e337c9 100644
--- a/src/commonlib/include/commonlib/helpers.h
+++ b/src/commonlib/include/commonlib/helpers.h
@@ -4,14 +4,18 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1UL)
+#define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1UL)
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
#define ALIGN_UP(x,a) ALIGN((x),(a))
-#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1UL))
-#define IS_ALIGNED(x,a) (((x) & ((typeof(x))(a)-1UL)) == 0)
+#define ALIGN_DOWN(x,a) ((x) & ~((__typeof__(x))(a)-1UL))
+#define IS_ALIGNED(x,a) (((x) & ((__typeof__(x))(a)-1UL)) == 0)
+#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
#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)
@@ -27,7 +31,9 @@
#define MHz (1000 * KHz)
#define GHz (1000 * MHz)
+#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
#if !defined(__clang__)
#define check_member(structure, member, offset) _Static_assert( \
@@ -45,7 +51,7 @@
*
*/
#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif /* COMMONLIB_HELPERS_H */
More information about the coreboot-gerrit
mailing list