[PATCH:libX11 2/3] unifdef WORD64

Alan Coopersmith alan.coopersmith at oracle.com
Fri Mar 1 14:06:57 PST 2013


WORD64 seems to have only been defined in <X11/Xmd.h> when building for
CRAY, to handle int being a 64-bit value (ILP64, not LP64) and having
64-bit alignment requirements.

It hadn't been fully supported even before autotooling, as can be
seen by removed code such as:

 #ifdef WORD64
 _XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
 #endif

(mostly performed with unifdef, followed by some manual cleanup of
 the remaining code)

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 include/X11/Xlibint.h |   37 +-------
 src/ImUtil.c          |   14 +--
 src/LiHosts.c         |    7 --
 src/Macros.c          |    5 --
 src/Quarks.c          |    4 -
 src/SendEvent.c       |    5 --
 src/XlibInt.c         |  236 -------------------------------------------------
 src/xkb/XKBNames.c    |   56 ------------
 src/xkb/XKBRdBuf.c    |   28 ------
 src/xkb/XKBlibint.h   |    2 +-
 10 files changed, 4 insertions(+), 390 deletions(-)

diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
index 5a7c0ed..48323f7 100644
--- a/include/X11/Xlibint.h
+++ b/include/X11/Xlibint.h
@@ -408,25 +408,8 @@ extern LockInfoPtr _Xglobal_lock;
  * X Protocol packetizing macros.
  */
 
-/*   Need to start requests on 64 bit word boundaries
- *   on a CRAY computer so add a NoOp (127) if needed.
- *   A character pointer on a CRAY computer will be non-zero
- *   after shifting right 61 bits of it is not pointing to
- *   a word boundary.
- */
-#ifdef WORD64
-#define WORD64ALIGN if ((long)dpy->bufptr >> 61) {\
-           dpy->last_req = dpy->bufptr;\
-           *(dpy->bufptr)   = X_NoOperation;\
-           *(dpy->bufptr+1) =  0;\
-           *(dpy->bufptr+2) =  0;\
-           *(dpy->bufptr+3) =  1;\
-             dpy->request++;\
-             dpy->bufptr += 4;\
-         }
-#else /* else does not require alignment on 64-bit boundaries */
+/* Leftover from CRAY support - was defined empty on all non-Cray systems */
 #define WORD64ALIGN
-#endif /* WORD64 */
 
 /**
  * Return a len-sized request buffer for the request type. This function may
@@ -510,18 +493,6 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
 	req = (xReq *) _XGetRequest(dpy, X_/**/name, SIZEOF(xReq))
 #endif
 
-#ifdef WORD64
-#define MakeBigReq(req,n) \
-    { \
-    char _BRdat[4]; \
-    unsigned long _BRlen = req->length - 1; \
-    req->length = 0; \
-    memcpy(_BRdat, ((char *)req) + (_BRlen << 2), 4); \
-    memmove(((char *)req) + 8, ((char *)req) + 4, _BRlen << 2); \
-    memcpy(((char *)req) + 4, _BRdat, 4); \
-    Data32(dpy, (long *)&_BRdat, 4); \
-    }
-#else
 #ifdef LONG64
 #define MakeBigReq(req,n) \
     { \
@@ -545,7 +516,6 @@ extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
     Data32(dpy, &_BRdat, 4); \
     }
 #endif
-#endif
 
 #ifndef __clang_analyzer__
 #define SetReqLen(req,n,badlen) \
@@ -609,10 +579,6 @@ extern void _XFlushGCCache(Display *dpy, GC gc);
     memset(ptr, '\0', n); \
     dpy->bufptr += (n);
 
-#ifdef WORD64
-#define Data16(dpy, data, len) _XData16(dpy, (_Xconst short *)data, len)
-#define Data32(dpy, data, len) _XData32(dpy, (_Xconst long *)data, len)
-#else
 #define Data16(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len))
 #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
 #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
@@ -632,7 +598,6 @@ extern void _XRead32(
 #define Data32(dpy, data, len) Data((dpy), (_Xconst char *)(data), (len))
 #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
 #endif
-#endif /* not WORD64 */
 
 #define PackData16(dpy,data,len) Data16 (dpy, data, len)
 #define PackData32(dpy,data,len) Data32 (dpy, data, len)
diff --git a/src/ImUtil.c b/src/ImUtil.c
index 3164d43..fa8d464 100644
--- a/src/ImUtil.c
+++ b/src/ImUtil.c
@@ -528,9 +528,7 @@ static unsigned long _XGetPixel (
 	  return (pixel & low_bits_table[ximage->depth]);
 }
 
-#ifndef WORD64
 static CARD32 const byteorderpixel = MSBFirst << 24;
-#endif
 
 static unsigned long _XGetPixel32 (
     register XImage *ximage,
@@ -543,12 +541,9 @@ static unsigned long _XGetPixel32 (
 	if ((ximage->format == ZPixmap) && (ximage->bits_per_pixel == 32)) {
 	    addr = &((unsigned char *)ximage->data)
 			[y * ximage->bytes_per_line + (x << 2)];
-#ifndef WORD64
 	    if (*((const char *)&byteorderpixel) == ximage->byte_order)
 		pixel = *((CARD32 *)addr);
-	    else
-#endif
-	    if (ximage->byte_order == MSBFirst)
+	    else if (ximage->byte_order == MSBFirst)
 		pixel = ((unsigned long)addr[0] << 24 |
 			 (unsigned long)addr[1] << 16 |
 			 (unsigned long)addr[2] << 8 |
@@ -734,12 +729,9 @@ static int _XPutPixel32 (
 	if ((ximage->format == ZPixmap) && (ximage->bits_per_pixel == 32)) {
 	    addr = &((unsigned char *)ximage->data)
 			[y * ximage->bytes_per_line + (x << 2)];
-#ifndef WORD64
 	    if (*((const char *)&byteorderpixel) == ximage->byte_order)
 		*((CARD32 *)addr) = pixel;
-	    else
-#endif
-	    if (ximage->byte_order == MSBFirst) {
+	    else if (ximage->byte_order == MSBFirst) {
 		addr[0] = pixel >> 24;
 		addr[1] = pixel >> 16;
 		addr[2] = pixel >> 8;
@@ -997,7 +989,6 @@ _XAddPixel (
 	    x = ximage->bytes_per_line * ximage->height;
 	    while (--x >= 0)
 		*dp++ += value;
-#ifndef WORD64
 	} else if ((ximage->format == ZPixmap) &&
 		   (ximage->bits_per_pixel == 16) &&
 		   (*((const char *)&byteorderpixel) == ximage->byte_order)) {
@@ -1012,7 +1003,6 @@ _XAddPixel (
 	    x = (ximage->bytes_per_line >> 2) * ximage->height;
 	    while (--x >= 0)
 		*dp++ += value;
-#endif
 	} else {
 	    for (y = ximage->height; --y >= 0; ) {
 		for (x = ximage->width; --x >= 0; ) {
diff --git a/src/LiHosts.c b/src/LiHosts.c
index 5ae70d5..0f5e837 100644
--- a/src/LiHosts.c
+++ b/src/LiHosts.c
@@ -111,15 +111,8 @@ XHostAddress *XListHosts (
 	_XRead (dpy, (char *) buf, nbytes);
 
 	for (i = 0; i < reply.nHosts; i++) {
-#ifdef WORD64
-	    xHostEntry xhe;
-	    memcpy((char *)&xhe, bp, SIZEOF(xHostEntry));
-	    op->family = xhe.family;
-	    op->length = xhe.length;
-#else
 	    op->family = ((xHostEntry *) bp)->family;
 	    op->length =((xHostEntry *) bp)->length;
-#endif
 	    if (op->family == FamilyServerInterpreted) {
 		char *tp = (char *) (bp + SIZEOF(xHostEntry));
 		char *vp = memchr(tp, 0, op->length);
diff --git a/src/Macros.c b/src/Macros.c
index 42d4cf1..cfc083a 100644
--- a/src/Macros.c
+++ b/src/Macros.c
@@ -137,12 +137,7 @@ int XImageByteOrder(Display *dpy) { return (ImageByteOrder(dpy)); }
 
 unsigned long XNextRequest(Display *dpy)
 {
-#ifdef WORD64
-    WORD64ALIGN
-    return dpy->request + 1;
-#else
     return (NextRequest(dpy));
-#endif
 }
 
 unsigned long XLastKnownRequestProcessed(Display *dpy)
diff --git a/src/Quarks.c b/src/Quarks.c
index 7a704b1..4eb90c5 100644
--- a/src/Quarks.c
+++ b/src/Quarks.c
@@ -131,10 +131,8 @@ static char *permalloc(unsigned int length)
     return(ret);
 }
 
-#ifndef WORD64
 typedef struct {char a; double b;} TestType1;
 typedef struct {char a; unsigned long b;} TestType2;
-#endif
 
 #ifdef XTHREADS
 static char *_Xpermalloc(unsigned int length);
@@ -157,7 +155,6 @@ char *Xpermalloc(unsigned int length)
     int i;
 
     if (neverFreeTableSize && length < NEVERFREETABLESIZE) {
-#ifndef WORD64
 	if ((sizeof(TestType1) !=
 	     (sizeof(TestType2) - sizeof(unsigned long) + sizeof(double))) &&
 	    !(length & (DALIGN-1)) &&
@@ -165,7 +162,6 @@ char *Xpermalloc(unsigned int length)
 	    neverFreeTableSize -= DALIGN - i;
 	    neverFreeTable += DALIGN - i;
 	} else
-#endif
 	    if ((i = (NEVERFREETABLESIZE - neverFreeTableSize) & (WALIGN-1))) {
 		neverFreeTableSize -= WALIGN - i;
 		neverFreeTable += WALIGN - i;
diff --git a/src/SendEvent.c b/src/SendEvent.c
index cc8bd5a..1de9860 100644
--- a/src/SendEvent.c
+++ b/src/SendEvent.c
@@ -67,12 +67,7 @@ XSendEvent(
 	req->destination = w;
 	req->propagate = propagate;
 	req->eventMask = event_mask;
-#ifdef WORD64
-	/* avoid quad-alignment problems */
-	memcpy ((char *) req->eventdata, (char *) &ev, SIZEOF(xEvent));
-#else
 	req->event = ev;
-#endif /* WORD64 */
     }
 
     UnlockDisplay(dpy);
diff --git a/src/XlibInt.c b/src/XlibInt.c
index c436842..1c964fd 100644
--- a/src/XlibInt.c
+++ b/src/XlibInt.c
@@ -293,124 +293,6 @@ void _XRead32(
 }
 #endif /* LONG64 */
 
-#ifdef WORD64
-
-/*
- * XXX This is a *really* stupid way of doing this....
- * PACKBUFFERSIZE must be a multiple of 4.
- */
-
-#define PACKBUFFERSIZE 4096
-
-
-/*
- * _XRead32 - Read bytes from the socket unpacking each 32 bits
- *            into a long (64 bits on a CRAY computer).
- *
- */
-static void _doXRead32(
-        register Display *dpy,
-        register long *data
-        register long size,
-	register char *packbuffer)
-{
- long *lpack,*lp;
- long mask32 = 0x00000000ffffffff;
- long maskw, nwords, i, bits;
-
-        _XReadPad (dpy, packbuffer, size);
-
-        lp = data;
-        lpack = (long *) packbuffer;
-        nwords = size >> 2;
-        bits = 32;
-
-        for(i=0;i<nwords;i++){
-            maskw = mask32 << bits;
-           *lp++ = ( *lpack & maskw ) >> bits;
-            bits = bits ^32;
-            if(bits){
-               lpack++;
-            }
-        }
-}
-
-void _XRead32(
-    Display *dpy,
-    long *data,
-    long len)
-{
-    char packbuffer[PACKBUFFERSIZE];
-    unsigned nunits = PACKBUFFERSIZE >> 2;
-
-    for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) {
-	_doXRead32 (dpy, data, PACKBUFFERSIZE, packbuffer);
-    }
-    if (len) _doXRead32 (dpy, data, len, packbuffer);
-}
-
-
-
-/*
- * _XRead16 - Read bytes from the socket unpacking each 16 bits
- *            into a long (64 bits on a CRAY computer).
- *
- */
-static _doXRead16(
-        register Display *dpy,
-        register short *data,
-        register long size,
-	char *packbuffer)
-{
-	long *lpack,*lp;
-	long mask16 = 0x000000000000ffff;
-	long maskw, nwords, i, bits;
-
-        (void) _XRead(dpy,packbuffer,size);	/* don't do a padded read... */
-
-        lp = (long *) data;
-        lpack = (long *) packbuffer;
-        nwords = size >> 1;  /* number of 16 bit words to be unpacked */
-        bits = 48;
-        for(i=0;i<nwords;i++){
-            maskw = mask16 << bits;
-           *lp++ = ( *lpack & maskw ) >> bits;
-            bits -= 16;
-            if(bits < 0){
-               lpack++;
-               bits = 48;
-            }
-        }
-}
-
-void _XRead16(
-    Display *dpy,
-    short *data,
-    long len)
-{
-    char packbuffer[PACKBUFFERSIZE];
-    unsigned nunits = PACKBUFFERSIZE >> 1;
-
-    for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) {
-	_doXRead16 (dpy, data, PACKBUFFERSIZE, packbuffer);
-    }
-    if (len) _doXRead16 (dpy, data, len, packbuffer);
-}
-
-void _XRead16Pad(
-    Display *dpy,
-    short *data,
-    long size)
-{
-    int slop = (size & 3);
-    short slopbuf[3];
-
-    _XRead16 (dpy, data, size);
-    if (slop > 0) {
-	_XRead16 (dpy, slopbuf, 4 - slop);
-    }
-}
-#endif /* WORD64 */
 
 /*
  * The hard part about this is that we only get 16 bits from a reply.
@@ -1764,122 +1646,6 @@ _XData32(
 }
 #endif /* LONG64 */
 
-#ifdef WORD64
-
-/*
- * XXX This is a *really* stupid way of doing this.  It should just use
- * dpy->bufptr directly, taking into account where in the word it is.
- */
-
-/*
- * Data16 - Place 16 bit data in the buffer.
- *
- * "dpy" is a pointer to a Display.
- * "data" is a pointer to the data.
- * "len" is the length in bytes of the data.
- */
-
-static doData16(
-    register Display *dpy,
-    _Xconst short *data,
-    unsigned len,
-    char *packbuffer)
-{
-    long *lp,*lpack;
-    long i, nwords,bits;
-    long mask16 = 0x000000000000ffff;
-
-        lp = (long *)data;
-        lpack = (long *)packbuffer;
-
-/*  nwords is the number of 16 bit values to be packed,
- *  the low order 16 bits of each word will be packed
- *  into 64 bit words
- */
-        nwords = len >> 1;
-        bits = 48;
-
-        for(i=0;i<nwords;i++){
-	   if (bits == 48) *lpack = 0;
-           *lpack ^= (*lp & mask16) << bits;
-           bits -= 16 ;
-           lp++;
-           if(bits < 0){
-               lpack++;
-               bits = 48;
-           }
-        }
-        Data(dpy, packbuffer, len);
-}
-
-_XData16 (
-    Display *dpy,
-    _Xconst short *data,
-    unsigned len)
-{
-    char packbuffer[PACKBUFFERSIZE];
-    unsigned nunits = PACKBUFFERSIZE >> 1;
-
-    for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) {
-	doData16 (dpy, data, PACKBUFFERSIZE, packbuffer);
-    }
-    if (len) doData16 (dpy, data, len, packbuffer);
-}
-
-/*
- * Data32 - Place 32 bit data in the buffer.
- *
- * "dpy" is a pointer to a Display.
- * "data" is a pointer to the data.
- * "len" is the length in bytes of the data.
- */
-
-static doData32(
-    register Display *dpy
-    _Xconst long *data,
-    unsigned len,
-    char *packbuffer)
-{
-    long *lp,*lpack;
-    long i,bits,nwords;
-    long mask32 = 0x00000000ffffffff;
-
-        lpack = (long *) packbuffer;
-        lp = data;
-
-/*  nwords is the number of 32 bit values to be packed
- *  the low order 32 bits of each word will be packed
- *  into 64 bit words
- */
-        nwords = len >> 2;
-        bits = 32;
-
-        for(i=0;i<nwords;i++){
-	   if (bits == 32) *lpack = 0;
-           *lpack ^= (*lp & mask32) << bits;
-           bits = bits ^32;
-           lp++;
-           if(bits)
-              lpack++;
-        }
-        Data(dpy, packbuffer, len);
-}
-
-void _XData32(
-    Display *dpy,
-    _Xconst long *data,
-    unsigned len)
-{
-    char packbuffer[PACKBUFFERSIZE];
-    unsigned nunits = PACKBUFFERSIZE >> 2;
-
-    for (; len > PACKBUFFERSIZE; len -= PACKBUFFERSIZE, data += nunits) {
-	doData32 (dpy, data, PACKBUFFERSIZE, packbuffer);
-    }
-    if (len) doData32 (dpy, data, len, packbuffer);
-}
-
-#endif /* WORD64 */
 
 
 /* Make sure this produces the same string as DefineLocal/DefineSelf in xdm.
@@ -1967,8 +1733,6 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len)
 {
     xReq *req;
 
-    WORD64ALIGN
-
     if (dpy->bufptr + len > dpy->bufmax)
 	_XFlush(dpy);
 
diff --git a/src/xkb/XKBNames.c b/src/xkb/XKBNames.c
index cf2382c..0276c05 100644
--- a/src/xkb/XKBNames.c
+++ b/src/xkb/XKBNames.c
@@ -494,38 +494,10 @@ XkbSetNames(	Display *	dpy,
     if (which&XkbGroupNamesMask)
 	_XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
     if (which&XkbKeyNamesMask) {
-#ifdef WORD64
-	char *tmp;
-	register int i;
-	BufAlloc(char *,tmp,nKeys*XkbKeyNameLength);
-	for (i=0;i<nKeys;i++,tmp+= XkbKeyNameLength) {
-	    tmp[0]= names->keys[firstKey+i].name[0];
-	    tmp[1]= names->keys[firstKey+i].name[1];
-	    tmp[2]= names->keys[firstKey+i].name[2];
-	    tmp[3]= names->keys[firstKey+i].name[3];
-	}
-#else
 	Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
-#endif
     }
     if (which&XkbKeyAliasesMask) {
-#ifdef WORD64
-	char *tmp;
-	register int i;
-	BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
-	for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
-	    tmp[0]= names->key_aliases[i].real[0];
-	    tmp[1]= names->key_aliases[i].real[1];
-	    tmp[2]= names->key_aliases[i].real[2];
-	    tmp[3]= names->key_aliases[i].real[3];
-	    tmp[4]= names->key_aliases[i].alias[0];
-	    tmp[5]= names->key_aliases[i].alias[1];
-	    tmp[6]= names->key_aliases[i].alias[2];
-	    tmp[7]= names->key_aliases[i].alias[3];
-	}
-#else
 	Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
-#endif
     }
     if (which&XkbRGNamesMask) {
 	Data32(dpy,(long *)names->radio_groups,nRG*4);
@@ -750,38 +722,10 @@ XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
     if (which&XkbGroupNamesMask)
 	_XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
     if (which&XkbKeyNamesMask) {
-#ifdef WORD64
-	char *tmp;
-	register int i;
-	BufAlloc(char *,tmp,nKeys*4);
-	for (i=0;i<nKeys;i++,tmp+= 4) {
-	    tmp[0]= names->keys[firstKey+i].name[0];
-	    tmp[1]= names->keys[firstKey+i].name[1];
-	    tmp[2]= names->keys[firstKey+i].name[2];
-	    tmp[3]= names->keys[firstKey+i].name[3];
-	}
-#else
 	Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
-#endif
     }
     if (which&XkbKeyAliasesMask) {
-#ifdef WORD64
-	char *tmp;
-	register int i;
-	BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
-	for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
-	    tmp[0]= names->key_aliases[i].real[0];
-	    tmp[1]= names->key_aliases[i].real[1];
-	    tmp[2]= names->key_aliases[i].real[2];
-	    tmp[3]= names->key_aliases[i].real[3];
-	    tmp[4]= names->key_aliases[i].alias[0];
-	    tmp[5]= names->key_aliases[i].alias[1];
-	    tmp[6]= names->key_aliases[i].alias[2];
-	    tmp[7]= names->key_aliases[i].alias[3];
-	}
-#else
 	Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
-#endif
     }
     if (which&XkbRGNamesMask) {
 	Data32(dpy,(long *)names->radio_groups,nRG*4);
diff --git a/src/xkb/XKBRdBuf.c b/src/xkb/XKBRdBuf.c
index 3023a32..bf2883a 100644
--- a/src/xkb/XKBRdBuf.c
+++ b/src/xkb/XKBRdBuf.c
@@ -116,30 +116,7 @@ _XkbReadCopyData32(int *wire,long *to,int num_words)
     }
     return 1;
 }
-#endif
-#ifdef WORD64
-int
-_XkbReadCopyData32(int *from,long *lp,int num_words)
-{
-long *lpack;
-long mask32 = 0x00000000ffffffff;
-long maskw, i, bits;
-
-    lpack = (long *)from;
-    bits = 32;
-
-    for (i=0;i<num_words;i++) {
-	maskw = mask32 << bits;
-	*lp++ = (*lpack & maskw) >> bits;
-	bits = bits ^ 32;
-	if (bits)
-	    lpack++;
-    }
-    return 1;
-}
-#endif
 
-#if defined(LONG64) || defined(WORD64)
 int
 _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
 {
@@ -149,9 +126,7 @@ _XkbReadBufferCopy32(XkbReadBufferPtr from,long *to,int num_words)
     from->data+= (4*num_words);
     return True;
 }
-#endif
 
-#ifdef LONG64
 int
 _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
 {
@@ -163,9 +138,6 @@ _XkbWriteCopyData32 (register unsigned long *from,CARD32 *to,int len)
 }
 #endif /* LONG64 */
 
-#ifdef WORD64
-_XkbWriteCopyData32 Not Implemented Yet for sizeof(int)==8
-#endif
 
 char *
 _XkbPeekAtReadBuffer(XkbReadBufferPtr from,int size)
diff --git a/src/xkb/XKBlibint.h b/src/xkb/XKBlibint.h
index ce14527..7b41c3b 100644
--- a/src/xkb/XKBlibint.h
+++ b/src/xkb/XKBlibint.h
@@ -213,7 +213,7 @@ extern int _XkbCopyFromReadBuffer(
 );
 
 
-#if defined(WORD64) || defined(LONG64)
+#ifdef LONG64
 extern	int _XkbReadCopyData32(
     int *		/* from */,
     long *		/* to */,
-- 
1.7.9.2



More information about the xorg-devel mailing list