public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] u64 casts
@ 2004-02-27 20:58 Albert Cahalan
  2004-02-28  0:18 ` David Mosberger
  0 siblings, 1 reply; 15+ messages in thread
From: Albert Cahalan @ 2004-02-27 20:58 UTC (permalink / raw)
  To: linux-kernel mailing list; +Cc: Linus Torvalds, Andrew Morton OSDL

Casts are considered harmful, because they bypass
type checking, but how do you print a u64 value?
You cast it to "unsigned long long" like this:

  printk("%llu\n", (unsigned long long)foo);

Well, this is silly and ugly. As x86-64 has shown,
even a 64-bit port can use "long long" for 64-bit
values. This patch changes all other 64-bit ports.
It now becomes possible to avoid adding new casts
all over the place; existing ones may be removed
if so desired.

diff -Naurd old/include/asm-alpha/types.h new/include/asm-alpha/types.h
--- old/include/asm-alpha/types.h	2004-02-21 03:25:04.000000000 -0500
+++ new/include/asm-alpha/types.h	2004-02-27 15:37:40.000000000 -0500
@@ -27,8 +27,8 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
 
 #endif /* __ASSEMBLY__ */
 
@@ -50,8 +50,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-typedef signed long s64;
-typedef unsigned long u64;
+typedef signed long long s64;
+typedef unsigned long long u64;
 
 typedef u64 dma_addr_t;
 typedef u64 dma64_addr_t;
diff -Naurd old/include/asm-ia64/types.h new/include/asm-ia64/types.h
--- old/include/asm-ia64/types.h	2004-02-21 03:20:17.000000000 -0500
+++ new/include/asm-ia64/types.h	2004-02-27 15:40:14.000000000 -0500
@@ -41,8 +41,8 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
 
 /*
  * These aren't exported outside the kernel to avoid name space clashes
diff -Naurd old/include/asm-mips/types.h new/include/asm-mips/types.h
--- old/include/asm-mips/types.h	2004-02-21 03:19:29.000000000 -0500
+++ new/include/asm-mips/types.h	2004-02-27 15:39:51.000000000 -0500
@@ -34,20 +34,11 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-#if (_MIPS_SZLONG == 64)
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-
-#else
-
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
 #endif
 
-#endif
-
 #endif /* __ASSEMBLY__ */
 
 /*
@@ -68,20 +59,11 @@
 typedef __signed int s32;
 typedef unsigned int u32;
 
-#if (_MIPS_SZLONG == 64)
-
-typedef __signed__ long s64;
-typedef unsigned long u64;
-
-#else
-
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 typedef __signed__ long long s64;
 typedef unsigned long long u64;
 #endif
 
-#endif
-
 #if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
     || defined(CONFIG_MIPS64)
 typedef u64 dma_addr_t;
diff -Naurd old/include/asm-ppc64/types.h new/include/asm-ppc64/types.h
--- old/include/asm-ppc64/types.h	2004-02-21 03:21:11.000000000 -0500
+++ new/include/asm-ppc64/types.h	2004-02-27 15:41:06.000000000 -0500
@@ -32,8 +32,8 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
 
 typedef struct {
 	__u32 u[4];
@@ -58,8 +58,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-typedef signed long s64;
-typedef unsigned long u64;
+typedef signed long long s64;
+typedef unsigned long long u64;
 
 typedef __vector128 vector128;
 
diff -Naurd old/include/asm-s390/types.h new/include/asm-s390/types.h
--- old/include/asm-s390/types.h	2004-02-21 03:22:57.000000000 -0500
+++ new/include/asm-s390/types.h	2004-02-27 15:43:42.000000000 -0500
@@ -27,15 +27,10 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-#ifndef __s390x__
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
 #endif
-#else /* __s390x__ */
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#endif
 
 /* A address type so that arithmetic can be done on it & it can be upgraded to
    64 bit when necessary 
@@ -67,13 +62,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-#ifndef __s390x__
 typedef signed long long s64;
 typedef unsigned long long u64;
-#else /* __s390x__ */
-typedef signed long s64;
-typedef unsigned  long u64;
-#endif /* __s390x__ */
 
 typedef u32 dma_addr_t;
 
diff -Naurd old/include/asm-sparc64/types.h new/include/asm-sparc64/types.h
--- old/include/asm-sparc64/types.h	2004-02-21 03:28:23.000000000 -0500
+++ new/include/asm-sparc64/types.h	2004-02-27 15:42:19.000000000 -0500
@@ -28,8 +28,8 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
 
 #endif /* __ASSEMBLY__ */
 
@@ -48,8 +48,8 @@
 typedef __signed__ int s32;
 typedef unsigned int u32;
 
-typedef __signed__ long s64;
-typedef unsigned long u64;
+typedef __signed__ long long s64;
+typedef unsigned long long u64;
 
 /* Dma addresses come in generic and 64-bit flavours.  */
 




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-28  0:18 ` David Mosberger
@ 2004-02-27 22:16   ` Albert Cahalan
  2004-02-28  0:45     ` David Mosberger
  2004-02-28 10:42     ` Jakub Jelinek
  0 siblings, 2 replies; 15+ messages in thread
From: Albert Cahalan @ 2004-02-27 22:16 UTC (permalink / raw)
  To: davidm
  Cc: Albert Cahalan, linux-kernel mailing list, Linus Torvalds,
	Andrew Morton OSDL

On Fri, 2004-02-27 at 19:18, David Mosberger wrote:
> >>>>> On 27 Feb 2004 15:58:42 -0500, Albert Cahalan <albert@users.sourceforge.net> said:
> 
>   Albert> Casts are considered harmful, because they bypass
>   Albert> type checking, but how do you print a u64 value?
>   Albert> You cast it to "unsigned long long" like this:
> 
>   Albert> printk("%llu\n", (unsigned long long)foo);
> 
>   Albert> Well, this is silly and ugly. As x86-64 has shown,
>   Albert> even a 64-bit port can use "long long" for 64-bit
>   Albert> values. This patch changes all other 64-bit ports.
>   Albert> It now becomes possible to avoid adding new casts
>   Albert> all over the place; existing ones may be removed
>   Albert> if so desired.
> 
> Did you verify that none of the kernel header files that are still
> being used by glibc contain declarations based on __u64 or __s64?  If
> not, your patch breaks user-level code.

Supposing that this is the case, you may get warnings.
Well, good, maybe somebody will fix glibc. The data
types are obviously the same size, so no data-corrupting
errors will result.

Note that x86-64, a 64-bit port using glibc, is just
fine with "long long" already.

Also note that /usr/include/asm is a modified copy of
kernel headers. It won't be suddenly changing as a
result of the patch, even after a kernel upgrade.
(the symlink hasn't been OK since libc5 days)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-28  0:45     ` David Mosberger
@ 2004-02-27 22:53       ` Albert Cahalan
  2004-02-28  7:44       ` David S. Miller
  1 sibling, 0 replies; 15+ messages in thread
From: Albert Cahalan @ 2004-02-27 22:53 UTC (permalink / raw)
  To: davidm
  Cc: Albert Cahalan, linux-kernel mailing list, Linus Torvalds,
	Andrew Morton OSDL

On Fri, 2004-02-27 at 19:45, David Mosberger wrote:
> >>>>> On 27 Feb 2004 17:16:53 -0500, Albert Cahalan <albert@users.sourceforge.net> said:
> 
>   Albert> Supposing that this is the case, you may get warnings.
> 
> Well, then do it on your own kernel/system.  I'm not interested in
> spending time on this now, so please don't touch ia64 unless you
> verified that all the other pieces are in place.

Remember, that is only if all of:

1. glibc improperly uses raw kernel headers
2. usage is in such a way that warnings happen
3. you rebuild glibc with these kernel headers

If this is really the case, the warnings may be
eliminated by running a 1-line sed script over
the headers as they are imported into glibc.
It's something like this:  s/__u64/u_int64_t/

In return, you can have type-safety w/o warnings
during the kernel build.

In my example, suppose that foo is a pointer
to u64. You'd like to print the u64. If by
mistake you use the pointer itself, you won't
be getting a warning. The cast hides it.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-27 20:58 [patch] u64 casts Albert Cahalan
@ 2004-02-28  0:18 ` David Mosberger
  2004-02-27 22:16   ` Albert Cahalan
  0 siblings, 1 reply; 15+ messages in thread
From: David Mosberger @ 2004-02-28  0:18 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: linux-kernel mailing list, Linus Torvalds, Andrew Morton OSDL

>>>>> On 27 Feb 2004 15:58:42 -0500, Albert Cahalan <albert@users.sourceforge.net> said:

  Albert> Casts are considered harmful, because they bypass
  Albert> type checking, but how do you print a u64 value?
  Albert> You cast it to "unsigned long long" like this:

  Albert> printk("%llu\n", (unsigned long long)foo);

  Albert> Well, this is silly and ugly. As x86-64 has shown,
  Albert> even a 64-bit port can use "long long" for 64-bit
  Albert> values. This patch changes all other 64-bit ports.
  Albert> It now becomes possible to avoid adding new casts
  Albert> all over the place; existing ones may be removed
  Albert> if so desired.

Did you verify that none of the kernel header files that are still
being used by glibc contain declarations based on __u64 or __s64?  If
not, your patch breaks user-level code.

	--david

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-27 22:16   ` Albert Cahalan
@ 2004-02-28  0:45     ` David Mosberger
  2004-02-27 22:53       ` Albert Cahalan
  2004-02-28  7:44       ` David S. Miller
  2004-02-28 10:42     ` Jakub Jelinek
  1 sibling, 2 replies; 15+ messages in thread
From: David Mosberger @ 2004-02-28  0:45 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: davidm, linux-kernel mailing list, Linus Torvalds,
	Andrew Morton OSDL

>>>>> On 27 Feb 2004 17:16:53 -0500, Albert Cahalan <albert@users.sourceforge.net> said:

  Albert> Supposing that this is the case, you may get warnings.

Well, then do it on your own kernel/system.  I'm not interested in
spending time on this now, so please don't touch ia64 unless you
verified that all the other pieces are in place.

	--david

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-28  0:45     ` David Mosberger
  2004-02-27 22:53       ` Albert Cahalan
@ 2004-02-28  7:44       ` David S. Miller
  1 sibling, 0 replies; 15+ messages in thread
From: David S. Miller @ 2004-02-28  7:44 UTC (permalink / raw)
  To: davidm; +Cc: davidm, albert, linux-kernel, torvalds, akpm

On Fri, 27 Feb 2004 16:45:16 -0800
David Mosberger <davidm@napali.hpl.hp.com> wrote:

> >>>>> On 27 Feb 2004 17:16:53 -0500, Albert Cahalan <albert@users.sourceforge.net> said:
> 
>   Albert> Supposing that this is the case, you may get warnings.
> 
> Well, then do it on your own kernel/system.  I'm not interested in
> spending time on this now, so please don't touch ia64 unless you
> verified that all the other pieces are in place.

Yes, and I already know that trying to do things this way results
in more warnings and more problems on sparc64, as I've tried it.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] u64 casts
  2004-02-27 22:16   ` Albert Cahalan
  2004-02-28  0:45     ` David Mosberger
@ 2004-02-28 10:42     ` Jakub Jelinek
  2004-02-28 14:46       ` [patch] new version, u64 cast avoidance Albert Cahalan
  1 sibling, 1 reply; 15+ messages in thread
From: Jakub Jelinek @ 2004-02-28 10:42 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: davidm, linux-kernel mailing list, Linus Torvalds,
	Andrew Morton OSDL

On Fri, Feb 27, 2004 at 05:16:53PM -0500, Albert Cahalan wrote:
> Supposing that this is the case, you may get warnings.

It wouldn't be just about warnings if somebody uses current kernel
headers for /usr/include/linux and /usr/include/asm.
Think about C++ name mangling, there it matters a lot of
a type is long long or just long, although they are the same size.

It is true that (hopefully) most of the distributions use separate
modified kernel headers and glibc uses only very few kernel headers
in its headers, but there are certainly many apps in the wild
who #include <linux/*> or #include <asm/*> and I'm afraid still some
people use newest kernel headers for userland stuff.

So if you want to change that, I'd suggest to
#ifdef __KERNEL__
typedef unsigned long long __u64;
#else
typedef unsigned long __u64; /* Provided it has been defined that way before */
#endif

	Jakub

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [patch] new version, u64 cast avoidance
  2004-02-28 10:42     ` Jakub Jelinek
@ 2004-02-28 14:46       ` Albert Cahalan
  2004-02-28 23:58         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 15+ messages in thread
From: Albert Cahalan @ 2004-02-28 14:46 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: davem, davidm, linux-kernel mailing list, Linus Torvalds,
	Andrew Morton OSDL

On Sat, 2004-02-28 at 05:42, Jakub Jelinek wrote:
> On Fri, Feb 27, 2004 at 05:16:53PM -0500, Albert Cahalan wrote:

>> Supposing that this is the case, you may get warnings.
> 
> It wouldn't be just about warnings if somebody uses current kernel
> headers for /usr/include/linux and /usr/include/asm.
> Think about C++ name mangling, there it matters a lot of
> a type is long long or just long, although they are the same size.

That's disgusting.

> So if you want to change that, I'd suggest to
> #ifdef __KERNEL__
> typedef unsigned long long __u64;
> #else
> typedef unsigned long __u64; /* Provided it has been defined that way before */
> #endif

OK, got it. For the changelog:

If the u64 type is "unsigned long" on some platforms
and "unsigned long long" on others, a cast is often
required to avoid warnings. Type safety goes away
when you do that; even a pointer is accepted. Thus
the u64 type should be "unsigned long long" on all
platforms. Now this:
  printk("%llu\n", (unsigned long long)some_u64_value);
can become this:
  printk("%llu\n", some_u64_value);

 asm-alpha/types.h   |   14 ++++++++++++--
 asm-ia64/types.h    |   10 ++++++++++
 asm-mips/types.h    |   25 ++++++++++++-------------
 asm-ppc64/types.h   |   14 ++++++++++++--
 asm-s390/types.h    |   17 +++++++++--------
 asm-sparc64/types.h |   14 ++++++++++++--
 6 files changed, 67 insertions(+), 27 deletions(-)

diff -Naurd old/include/asm-alpha/types.h new/include/asm-alpha/types.h
--- old/include/asm-alpha/types.h	2004-02-21 03:25:04.000000000 -0500
+++ new/include/asm-alpha/types.h	2004-02-28 09:13:04.000000000 -0500
@@ -27,8 +27,18 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long".
+ * (name mangling leads to a purely user-space ABI problem)
+ */
+#ifdef __KERNEL__
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef __signed__ long __s64;
 typedef unsigned long __u64;
+#endif
 
 #endif /* __ASSEMBLY__ */
 
@@ -50,8 +60,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-typedef signed long s64;
-typedef unsigned long u64;
+typedef signed long long s64;
+typedef unsigned long long u64;
 
 typedef u64 dma_addr_t;
 typedef u64 dma64_addr_t;
diff -Naurd old/include/asm-ia64/types.h new/include/asm-ia64/types.h
--- old/include/asm-ia64/types.h	2004-02-21 03:20:17.000000000 -0500
+++ new/include/asm-ia64/types.h	2004-02-28 09:14:49.000000000 -0500
@@ -41,8 +41,18 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long".
+ * (name mangling leads to a purely user-space ABI problem)
+ */
+#ifdef __KERNEL__
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef __signed__ long __s64;
 typedef unsigned long __u64;
+#endif
 
 /*
  * These aren't exported outside the kernel to avoid name space clashes
diff -Naurd old/include/asm-mips/types.h new/include/asm-mips/types.h
--- old/include/asm-mips/types.h	2004-02-21 03:19:29.000000000 -0500
+++ new/include/asm-mips/types.h	2004-02-28 09:23:05.000000000 -0500
@@ -36,8 +36,18 @@
 
 #if (_MIPS_SZLONG == 64)
 
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long".
+ * (name mangling leads to a purely user-space ABI problem)
+ */
+#ifdef __KERNEL__
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef __signed__ long __s64;
 typedef unsigned long __u64;
+#endif
 
 #else
 
@@ -68,19 +78,8 @@
 typedef __signed int s32;
 typedef unsigned int u32;
 
-#if (_MIPS_SZLONG == 64)
-
-typedef __signed__ long s64;
-typedef unsigned long u64;
-
-#else
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long s64;
-typedef unsigned long long u64;
-#endif
-
-#endif
+typedef __s64 s64;
+typedef __u64 u64;
 
 #if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
     || defined(CONFIG_MIPS64)
diff -Naurd old/include/asm-ppc64/types.h new/include/asm-ppc64/types.h
--- old/include/asm-ppc64/types.h	2004-02-21 03:21:11.000000000 -0500
+++ new/include/asm-ppc64/types.h	2004-02-28 09:25:01.000000000 -0500
@@ -32,8 +32,18 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long".
+ * (name mangling leads to a purely user-space ABI problem)
+ */
+#ifdef __KERNEL__
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef __signed__ long __s64;
 typedef unsigned long __u64;
+#endif
 
 typedef struct {
 	__u32 u[4];
@@ -58,8 +68,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-typedef signed long s64;
-typedef unsigned long u64;
+typedef __s64 s64;
+typedef __u64 u64;
 
 typedef __vector128 vector128;
 
diff -Naurd old/include/asm-s390/types.h new/include/asm-s390/types.h
--- old/include/asm-s390/types.h	2004-02-21 03:22:57.000000000 -0500
+++ new/include/asm-s390/types.h	2004-02-28 09:31:14.000000000 -0500
@@ -27,7 +27,13 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
-#ifndef __s390x__
+
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul 64-bit user-space C++ code might rely on this being "long". 
+ * (name mangling leads to a purely user-space ABI problem) 
+ */
+#if defined(__KERNEL__) || !defined(__s390x__)
 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
@@ -67,13 +73,8 @@
 typedef signed int s32;
 typedef unsigned int u32;
 
-#ifndef __s390x__
-typedef signed long long s64;
-typedef unsigned long long u64;
-#else /* __s390x__ */
-typedef signed long s64;
-typedef unsigned  long u64;
-#endif /* __s390x__ */
+typedef __s64 s64;
+typedef __u64 u64;
 
 typedef u32 dma_addr_t;
 
diff -Naurd old/include/asm-sparc64/types.h new/include/asm-sparc64/types.h
--- old/include/asm-sparc64/types.h	2004-02-21 03:28:23.000000000 -0500
+++ new/include/asm-sparc64/types.h	2004-02-28 09:29:53.000000000 -0500
@@ -28,8 +28,18 @@
 typedef __signed__ int __s32;
 typedef unsigned int __u32;
 
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long".
+ * (name mangling leads to a purely user-space ABI problem)
+ */
+#ifdef __KERNEL__
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#else
 typedef __signed__ long __s64;
 typedef unsigned long __u64;
+#endif
 
 #endif /* __ASSEMBLY__ */
 
@@ -48,8 +58,8 @@
 typedef __signed__ int s32;
 typedef unsigned int u32;
 
-typedef __signed__ long s64;
-typedef unsigned long u64;
+typedef __s64 s64;
+typedef __u64 u64;
 
 /* Dma addresses come in generic and 64-bit flavours.  */
 




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-28 23:59           ` Benjamin Herrenschmidt
@ 2004-02-28 22:21             ` Albert Cahalan
  2004-02-29  1:08               ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 15+ messages in thread
From: Albert Cahalan @ 2004-02-28 22:21 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Albert Cahalan, Jakub Jelinek, David S. Miller, davidm,
	linux-kernel mailing list, Linus Torvalds, Andrew Morton OSDL

On Sat, 2004-02-28 at 18:59, Benjamin Herrenschmidt wrote:
> On Sun, 2004-02-29 at 10:58, Benjamin Herrenschmidt wrote:
> > >  asm-ppc64/types.h   |   14 ++++++++++++--
> > 
> > Please, do not mess with ppc64 at this point, I'm not sure
> > I like the approach anyway, I can live with some warnings
> > in printk...
> 
> I meant some casts of course ;)

If only those were casts under arch/ppc64, sure.
All 32-bit ports and x86-64 are being affected.
Besides being ugly and verbose, the current situation
isn't type-safe.

I'd be interested to hear why you don't like the
approach, and interested to hear your alternatives.
For example:

a. my solution, as given
b. move u64 and friends to include/linux/*.h
c. you promise to never complain about warnings
d. printk("Ugly: " U64_FMT "\n", some_u64_value);
e. you patch gcc to modify format strings :-)
f. ...

In other words, how do you propose to eliminate
the casts?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-29  1:08               ` Benjamin Herrenschmidt
@ 2004-02-28 23:49                 ` Albert Cahalan
  2004-02-29  3:25                   ` Matt Mackall
  2004-02-29  1:01                 ` [patch] 3rd " Albert Cahalan
  1 sibling, 1 reply; 15+ messages in thread
From: Albert Cahalan @ 2004-02-28 23:49 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Albert Cahalan, Jakub Jelinek, David S. Miller, davidm,
	linux-kernel mailing list, Linus Torvalds, Andrew Morton OSDL

On Sat, 2004-02-28 at 20:08, Benjamin Herrenschmidt wrote:
> > a. my solution, as given
> > b. move u64 and friends to include/linux/*.h
> > c. you promise to never complain about warnings
> > d. printk("Ugly: " U64_FMT "\n", some_u64_value);
> > e. you patch gcc to modify format strings :-)
> > f. ...
> > 
> > In other words, how do you propose to eliminate
> > the casts?
> 
> Can't we live with those casts at least for a while ?
>
> I don't know honestly what is the best solution,
> they all sound equally ugly to me.

They are, until you count the number of occurances.
My solution, as given, puts #if crud in just 6 files.
The existing situation has crud all over the place,
growing day by day.

If there is some patch merging issue, I'd be happy
to send you a separate patch for ppc64.

If you'd prefer, I can create <linux/bit_types.h>
for these types and pull that in. For now it would
be included by all the asm-*/types.h files. Like so:

#if defined(_BROKEN_USER_TYPES) && !defined(__KERNEL__)
typedef unsigned long __u64;
typedef __signed__ long __s64;
#else
#if defined(__GNUC__)
__extension__ typedef unsigned long long __u64;
__extension__ typedef __signed__ long long __s64;
endif
#endif
/* ... */



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-28 14:46       ` [patch] new version, u64 cast avoidance Albert Cahalan
@ 2004-02-28 23:58         ` Benjamin Herrenschmidt
  2004-02-28 23:59           ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 15+ messages in thread
From: Benjamin Herrenschmidt @ 2004-02-28 23:58 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: Jakub Jelinek, David S. Miller, davidm, linux-kernel mailing list,
	Linus Torvalds, Andrew Morton OSDL


>  asm-ppc64/types.h   |   14 ++++++++++++--

Please, do not mess with ppc64 at this point, I'm not sure
I like the approach anyway, I can live with some warnings
in printk...

Ben.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-28 23:58         ` Benjamin Herrenschmidt
@ 2004-02-28 23:59           ` Benjamin Herrenschmidt
  2004-02-28 22:21             ` Albert Cahalan
  0 siblings, 1 reply; 15+ messages in thread
From: Benjamin Herrenschmidt @ 2004-02-28 23:59 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: Jakub Jelinek, David S. Miller, davidm, linux-kernel mailing list,
	Linus Torvalds, Andrew Morton OSDL

On Sun, 2004-02-29 at 10:58, Benjamin Herrenschmidt wrote:
> >  asm-ppc64/types.h   |   14 ++++++++++++--
> 
> Please, do not mess with ppc64 at this point, I'm not sure
> I like the approach anyway, I can live with some warnings
> in printk...

I meant some casts of course ;)

Ben.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [patch] 3rd version, u64 cast avoidance
  2004-02-29  1:08               ` Benjamin Herrenschmidt
  2004-02-28 23:49                 ` Albert Cahalan
@ 2004-02-29  1:01                 ` Albert Cahalan
  1 sibling, 0 replies; 15+ messages in thread
From: Albert Cahalan @ 2004-02-29  1:01 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Albert Cahalan, Jakub Jelinek, David S. Miller, davidm,
	linux-kernel mailing list, Linus Torvalds, Andrew Morton OSDL

This is option 'b', which eliminates lots of
redundant code. Mult-width arch are handled.

User-space types are unchanged. For the kernel,
all u64 and related types are done with long long,
eliminating the need to lose type-safety with
casts all over the place.

 asm-alpha/types.h   |   30 ++----------------------------
 asm-arm/types.h     |   31 +------------------------------
 asm-arm26/types.h   |   31 +------------------------------
 asm-cris/types.h    |   31 +------------------------------
 asm-h8300/types.h   |   31 +------------------------------
 asm-i386/types.h    |   31 +------------------------------
 asm-ia64/types.h    |   30 ++----------------------------
 asm-m68k/types.h    |   31 +------------------------------
 asm-mips/types.h    |   49 ++-----------------------------------------------
 asm-parisc/types.h  |   31 +------------------------------
 asm-ppc/types.h     |   26 +-------------------------
 asm-ppc64/types.h   |   30 ++----------------------------
 asm-s390/types.h    |   42 +++---------------------------------------
 asm-sh/types.h      |   31 +------------------------------
 asm-sparc/types.h   |   24 +-----------------------
 asm-sparc64/types.h |   30 ++----------------------------
 asm-v850/types.h    |   31 +------------------------------
 asm-x86_64/types.h  |   29 +----------------------------
 linux/bit_types.h   |   37 +++++++++++++++++++++++++++++++++++++
 19 files changed, 62 insertions(+), 544 deletions(-)

diff -Naurd old/include/asm-alpha/types.h new/include/asm-alpha/types.h
--- old/include/asm-alpha/types.h	2004-02-21 03:25:04.000000000 -0500
+++ new/include/asm-alpha/types.h	2004-02-28 19:28:38.000000000 -0500
@@ -13,22 +13,8 @@
 
 typedef unsigned int umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+#define _BROKEN_U64_S64
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -41,18 +27,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long s64;
-typedef unsigned long u64;
-
 typedef u64 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -Naurd old/include/asm-arm/types.h new/include/asm-arm/types.h
--- old/include/asm-arm/types.h	2004-02-21 03:19:13.000000000 -0500
+++ new/include/asm-arm/types.h	2004-02-28 19:30:06.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -35,18 +18,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-arm26/types.h new/include/asm-arm26/types.h
--- old/include/asm-arm26/types.h	2004-02-21 03:19:02.000000000 -0500
+++ new/include/asm-arm26/types.h	2004-02-28 19:30:44.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -35,18 +18,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-cris/types.h new/include/asm-cris/types.h
--- old/include/asm-cris/types.h	2004-02-21 03:23:34.000000000 -0500
+++ new/include/asm-cris/types.h	2004-02-28 19:31:13.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -35,18 +18,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide, just like our other addresses.  */
  
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-h8300/types.h new/include/asm-h8300/types.h
--- old/include/asm-h8300/types.h	2004-02-21 03:24:05.000000000 -0500
+++ new/include/asm-h8300/types.h	2004-02-28 19:31:50.000000000 -0500
@@ -13,42 +13,13 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 /*
  * These aren't exported outside the kernel to avoid name space clashes
  */
 #ifdef __KERNEL__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 #define BITS_PER_LONG 32
 
 /* Dma addresses are 32-bits wide.  */
diff -Naurd old/include/asm-i386/types.h new/include/asm-i386/types.h
--- old/include/asm-i386/types.h	2004-02-21 03:23:45.000000000 -0500
+++ new/include/asm-i386/types.h	2004-02-28 19:32:20.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -37,18 +20,6 @@
 
 #include <linux/config.h>
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* DMA addresses come in generic and 64-bit flavours.  */
 
 #ifdef CONFIG_HIGHMEM64G
diff -Naurd old/include/asm-ia64/types.h new/include/asm-ia64/types.h
--- old/include/asm-ia64/types.h	2004-02-21 03:20:17.000000000 -0500
+++ new/include/asm-ia64/types.h	2004-02-28 19:32:59.000000000 -0500
@@ -27,40 +27,14 @@
 
 typedef unsigned int umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+#define _BROKEN_U64_S64
+#include <linux/bit_types.h>
 
 /*
  * These aren't exported outside the kernel to avoid name space clashes
  */
 # ifdef __KERNEL__
 
-typedef __s8 s8;
-typedef __u8 u8;
-
-typedef __s16 s16;
-typedef __u16 u16;
-
-typedef __s32 s32;
-typedef __u32 u32;
-
-typedef __s64 s64;
-typedef __u64 u64;
-
 #define BITS_PER_LONG 64
 
 /* DMA addresses are 64-bits wide, in general.  */
diff -Naurd old/include/asm-m68k/types.h new/include/asm-m68k/types.h
--- old/include/asm-m68k/types.h	2004-02-21 03:18:50.000000000 -0500
+++ new/include/asm-m68k/types.h	2004-02-28 19:33:25.000000000 -0500
@@ -13,24 +13,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -43,18 +26,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* DMA addresses are always 32-bits wide */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-mips/types.h new/include/asm-mips/types.h
--- old/include/asm-mips/types.h	2004-02-21 03:19:29.000000000 -0500
+++ new/include/asm-mips/types.h	2004-02-28 19:34:58.000000000 -0500
@@ -20,33 +20,11 @@
 typedef unsigned int umode_t;
 #endif
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
 #if (_MIPS_SZLONG == 64)
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-
-#else
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
+#define _BROKEN_U64_S64
 #endif
+#include <linux/bit_types.h>
 
-#endif
 
 #endif /* __ASSEMBLY__ */
 
@@ -59,29 +37,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef __signed char s8;
-typedef unsigned char u8;
-
-typedef __signed short s16;
-typedef unsigned short u16;
-
-typedef __signed int s32;
-typedef unsigned int u32;
-
-#if (_MIPS_SZLONG == 64)
-
-typedef __signed__ long s64;
-typedef unsigned long u64;
-
-#else
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long s64;
-typedef unsigned long long u64;
-#endif
-
-#endif
-
 #if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
     || defined(CONFIG_MIPS64)
 typedef u64 dma_addr_t;
diff -Naurd old/include/asm-parisc/types.h new/include/asm-parisc/types.h
--- old/include/asm-parisc/types.h	2004-02-21 03:19:57.000000000 -0500
+++ new/include/asm-parisc/types.h	2004-02-28 19:35:48.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -39,18 +22,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-ppc/types.h new/include/asm-ppc/types.h
--- old/include/asm-ppc/types.h	2004-02-21 03:26:52.000000000 -0500
+++ new/include/asm-ppc/types.h	2004-02-28 19:36:19.000000000 -0500
@@ -3,19 +3,7 @@
 
 #ifndef __ASSEMBLY__
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 typedef struct {
 	__u32 u[4];
@@ -37,18 +25,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 typedef __vector128 vector128;
 
 /* DMA addresses are 32-bits wide */
diff -Naurd old/include/asm-ppc64/types.h new/include/asm-ppc64/types.h
--- old/include/asm-ppc64/types.h	2004-02-21 03:21:11.000000000 -0500
+++ new/include/asm-ppc64/types.h	2004-02-28 19:36:57.000000000 -0500
@@ -18,22 +18,8 @@
 
 typedef unsigned int umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+#define _BROKEN_U64_S64
+#include <linux/bit_types.h>
 
 typedef struct {
 	__u32 u[4];
@@ -49,18 +35,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long s64;
-typedef unsigned long u64;
-
 typedef __vector128 vector128;
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-s390/types.h new/include/asm-s390/types.h
--- old/include/asm-s390/types.h	2004-02-21 03:22:57.000000000 -0500
+++ new/include/asm-s390/types.h	2004-02-28 19:38:14.000000000 -0500
@@ -13,29 +13,10 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#ifndef __s390x__
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
-#else /* __s390x__ */
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+#ifdef __s390x__
+#define _BROKEN_U64_S64
 #endif
+#include <linux/bit_types.h>
 
 /* A address type so that arithmetic can be done on it & it can be upgraded to
    64 bit when necessary 
@@ -58,23 +39,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-#ifndef __s390x__
-typedef signed long long s64;
-typedef unsigned long long u64;
-#else /* __s390x__ */
-typedef signed long s64;
-typedef unsigned  long u64;
-#endif /* __s390x__ */
-
 typedef u32 dma_addr_t;
 
 #ifndef __s390x__
diff -Naurd old/include/asm-sh/types.h new/include/asm-sh/types.h
--- old/include/asm-sh/types.h	2004-02-21 03:27:11.000000000 -0500
+++ new/include/asm-sh/types.h	2004-02-28 19:38:47.000000000 -0500
@@ -5,24 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -35,18 +18,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef __signed__ char s8;
-typedef unsigned char u8;
-
-typedef __signed__ short s16;
-typedef unsigned short u16;
-
-typedef __signed__ int s32;
-typedef unsigned int u32;
-
-typedef __signed__ long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-sparc/types.h new/include/asm-sparc/types.h
--- old/include/asm-sparc/types.h	2004-02-21 03:22:57.000000000 -0500
+++ new/include/asm-sparc/types.h	2004-02-28 19:39:25.000000000 -0500
@@ -19,17 +19,7 @@
 
 typedef unsigned short umode_t;
 
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -39,18 +29,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef __signed__ char s8;
-typedef unsigned char u8;
-
-typedef __signed__ short s16;
-typedef unsigned short u16;
-
-typedef __signed__ int s32;
-typedef unsigned int u32;
-
-typedef __signed__ long long s64;
-typedef unsigned long long u64;
-
 typedef u32 dma_addr_t;
 typedef u32 dma64_addr_t;
 
diff -Naurd old/include/asm-sparc64/types.h new/include/asm-sparc64/types.h
--- old/include/asm-sparc64/types.h	2004-02-21 03:28:23.000000000 -0500
+++ new/include/asm-sparc64/types.h	2004-02-28 19:39:55.000000000 -0500
@@ -14,22 +14,8 @@
 
 typedef unsigned short umode_t;
 
-/*
- * _xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space.
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
+#define _BROKEN_U64_S64
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -39,18 +25,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef __signed__ char s8;
-typedef unsigned char u8;
-
-typedef __signed__ short s16;
-typedef unsigned short u16;
-
-typedef __signed__ int s32;
-typedef unsigned int u32;
-
-typedef __signed__ long s64;
-typedef unsigned long u64;
-
 /* Dma addresses come in generic and 64-bit flavours.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-v850/types.h new/include/asm-v850/types.h
--- old/include/asm-v850/types.h	2004-02-21 03:26:16.000000000 -0500
+++ new/include/asm-v850/types.h	2004-02-28 19:40:34.000000000 -0500
@@ -13,24 +13,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif
+#include <linux/bit_types.h>
 
 #endif /* !__ASSEMBLY__ */
 
@@ -43,18 +26,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 /* Dma addresses are 32-bits wide.  */
 
 typedef u32 dma_addr_t;
diff -Naurd old/include/asm-x86_64/types.h new/include/asm-x86_64/types.h
--- old/include/asm-x86_64/types.h	2004-02-21 03:26:16.000000000 -0500
+++ new/include/asm-x86_64/types.h	2004-02-28 19:40:57.000000000 -0500
@@ -5,22 +5,7 @@
 
 typedef unsigned short umode_t;
 
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-typedef __signed__ char __s8;
-typedef unsigned char __u8;
-
-typedef __signed__ short __s16;
-typedef unsigned short __u16;
-
-typedef __signed__ int __s32;
-typedef unsigned int __u32;
-
-typedef __signed__ long long __s64;
-typedef unsigned long long  __u64;
+#include <linux/bit_types.h>
 
 #endif /* __ASSEMBLY__ */
 
@@ -33,18 +18,6 @@
 
 #ifndef __ASSEMBLY__
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
-typedef unsigned int u32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 typedef u64 dma64_addr_t;
 typedef u64 dma_addr_t;
 
diff -Naurd old/include/linux/bit_types.h new/include/linux/bit_types.h
--- old/include/linux/bit_types.h	1969-12-31 19:00:00.000000000 -0500
+++ new/include/linux/bit_types.h	2004-02-28 19:22:41.000000000 -0500
@@ -0,0 +1,37 @@
+#ifndef _LINUX_BIT_TYPES_H
+#define _LINUX_BIT_TYPES_H
+
+typedef __signed__ char  s8;
+typedef unsigned   char  u8;
+typedef __signed__ short s16;
+typedef unsigned   short u16;
+typedef __signed__ int   s32;
+typedef unsigned   int   u32;
+
+/*
+ * We want "long long" in the kernel to reduce the need for casts,
+ * but foul user-space C++ code might rely on this being "long". 
+ * (name mangling leads to a purely user-space ABI problem) 
+ */
+#if defined(_BROKEN_U64_S64) && !defined(__KERNEL__)
+typedef unsigned   long __u64;
+typedef __signed__ long __s64;
+#else
+#if defined(__GNUC__)
+__extension__ typedef unsigned   long long __u64;
+__extension__ typedef __signed__ long long __s64;
+endif
+#endif
+
+#ifdef __KERNEL__
+typedef __s8 s8;
+typedef __u8 u8;
+typedef __s16 s16;
+typedef __u16 u16;
+typedef __s32 s32;
+typedef __u32 u32;
+typedef __s64 s64;
+typedef __u64 u64;
+#endif
+
+#endif /* _LINUX_BIT_TYPES_H */




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-28 22:21             ` Albert Cahalan
@ 2004-02-29  1:08               ` Benjamin Herrenschmidt
  2004-02-28 23:49                 ` Albert Cahalan
  2004-02-29  1:01                 ` [patch] 3rd " Albert Cahalan
  0 siblings, 2 replies; 15+ messages in thread
From: Benjamin Herrenschmidt @ 2004-02-29  1:08 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: Jakub Jelinek, David S. Miller, davidm, linux-kernel mailing list,
	Linus Torvalds, Andrew Morton OSDL


> a. my solution, as given
> b. move u64 and friends to include/linux/*.h
> c. you promise to never complain about warnings
> d. printk("Ugly: " U64_FMT "\n", some_u64_value);
> e. you patch gcc to modify format strings :-)
> f. ...
> 
> In other words, how do you propose to eliminate
> the casts?

Can't we live with those casts at least for a while ?

I don't know honestly what is the best solution, they all sound
equally ugly to me.

Ben.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch] new version, u64 cast avoidance
  2004-02-28 23:49                 ` Albert Cahalan
@ 2004-02-29  3:25                   ` Matt Mackall
  0 siblings, 0 replies; 15+ messages in thread
From: Matt Mackall @ 2004-02-29  3:25 UTC (permalink / raw)
  To: Albert Cahalan
  Cc: Benjamin Herrenschmidt, Jakub Jelinek, David S. Miller, davidm,
	linux-kernel mailing list, Linus Torvalds, Andrew Morton OSDL

On Sat, Feb 28, 2004 at 06:49:23PM -0500, Albert Cahalan wrote:
> On Sat, 2004-02-28 at 20:08, Benjamin Herrenschmidt wrote:
> > > a. my solution, as given
> > > b. move u64 and friends to include/linux/*.h
> > > c. you promise to never complain about warnings
> > > d. printk("Ugly: " U64_FMT "\n", some_u64_value);
> > > e. you patch gcc to modify format strings :-)
> > > f. ...
> > > 
> > > In other words, how do you propose to eliminate
> > > the casts?
> > 
> > Can't we live with those casts at least for a while ?
> >
> > I don't know honestly what is the best solution,
> > they all sound equally ugly to me.
> 
> They are, until you count the number of occurances.
> My solution, as given, puts #if crud in just 6 files.
> The existing situation has crud all over the place,
> growing day by day.
> 
> If there is some patch merging issue, I'd be happy
> to send you a separate patch for ppc64.
> 
> If you'd prefer, I can create <linux/bit_types.h>
> for these types and pull that in. For now it would
> be included by all the asm-*/types.h files. Like so:
> 
> #if defined(_BROKEN_USER_TYPES) && !defined(__KERNEL__)
> typedef unsigned long __u64;
> typedef __signed__ long __s64;
> #else
> #if defined(__GNUC__)
> __extension__ typedef unsigned long long __u64;
> __extension__ typedef __signed__ long long __s64;
> endif
> #endif
> /* ... */

And if we can actually manage to eliminate the long-deprecated
inclusion of kernel headers by userspace in 2.7, we can kill that
conditional too.

-- 
Matt Mackall : http://www.selenic.com : Linux development and consulting

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2004-02-29  3:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-27 20:58 [patch] u64 casts Albert Cahalan
2004-02-28  0:18 ` David Mosberger
2004-02-27 22:16   ` Albert Cahalan
2004-02-28  0:45     ` David Mosberger
2004-02-27 22:53       ` Albert Cahalan
2004-02-28  7:44       ` David S. Miller
2004-02-28 10:42     ` Jakub Jelinek
2004-02-28 14:46       ` [patch] new version, u64 cast avoidance Albert Cahalan
2004-02-28 23:58         ` Benjamin Herrenschmidt
2004-02-28 23:59           ` Benjamin Herrenschmidt
2004-02-28 22:21             ` Albert Cahalan
2004-02-29  1:08               ` Benjamin Herrenschmidt
2004-02-28 23:49                 ` Albert Cahalan
2004-02-29  3:25                   ` Matt Mackall
2004-02-29  1:01                 ` [patch] 3rd " Albert Cahalan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox