Re: [PATCH] Use more gcc extensions in the Linux headers
From: Jan Engelhardt
Date: Sat Mar 10 2007 - 22:01:20 EST
On Mar 11 2007 13:50, Rusty Russell wrote:
>On Sat, 2007-03-10 at 02:04 +0100, Jan Engelhardt wrote:
>> Getting back at the macro, how would you like to have it merged?
>
>Well, this is what I sent to Linus and Andrew (many thanks to those who
>made appropriately whimsical *or* useful comments):
>
>diff -r 1ccdf46b0f41 include/linux/compiler-gcc.h
>--- a/include/linux/compiler-gcc.h Sat Mar 10 09:55:29 2007 +1100
>+++ b/include/linux/compiler-gcc.h Sat Mar 10 11:06:35 2007 +1100
>@@ -22,6 +22,9 @@
> __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
> (typeof(ptr)) (__ptr + (off)); })
>
>+/* &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])))
This looks _much_ nicer! (And BUILD_BUG_ON is also appropriately
commented.)
>
> #define inline inline __attribute__((always_inline))
> #define __inline__ __inline__ __attribute__((always_inline))
>diff -r 1ccdf46b0f41 include/linux/compiler-intel.h
>--- a/include/linux/compiler-intel.h Sat Mar 10 09:55:29 2007 +1100
>+++ b/include/linux/compiler-intel.h Sat Mar 10 11:06:25 2007 +1100
>@@ -21,4 +21,7 @@
> __ptr = (unsigned long) (ptr); \
> (typeof(ptr)) (__ptr + (off)); })
>
>+/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */
>+#define __must_be_array(a) 0
>+
> #endif
>diff -r 1ccdf46b0f41 include/linux/kernel.h
>--- a/include/linux/kernel.h Sat Mar 10 09:55:29 2007 +1100
>+++ b/include/linux/kernel.h Sat Mar 10 11:06:16 2007 +1100
>@@ -35,7 +35,8 @@ extern const char linux_proc_banner[];
> #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
> #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
>
>-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
>+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
>+
> #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
80 cols *cough* :)
Jan
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/