From: Jeff Dike <jdike@addtoit.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
uml-devel <user-mode-linux-devel@lists.sourceforge.net>
Subject: [uml-devel] [ PATCH 1/7 ] UML - Update UML definition of ARRAY_SIZE
Date: Thu, 22 Mar 2007 12:06:41 -0400 [thread overview]
Message-ID: <20070322160641.GA6997@c2.user-mode-linux.org> (raw)
This is the minimal change needed to keep UML building with the new
definition of ARRAY_SIZE. It is defined in user_util.h so that
userspace files, which can't include kernel.h, can still use
ARRAY_SIZE. However, since user_util.h is included everywhere,
including kernel files, the token sequence of the expansion has to
match.
This patch copies enough from the kernel headers to make that happen.
However, this is too gross to survive, and so is the entire header.
Future patches will make this header disappear, but this is a quick
and simple fix for the problem in case there is a noticable lag
between this patch and the more extensive patches which tidy this mess.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/include/user_util.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
Index: linux-2.6.21-mm/arch/um/include/user_util.h
===================================================================
--- linux-2.6.21-mm.orig/arch/um/include/user_util.h 2007-03-21 10:58:05.000000000 -0400
+++ linux-2.6.21-mm/arch/um/include/user_util.h 2007-03-21 11:05:44.000000000 -0400
@@ -8,8 +8,19 @@
#include "sysdep/ptrace.h"
-/* Copied from kernel.h */
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+/* Copied from kernel.h and compiler-gcc.h */
+
+/* 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(char[1 - 2 * !!(e)]) - 1)
+
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a) \
+ BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR))
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jeff Dike <jdike@addtoit.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
uml-devel <user-mode-linux-devel@lists.sourceforge.net>
Subject: [ PATCH 1/7 ] UML - Update UML definition of ARRAY_SIZE
Date: Thu, 22 Mar 2007 12:06:41 -0400 [thread overview]
Message-ID: <20070322160641.GA6997@c2.user-mode-linux.org> (raw)
This is the minimal change needed to keep UML building with the new
definition of ARRAY_SIZE. It is defined in user_util.h so that
userspace files, which can't include kernel.h, can still use
ARRAY_SIZE. However, since user_util.h is included everywhere,
including kernel files, the token sequence of the expansion has to
match.
This patch copies enough from the kernel headers to make that happen.
However, this is too gross to survive, and so is the entire header.
Future patches will make this header disappear, but this is a quick
and simple fix for the problem in case there is a noticable lag
between this patch and the more extensive patches which tidy this mess.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
arch/um/include/user_util.h | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
Index: linux-2.6.21-mm/arch/um/include/user_util.h
===================================================================
--- linux-2.6.21-mm.orig/arch/um/include/user_util.h 2007-03-21 10:58:05.000000000 -0400
+++ linux-2.6.21-mm/arch/um/include/user_util.h 2007-03-21 11:05:44.000000000 -0400
@@ -8,8 +8,19 @@
#include "sysdep/ptrace.h"
-/* Copied from kernel.h */
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+/* Copied from kernel.h and compiler-gcc.h */
+
+/* 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(char[1 - 2 * !!(e)]) - 1)
+
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a) \
+ BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#define CATCH_EINTR(expr) while ((errno = 0, ((expr) < 0)) && (errno == EINTR))
next reply other threads:[~2007-03-22 16:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-22 16:06 Jeff Dike [this message]
2007-03-22 16:06 ` [ PATCH 1/7 ] UML - Update UML definition of ARRAY_SIZE Jeff Dike
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=20070322160641.GA6997@c2.user-mode-linux.org \
--to=jdike@addtoit.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.