[PATCH 03/18] dix: switch to byte-counting functions.
Peter Hutterer
peter.hutterer at who-t.net
Wed Jul 8 17:05:01 PDT 2009
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
dix/devices.c | 9 ++++---
dix/dispatch.c | 56 ++++++++++++++++++++++++++--------------------------
dix/dixfonts.c | 12 +++++-----
dix/eventconvert.c | 10 ++++----
dix/events.c | 4 +-
dix/extension.c | 2 +-
dix/property.c | 6 ++--
dix/swaprep.c | 4 +-
dix/window.c | 4 +-
9 files changed, 54 insertions(+), 53 deletions(-)
diff --git a/dix/devices.c b/dix/devices.c
index 8fac981..c1310ba 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1532,7 +1532,7 @@ ProcSetModifierMapping(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
if (client->req_len != ((stuff->numKeyPerModifier << 1) +
- (sizeof (xSetModifierMappingReq) >> 2)))
+ num_dwords_for_bytes(sizeof(xSetModifierMappingReq))))
return BadLength;
rep.type = X_Reply;
@@ -1591,7 +1591,7 @@ ProcChangeKeyboardMapping(ClientPtr client)
int rc;
REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
- len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xChangeKeyboardMappingReq));
if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode))
return BadLength;
@@ -1650,7 +1650,8 @@ ProcSetPointerMapping(ClientPtr client)
REQUEST(xSetPointerMappingReq);
REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
- if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2)
+ if (client->req_len !=
+ num_dwords_for_bytes(sizeof(xSetPointerMappingReq) + stuff->nElts))
return BadLength;
rep.type = X_Reply;
rep.length = 0;
@@ -2229,7 +2230,7 @@ ProcGetMotionEvents(ClientPtr client)
nEvents++;
}
}
- rep.length = nEvents * (sizeof(xTimecoord) >> 2);
+ rep.length = nEvents * num_dwords_for_bytes(sizeof(xTimecoord));
rep.nEvents = nEvents;
WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep);
if (nEvents)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 86db92f..e2ece16 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -513,7 +513,7 @@ CreateConnectionBlock(void)
QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
lenofblock = sizeof(xConnSetup) +
- ((setup.nbytesVendor + 3) & ~3) +
+ pad_to_dwords(setup.nbytesVendor) +
(setup.numFormats * sizeof(xPixmapFormat)) +
(setup.numRoots * sizeof(xWindowRoot));
ConnectionInfo = xalloc(lenofblock);
@@ -638,7 +638,7 @@ ProcCreateWindow(ClientPtr client)
rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xCreateWindowReq));
if (Ones(stuff->mask) != len)
return BadLength;
if (!stuff->width || !stuff->height)
@@ -681,7 +681,7 @@ ProcChangeWindowAttributes(ClientPtr client)
rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xChangeWindowAttributesReq));
if (len != Ones(stuff->valueMask))
return BadLength;
result = ChangeWindowAttributes(pWin,
@@ -885,7 +885,7 @@ ProcConfigureWindow(ClientPtr client)
DixManageAccess|DixSetAttrAccess);
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xConfigureWindowReq));
if (Ones((Mask)stuff->mask) != len)
return BadLength;
result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1],
@@ -1013,7 +1013,7 @@ ProcQueryTree(ClientPtr client)
}
reply.nChildren = numChildren;
- reply.length = (numChildren * sizeof(Window)) >> 2;
+ reply.length = num_dwords_for_bytes(numChildren * sizeof(Window));
WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply);
if (numChildren)
@@ -1070,7 +1070,7 @@ ProcGetAtomName(ClientPtr client)
len = strlen(str);
memset(&reply, 0, sizeof(xGetAtomNameReply));
reply.type = X_Reply;
- reply.length = (len + 3) >> 2;
+ reply.length = num_dwords_for_bytes(len);
reply.sequenceNumber = client->sequence;
reply.nameLength = len;
WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
@@ -1310,7 +1310,7 @@ ProcQueryFont(ClientPtr client)
}
reply->type = X_Reply;
- reply->length = (rlength - sizeof(xGenericReply)) >> 2;
+ reply->length = num_dwords_for_bytes(rlength - sizeof(xGenericReply));
reply->sequenceNumber = client->sequence;
QueryFont( pFont, reply, nprotoxcistructs);
@@ -1344,7 +1344,7 @@ ProcQueryTextExtents(ClientPtr client)
if (rc != Success)
return (rc == BadValue) ? BadFont: rc;
- length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
+ length = client->req_len - num_dwords_for_bytes(sizeof(xQueryTextExtentsReq));
length = length << 1;
if (stuff->oddLength)
{
@@ -1512,7 +1512,7 @@ ProcCreateGC(ClientPtr client)
if (rc != Success)
return rc;
- len = client->req_len - (sizeof(xCreateGCReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xCreateGCReq));
if (len != Ones(stuff->mask))
return BadLength;
pGC = (GC *)CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error,
@@ -1537,7 +1537,7 @@ ProcChangeGC(ClientPtr client)
if (result != Success)
return result;
- len = client->req_len - (sizeof(xChangeGCReq) >> 2);
+ len = client->req_len - num_dwords_for_bytes(sizeof(xChangeGCReq));
if (len != Ones(stuff->mask))
return BadLength;
@@ -1787,7 +1787,7 @@ ProcPolyPoint(ClientPtr client)
return BadValue;
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
+ npoint = num_dwords_for_bytes((client->req_len << 2) - sizeof(xPolyPointReq));
if (npoint)
(*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
(xPoint *) &stuff[1]);
@@ -1810,7 +1810,7 @@ ProcPolyLine(ClientPtr client)
return BadValue;
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
+ npoint = num_dwords_for_bytes((client->req_len << 2) - sizeof(xPolyLineReq));
if (npoint > 1)
(*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint,
(DDXPointPtr) &stuff[1]);
@@ -1898,7 +1898,7 @@ ProcFillPoly(ClientPtr client)
}
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
- things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
+ things = num_dwords_for_bytes((client->req_len << 2) - sizeof(xFillPolyReq));
if (things)
(*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
stuff->coordMode, things,
@@ -2042,8 +2042,8 @@ ProcPutImage(ClientPtr client)
tmpImage = (char *)&stuff[1];
lengthProto = length;
- if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) +
- (sizeof(xPutImageReq) >> 2)) != client->req_len)
+ if ((num_dwords_for_bytes(lengthProto * stuff->height) +
+ num_dwords_for_bytes(sizeof(xPutImageReq))) != client->req_len)
return BadLength;
ReformatImage (tmpImage, lengthProto * stuff->height,
@@ -2143,7 +2143,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
*(xGetImageReply *)pBuf = xgi;
pBuf += sz_xGetImageReply;
} else {
- xgi.length = (xgi.length + 3) >> 2;
+ xgi.length = num_dwords_for_bytes(xgi.length);
if (widthBytesLine == 0 || height == 0)
linesPerBuf = 0;
else if (widthBytesLine >= IMAGE_BUFSIZE)
@@ -2705,7 +2705,7 @@ ProcAllocColorCells (ClientPtr client)
#endif
{
accr.type = X_Reply;
- accr.length = length >> 2;
+ accr.length = num_dwords_for_bytes(length);
accr.sequenceNumber = client->sequence;
accr.nPixels = npixels;
accr.nMasks = nmasks;
@@ -2769,7 +2769,7 @@ ProcAllocColorPlanes(ClientPtr client)
else
return rc;
}
- acpr.length = length >> 2;
+ acpr.length = num_dwords_for_bytes(length);
#ifdef PANORAMIX
if (noPanoramiXExtension || !pcmp->pScreen->myNum)
#endif
@@ -2804,7 +2804,7 @@ ProcFreeColors(ClientPtr client)
if(pcmp->flags & AllAllocated)
return(BadAccess);
- count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
+ count = num_dwords_for_bytes((client->req_len << 2) - sizeof(xFreeColorsReq));
rc = FreeColors(pcmp, client->index, count,
(Pixel *)&stuff[1], (Pixel)stuff->planeMask);
if (client->noClientException != Success)
@@ -2907,7 +2907,7 @@ ProcQueryColors(ClientPtr client)
xrgb *prgbs;
xQueryColorsReply qcr;
- count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
+ count = num_dwords_for_bytes((client->req_len << 2) - sizeof(xQueryColorsReq));
prgbs = xcalloc(1, count * sizeof(xrgb));
if(!prgbs && count)
return(BadAlloc);
@@ -2924,7 +2924,7 @@ ProcQueryColors(ClientPtr client)
}
memset(&qcr, 0, sizeof(xQueryColorsReply));
qcr.type = X_Reply;
- qcr.length = (count * sizeof(xrgb)) >> 2;
+ qcr.length = num_dwords_for_bytes(count * sizeof(xrgb));
qcr.sequenceNumber = client->sequence;
qcr.nColors = count;
WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
@@ -3294,7 +3294,7 @@ ProcListHosts(ClientPtr client)
reply.type = X_Reply;
reply.sequenceNumber = client->sequence;
reply.nHosts = nHosts;
- reply.length = len >> 2;
+ reply.length = num_dwords_for_bytes(len);
WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
if (nHosts)
{
@@ -3427,7 +3427,7 @@ ProcGetFontPath(ClientPtr client)
reply.type = X_Reply;
reply.sequenceNumber = client->sequence;
- reply.length = (stringLens + numpaths + 3) >> 2;
+ reply.length = num_dwords_for_bytes(stringLens + numpaths);
reply.nPaths = numpaths;
WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
@@ -3656,7 +3656,7 @@ ClientPtr NextAvailableClient(pointer ospriv)
return (ClientPtr)NULL;
}
data.reqType = 1;
- data.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
+ data.length = num_dwords_for_bytes(sz_xReq + sz_xConnClientPrefix);
if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
{
FreeClientResources(client);
@@ -3696,8 +3696,8 @@ ProcInitialConnection(ClientPtr client)
SwapConnClientPrefix(prefix);
}
stuff->reqType = 2;
- stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) +
- ((prefix->nbytesAuthString + (unsigned)3) >> 2);
+ stuff->length += num_dwords_for_bytes(prefix->nbytesAuthProto) +
+ num_dwords_for_bytes(prefix->nbytesAuthString);
if (client->swapped)
{
swaps(&stuff->length, whichbyte);
@@ -3721,7 +3721,7 @@ SendConnSetup(ClientPtr client, char *reason)
csp.success = xFalse;
csp.lengthReason = strlen(reason);
- csp.length = (csp.lengthReason + (unsigned)3) >> 2;
+ csp.length = num_dwords_for_bytes(csp.lengthReason);
csp.majorVersion = X_PROTOCOL;
csp.minorVersion = X_PROTOCOL_REVISION;
if (client->swapped)
@@ -3812,7 +3812,7 @@ ProcEstablishConnection(ClientPtr client)
prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq);
auth_proto = (char *)prefix + sz_xConnClientPrefix;
- auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3);
+ auth_string = auth_proto + pad_to_dwords(prefix->nbytesAuthProto);
if ((prefix->majorVersion != X_PROTOCOL) ||
(prefix->minorVersion != X_PROTOCOL_REVISION))
reason = "Protocol version mismatch";
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 8b6e7a3..6a54708 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -792,7 +792,7 @@ finish:
memset(&reply, 0, sizeof(xListFontsReply));
reply.type = X_Reply;
- reply.length = (stringLens + nnames + 3) >> 2;
+ reply.length = num_dwords_for_bytes(stringLens + nnames);
reply.nFonts = nnames;
reply.sequenceNumber = client->sequence;
@@ -817,7 +817,7 @@ finish:
}
}
nnames = reply.nFonts;
- reply.length = (stringLens + nnames + 3) >> 2;
+ reply.length = num_dwords_for_bytes(stringLens + nnames);
client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply);
(void) WriteToClient(client, stringLens + nnames, bufferStart);
@@ -1057,9 +1057,9 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
namelen = strlen(name);
}
reply->type = X_Reply;
- reply->length = (sizeof *reply - sizeof(xGenericReply) +
+ reply->length = num_dwords_for_bytes(sizeof *reply - sizeof(xGenericReply) +
pFontInfo->nprops * sizeof(xFontProp) +
- namelen + 3) >> 2;
+ namelen);
reply->sequenceNumber = client->sequence;
reply->nameLength = namelen;
reply->minBounds = pFontInfo->ink_minbounds;
@@ -1097,8 +1097,8 @@ finish:
bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply));
finalReply.type = X_Reply;
finalReply.sequenceNumber = client->sequence;
- finalReply.length = (sizeof(xListFontsWithInfoReply)
- - sizeof(xGenericReply)) >> 2;
+ finalReply.length = num_dwords_for_bytes(sizeof(xListFontsWithInfoReply)
+ - sizeof(xGenericReply));
WriteSwappedDataToClient(client, length, &finalReply);
bail:
if (c->slept)
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index ac2b0c3..caeaf9f 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -389,13 +389,13 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
/* FIXME: this should just send the buttons we have, not MAX_BUTTONs. Same
* with MAX_VALUATORS below */
/* btlen is in 4 byte units */
- btlen = (((MAX_BUTTONS + 7)/8) + 3)/4;
+ btlen = num_dwords_for_bytes(num_bytes_for_bits(MAX_BUTTONS));
len += btlen * 4; /* buttonmask len */
vallen = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0]));
len += vallen * 2 * sizeof(uint32_t); /* axisvalues */
- vallen = (((MAX_VALUATORS + 7)/8) + 3)/4;
+ vallen = num_dwords_for_bytes(num_bytes_for_bits(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */
*xi = xcalloc(1, len);
@@ -404,7 +404,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
xde->extension = IReqCode;
xde->evtype = GetXI2Type((InternalEvent*)ev);
xde->time = ev->time;
- xde->length = (len - sizeof(xEvent) + 3)/4;
+ xde->length = num_dwords_for_bytes(len - sizeof(xEvent));
xde->detail = ev->detail.button;
xde->root = ev->root;
xde->buttons_len = btlen;
@@ -457,7 +457,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0]));
len += nvals * (2 * sizeof(uint32_t)) * 2; /* 8 byte per valuator, once
raw, once processed */
- vallen = (((MAX_VALUATORS + 7)/8) + 3)/4;
+ vallen = num_dwords_for_bytes(num_bytes_for_bits(MAX_VALUATORS));
len += vallen * 4; /* valuators mask */
*xi = xcalloc(1, len);
@@ -466,7 +466,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
raw->extension = IReqCode;
raw->evtype = GetXI2Type((InternalEvent*)ev);
raw->time = ev->time;
- raw->length = (len - sizeof(xEvent) + 3)/4;
+ raw->length = num_dwords_for_bytes(len - sizeof(xEvent));
raw->eventtype = ev->subtype;
raw->detail = ev->detail.button;
raw->deviceid = ev->deviceid;
diff --git a/dix/events.c b/dix/events.c
index 81e5b6d..788d5a7 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4287,8 +4287,8 @@ DeviceEnterLeaveEvent(
(mode == XINotifyPassiveUngrab && type == XI_Enter))
return;
- btlen = (mouse->button) ? (mouse->button->numButtons + 7)/8 : 0;
- btlen = (btlen + 3)/4;
+ btlen = (mouse->button) ? num_bytes_for_bits(mouse->button->numButtons) : 0;
+ btlen = num_dwords_for_bytes(btlen);
len = sizeof(xXIEnterEvent) + btlen * 4;
event = xcalloc(1, len);
diff --git a/dix/extension.c b/dix/extension.c
index c768ccb..55fb365 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -324,7 +324,7 @@ ProcListExtensions(ClientPtr client)
for (j = extensions[i]->num_aliases; --j >= 0;)
total_length += strlen(extensions[i]->aliases[j]) + 1;
}
- reply.length = (total_length + 3) >> 2;
+ reply.length = num_dwords_for_bytes(total_length);
buffer = bufptr = xalloc(total_length);
if (!buffer)
return(BadAlloc);
diff --git a/dix/property.c b/dix/property.c
index d63b8f4..a8cb8b4 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -218,7 +218,7 @@ ProcChangeProperty(ClientPtr client)
return BadValue;
}
len = stuff->nUnits;
- if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2))
+ if (len > num_dwords_for_bytes(0xffffffff - sizeof(xChangePropertyReq)))
return BadLength;
sizeInBytes = format>>3;
totalSize = len * sizeInBytes;
@@ -532,7 +532,7 @@ ProcGetProperty(ClientPtr client)
reply.bytesAfter = n - (ind + len);
reply.format = pProp->format;
- reply.length = (len + 3) >> 2;
+ reply.length = num_dwords_for_bytes(len);
reply.nItems = len / (pProp->format / 8 );
reply.propertyType = pProp->type;
@@ -606,7 +606,7 @@ ProcListProperties(ClientPtr client)
xlpr.type = X_Reply;
xlpr.nProperties = numProps;
- xlpr.length = (numProps * sizeof(Atom)) >> 2;
+ xlpr.length = num_dwords_for_bytes(numProps * sizeof(Atom));
xlpr.sequenceNumber = client->sequence;
WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
if (numProps)
diff --git a/dix/swaprep.c b/dix/swaprep.c
index 8624216..5d2f672 100644
--- a/dix/swaprep.c
+++ b/dix/swaprep.c
@@ -731,7 +731,7 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf)
int len = host->length;
char n;
swaps (&host->length, n);
- bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2);
+ bufT += sizeof (xHostEntry) + pad_to_dwords(len);
}
(void)WriteToClient (pClient, size, buf);
}
@@ -1222,7 +1222,7 @@ SwapConnSetupInfo(
pInfoT += sizeof(xConnSetup);
/* Copy the vendor string */
- i = (pConnSetup->nbytesVendor + 3) & ~3;
+ i = pad_to_dwords(pConnSetup->nbytesVendor);
memcpy(pInfoT, pInfo, i);
pInfo += i;
pInfoT += i;
diff --git a/dix/window.c b/dix/window.c
index 99b594b..d84a8ff 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1457,8 +1457,8 @@ GetWindowAttributes(WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply
wa->backingStore = NotUseful;
else
wa->backingStore = pWin->backingStore;
- wa->length = (sizeof(xGetWindowAttributesReply) -
- sizeof(xGenericReply)) >> 2;
+ wa->length = num_dwords_for_bytes(sizeof(xGetWindowAttributesReply) -
+ sizeof(xGenericReply));
wa->sequenceNumber = client->sequence;
wa->backingBitPlanes = wBackingBitPlanes (pWin);
wa->backingPixel = wBackingPixel (pWin);
--
1.6.3.rc1.2.g0164.dirty
More information about the xorg-devel
mailing list