On 10/05/2009 10:08 PM, Eric Anholt wrote:
> On Mon, 2009-10-05 at 15:35 -0400, Adam Jackson wrote:
>   
>> On Sun, 2009-10-04 at 12:08 +1100, Daniel Stone wrote:
>>     
>>> On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
>>>       
>>>> On 64-bit systems, int and pointers don't have the same size, so GCC gives
>>>> warnings about casts between int and pointer types. However, in the cases
>>>> covered by this patch, it's always a value that fits in int being stored
>>>> temporarily as a pointer and then converted back later, which is safe.
>>>> Casting through the pointer-sized integer type intptr_t convinces the
>>>> compiler that this is OK.
>>>>
>>>> Signed-off-by: Jamey Sharp <ja...@minilop.net>
>>>>         
>>> Alan, Matthieu -- is this portable enough?
>>>       
>> intptr_t is part of stdint.h in C99, but seems to also be in unistd.h in
>> UNIX98, which is nearly universal by this point unlike C99.
>>
>> I would love love love to see us move entirely to stdint types instead
>> of the mess we've got now.
>>     
> Yes.  Yes yes yes.
>   

I have a patch sitting around that does this, guess I'll float it.

The key file is x11proto/Xmd.h.  Xdefs.h and X.h also have some
redefinitions.  I just moved what I could into Xmd.h since both other
headers include it.

The behavior in configure.ac is kind of naive.  The proper solution
probably involves some kind of Xmd.h.in file.

--Eamon


commit 5a8962bb85045eb3500a51ea2f30b21ac3dca51e
Author: Eamon Walsh <ewa...@tycho.nsa.gov>
Date:   Wed Oct 21 20:46:33 2009 -0400

    Convert CARD32 and friends to use standard integer types.
    
    Requires stdint.h to be present and contain the C99 type definitions.
    Also moves some resource type definitions from X.h and Xdefs.h.

diff --git a/X.h b/X.h
index 5cf695d..5d8e849 100644
--- a/X.h
+++ b/X.h
@@ -53,59 +53,7 @@ SOFTWARE.
 #define X_PROTOCOL	11		/* current protocol version */
 #define X_PROTOCOL_REVISION 0		/* current minor version */
 
-/* Resources */
-
-/*
- * _XSERVER64 must ONLY be defined when compiling X server sources on
- * systems where unsigned long is not 32 bits, must NOT be used in
- * client or library code.
- */
-#ifndef _XSERVER64
-#  ifndef _XTYPEDEF_XID
-#    define _XTYPEDEF_XID
-typedef unsigned long XID;
-#  endif
-#  ifndef _XTYPEDEF_MASK
-#    define _XTYPEDEF_MASK
-typedef unsigned long Mask;
-#  endif
-#  ifndef _XTYPEDEF_ATOM
-#    define _XTYPEDEF_ATOM
-typedef unsigned long Atom;		/* Also in Xdefs.h */
-#  endif
-typedef unsigned long VisualID;
-typedef unsigned long Time;
-#else
-#  include <X11/Xmd.h>
-#  ifndef _XTYPEDEF_XID
-#    define _XTYPEDEF_XID
-typedef CARD32 XID;
-#  endif
-#  ifndef _XTYPEDEF_MASK
-#    define _XTYPEDEF_MASK
-typedef CARD32 Mask;
-#  endif
-#  ifndef _XTYPEDEF_ATOM
-#    define _XTYPEDEF_ATOM
-typedef CARD32 Atom;
-#  endif
-typedef CARD32 VisualID;
-typedef CARD32 Time;
-#endif
-
-typedef XID Window;
-typedef XID Drawable;
-#ifndef _XTYPEDEF_FONT
-#  define _XTYPEDEF_FONT
-typedef XID Font;
-#endif
-typedef XID Pixmap;
-typedef XID Cursor;
-typedef XID Colormap;
-typedef XID GContext;
-typedef XID KeySym;
-
-typedef unsigned char KeyCode;
+#include <X11/Xmd.h>
 
 /*****************************************************************
  * RESERVED RESOURCE AND CONSTANT DEFINITIONS
diff --git a/Xdefs.h b/Xdefs.h
index 46ffdad..44c134b 100644
--- a/Xdefs.h
+++ b/Xdefs.h
@@ -28,72 +28,25 @@ authorization from The XFree86 Project Inc..
 #ifndef _XDEFS_H
 #define _XDEFS_H
 
-#ifdef _XSERVER64
 #include <X11/Xmd.h>
-#endif 
-
-#ifndef _XTYPEDEF_ATOM
-#  define _XTYPEDEF_ATOM
-#  ifndef _XSERVER64
-typedef unsigned long Atom;
-#  else
-typedef CARD32 Atom;
-#  endif
-#endif
 
 #ifndef Bool
-#  ifndef _XTYPEDEF_BOOL
-#   define _XTYPEDEF_BOOL
 typedef int Bool;
-#  endif
 #endif
 
-#ifndef _XTYPEDEF_POINTER
-#  define _XTYPEDEF_POINTER
 typedef void *pointer;
-#endif
 
 #ifndef _XTYPEDEF_CLIENTPTR
 typedef struct _Client *ClientPtr;
 #  define _XTYPEDEF_CLIENTPTR
 #endif
 
-#ifndef _XTYPEDEF_XID
-#  define _XTYPEDEF_XID
-#  ifndef _XSERVER64
-typedef unsigned long XID;
-#  else
-typedef CARD32 XID;
-#  endif
-#endif
-
-#ifndef _XTYPEDEF_MASK
-#  define _XTYPEDEF_MASK
-#  ifndef _XSERVER64
-typedef unsigned long Mask;
-#  else
-typedef CARD32 Mask;
-#  endif
-#endif
-
 #ifndef _XTYPEDEF_FONTPTR
 #  define _XTYPEDEF_FONTPTR
 typedef struct _Font *FontPtr; /* also in fonts/include/font.h */
 #endif
 
-#ifndef _XTYPEDEF_FONT
-#  define _XTYPEDEF_FONT
-typedef XID	Font;
-#endif
-
-#ifndef _XTYPEDEF_FSID
-#  ifndef _XSERVER64
-typedef unsigned long FSID;
-#  else
 typedef CARD32 FSID;
-#  endif
-#endif
-
 typedef FSID AccContext;
 
 /* OS independent time value 
diff --git a/Xmd.h b/Xmd.h
index f3868b3..0478213 100644
--- a/Xmd.h
+++ b/Xmd.h
@@ -49,6 +49,7 @@ SOFTWARE.
 /*
  *  Xmd.h: MACHINE DEPENDENT DECLARATIONS.
  */
+#include <stdint.h>
 
 /*
  * Special per-machine configuration flags.
@@ -98,43 +99,21 @@ SOFTWARE.
  * need them.  Note that bitfields are not guaranteed to be signed
  * (or even unsigned) according to ANSI C.
  */
-# ifdef WORD64
-typedef long INT64;
-typedef unsigned long CARD64;
-#  define B32 :32
-#  define B16 :16
-#  ifdef UNSIGNEDBITFIELDS
-typedef unsigned int INT32;
-typedef unsigned int INT16;
-#  else
-typedef signed int INT32;
-typedef signed int INT16;
-#  endif
-# else
-#  define B32
-#  define B16
-#  ifdef LONG64
-typedef long INT64;
-typedef int INT32;
-#  else
-typedef long INT32;
-#  endif
-typedef short INT16;
-# endif
+#define B32
+#define B16
 
-typedef signed char    INT8;
+/*
+ * Standard integer types.
+ */
 
-# ifdef LONG64
-typedef unsigned long CARD64;
-typedef unsigned int CARD32;
-# else
-typedef unsigned long CARD32;
-# endif
-# if !defined(WORD64) && !defined(LONG64)
-typedef unsigned long long CARD64;
-# endif
-typedef unsigned short CARD16;
-typedef unsigned char  CARD8;
+typedef uint8_t  CARD8;
+typedef uint16_t CARD16;
+typedef uint32_t CARD32;
+typedef uint64_t CARD64;
+typedef int8_t   INT8;
+typedef int16_t  INT16;
+typedef int32_t  INT32;
+typedef int64_t  INT64;
 
 typedef CARD32		BITS32;
 typedef CARD16		BITS16;
@@ -143,6 +122,26 @@ typedef CARD8		BYTE;
 typedef CARD8		BOOL;
 
 /*
+ * Resources
+ */
+typedef CARD32 XID;
+typedef CARD32 Mask;
+typedef CARD32 Atom;
+typedef CARD32 VisualID;
+typedef CARD32 Time;
+
+typedef XID Window;
+typedef XID Drawable;
+typedef XID Font;
+typedef XID Pixmap;
+typedef XID Cursor;
+typedef XID Colormap;
+typedef XID GContext;
+typedef XID KeySym;
+
+typedef unsigned char KeyCode;
+
+/*
  * definitions for sign-extending bitfields on 64-bit architectures
  */
 # if defined(WORD64) && defined(UNSIGNEDBITFIELDS)
diff --git a/Xproto.h b/Xproto.h
index 495d441..fb17389 100644
--- a/Xproto.h
+++ b/Xproto.h
@@ -232,24 +232,6 @@ SOFTWARE.
 #define sz_xChangeKeyboardMappingReq 8
 
 
-/* For the purpose of the structure definitions in this file,
-we must redefine the following types in terms of Xmd.h's types, which may
-include bit fields.  All of these are #undef'd at the end of this file,
-restoring the definitions in X.h.  */
-
-#define Window CARD32
-#define Drawable CARD32
-#define Font CARD32
-#define Pixmap CARD32
-#define Cursor CARD32
-#define Colormap CARD32
-#define GContext CARD32
-#define Atom CARD32
-#define VisualID CARD32
-#define Time CARD32
-#define KeyCode CARD8
-#define KeySym CARD32
-
 #define X_TCP_PORT 6000     /* add display number */
 
 #define xTrue        1
@@ -2140,18 +2122,4 @@ typedef struct { /* followed by LIST of ATOM */
 #define X_GetModifierMapping	       119
 #define X_NoOperation                  127
 
-/* restore these definitions back to the typedefs in X.h */
-#undef Window
-#undef Drawable
-#undef Font
-#undef Pixmap
-#undef Cursor
-#undef Colormap
-#undef GContext
-#undef Atom
-#undef VisualID
-#undef Time
-#undef KeyCode
-#undef KeySym
-
 #endif /* XPROTO_H */
diff --git a/configure.ac b/configure.ac
index a0b44ec..9735055 100755
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,15 @@ AC_ARG_ENABLE(wide-prototypes,
 
 AC_CHECK_HEADERS([sys/select.h sys/param.h sys/types.h sys/time.h])
 
+# C99 Types are now a requirement.
+AC_CHECK_HEADER([stdint.h],
+                [],
+                [AC_MSG_ERROR([stdint.h required but not found.])])
+AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t],
+               [],
+               [AC_MSG_ERROR([stdint.h does not contain required C99 types.])],
+               [#include <stdint.h>])
+
 # Handle Xpoll.h.in
 # Avoid determining fds_bits on WIN32 hosts (not including cygwin)
 case $host_os in
_______________________________________________
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to