mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Cc: sha@pengutronix.de
Subject: [PATCH 11/11] common.h: add compile time check helper functions
Date: Tue, 16 Feb 2010 15:46:26 +0100	[thread overview]
Message-ID: <1266331586-11253-12-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1266331586-11253-11-git-send-email-mkl@pengutronix.de>

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/common.h |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/common.h b/include/common.h
index 2b40954..76e9be9 100644
--- a/include/common.h
+++ b/include/common.h
@@ -45,7 +45,7 @@
 #ifdef DEBUG
 #define pr_debug(fmt, arg...)	printf(fmt, ##arg)
 #else
-#define pr_debug(fmt, arg...) do {} while(0)
+#define pr_debug(fmt, arg...)	do {} while(0)
 #endif
 
 #define debug(fmt, arg...)	pr_debug(fmt, ##arg)
@@ -138,7 +138,32 @@ int arch_execute(void *, int argc, char *argv[]);
 
 int run_shell(void);
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
+
+/* Force a compilation error if condition is constant and true */
+#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
+
+/* Force a compilation error if a constant expression is not a power of 2 */
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n)			\
+	BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
+
+/*
+ * Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type size_t), so the expression can be used
+ * e.g. in a structure initializer (or where-ever else comma
+ * expressions aren't permitted).
+ */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
+
+#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
+#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
+#define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
+#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
+
+#define ARRAY_SIZE(arr)		(sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#define ARRAY_AND_SIZE(x)	(x), ARRAY_SIZE(x)
 
 /**
  * container_of - cast a member of a structure out to the containing structure
@@ -164,4 +189,6 @@ int run_shell(void);
 #define LLONG_MIN	(-LLONG_MAX - 1)
 #define ULLONG_MAX	(~0ULL)
 
+#define PAGE_SIZE	4096
+
 #endif	/* __COMMON_H_ */
-- 
1.6.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2010-02-16 14:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16 14:46 [PATCH 00/11] arch/arm and other random cleanups Marc Kleine-Budde
2010-02-16 14:46 ` [PATCH 01/11] arm/Kconfig: delete trailing whitespace Marc Kleine-Budde
2010-02-16 14:46   ` [PATCH 02/11] arm/Kconfig: removed unused TAG options Marc Kleine-Budde
2010-02-16 14:46     ` [PATCH 03/11] arm/Makefile: keep list of boards sorted Marc Kleine-Budde
2010-02-16 14:46       ` [PATCH 04/11] arm/cpu/Makefile: cleanup: propper indention Marc Kleine-Budde
2010-02-16 14:46         ` [PATCH 05/11] drivers/video/Makefile: cleanup " Marc Kleine-Budde
2010-02-16 14:46           ` [PATCH 06/11] start-arm: cleanup: " Marc Kleine-Budde
2010-02-16 14:46             ` [PATCH 07/11] i2c.h: fix typo in copyright Marc Kleine-Budde
2010-02-16 14:46               ` [PATCH 08/11] ioreadsb: put the whole ioreadsb function into the .text.readsb section Marc Kleine-Budde
2010-02-16 14:46                 ` [PATCH 09/11] import recent include/linux/compiler*.h Marc Kleine-Budde
2010-02-16 14:46                   ` [PATCH 10/11] io.h: update definitions of __raw_{read,write}* Marc Kleine-Budde
2010-02-16 14:46                     ` Marc Kleine-Budde [this message]
2010-02-16 15:01             ` [PATCH 06/11] start-arm: cleanup: propper indention Uwe Kleine-König
2010-02-16 20:35           ` [PATCH 05/11] drivers/video/Makefile: cleanup " Marc Kleine-Budde
2010-02-16 14:54 ` [PATCH 00/11] arch/arm and other random cleanups Marc Kleine-Budde
2010-02-17  9:46   ` Sascha Hauer
2010-02-17 22:20     ` Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1266331586-11253-12-git-send-email-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox