Skip to content

Commit

Permalink
Use temporary variables instead of parts of reply structures
Browse files Browse the repository at this point in the history
When passing variable pointers to functions or otherwise doing long
sequences to compute values for replies, create & use some new
temporary variables, to allow for simpler initialization of reply
structures in the following patches.

Move memsets & other initializations to group with the rest of the
filling in of the reply structure, now that they're not needed so
early in the code path.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Daniel Stone <daniel@fooishbar.org>
  • Loading branch information
alanc committed Jul 10, 2012
1 parent c2fb1a7 commit 5b86c07
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 48 deletions.
6 changes: 4 additions & 2 deletions Xext/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ ProcShmGetImage(ClientPtr client)
Mask plane = 0;
xShmGetImageReply xgi;
ShmDescPtr shmdesc;
VisualID visual = None;
int rc;

REQUEST(xShmGetImageReq);
Expand Down Expand Up @@ -646,18 +647,19 @@ ProcShmGetImage(ClientPtr client)
stuff->y + (int) stuff->height >
wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height)
return BadMatch;
xgi.visual = wVisual(((WindowPtr) pDraw));
visual = wVisual(((WindowPtr) pDraw));
}
else {
if (stuff->x < 0 ||
stuff->x + (int) stuff->width > pDraw->width ||
stuff->y < 0 || stuff->y + (int) stuff->height > pDraw->height)
return BadMatch;
xgi.visual = None;
visual = None;
}
xgi.type = X_Reply;
xgi.length = 0;
xgi.sequenceNumber = client->sequence;
xgi.visual = visual;
xgi.depth = pDraw->depth;
if (stuff->format == ZPixmap) {
length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
Expand Down
18 changes: 12 additions & 6 deletions dix/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2801,17 +2801,21 @@ ProcLookupColor(ClientPtr client)
rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP,
client, DixReadAccess);
if (rc == Success) {
xLookupColorReply lcr;
CARD16 exactRed, exactGreen, exactBlue;

if (OsLookupColor
(pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
&lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) {
&exactRed, &exactGreen, &exactBlue)) {
xLookupColorReply lcr;
lcr.type = X_Reply;
lcr.length = 0;
lcr.sequenceNumber = client->sequence;
lcr.screenRed = lcr.exactRed;
lcr.screenGreen = lcr.exactGreen;
lcr.screenBlue = lcr.exactBlue;
lcr.exactRed = exactRed;
lcr.exactGreen = exactGreen;
lcr.exactBlue = exactBlue;
lcr.screenRed = exactRed;
lcr.screenGreen = exactGreen;
lcr.screenBlue = exactBlue;
(*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
&lcr.screenGreen,
&lcr.screenBlue, pcmp->pVisual);
Expand Down Expand Up @@ -3109,6 +3113,7 @@ ProcListHosts(ClientPtr client)
{
xListHostsReply reply;
int len, nHosts, result;
BOOL enabled;
pointer pdata;

/* REQUEST(xListHostsReq); */
Expand All @@ -3120,10 +3125,11 @@ ProcListHosts(ClientPtr client)
if (result != Success)
return result;

result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
result = GetHosts(&pdata, &nHosts, &len, &enabled);
if (result != Success)
return result;
reply.type = X_Reply;
reply.enabled = enabled;
reply.sequenceNumber = client->sequence;
reply.nHosts = nHosts;
reply.length = bytes_to_int32(len);
Expand Down
15 changes: 10 additions & 5 deletions dix/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -4797,6 +4797,7 @@ ProcGrabPointer(ClientPtr client)
GrabMask mask;
WindowPtr confineTo;
CursorPtr oldCursor;
BYTE status;

REQUEST(xGrabPointerReq);
int rc;
Expand All @@ -4818,7 +4819,6 @@ ProcGrabPointer(ClientPtr client)
return rc;
}

memset(&rep, 0, sizeof(xGrabPointerReply));
oldCursor = NullCursor;
grab = device->deviceGrab.grab;

Expand All @@ -4833,14 +4833,16 @@ ProcGrabPointer(ClientPtr client)

rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
stuff->grabWindow, stuff->ownerEvents, stuff->time,
&mask, CORE, stuff->cursor, stuff->confineTo, &rep.status);
&mask, CORE, stuff->cursor, stuff->confineTo, &status);
if (rc != Success)
return rc;

if (oldCursor && rep.status == GrabSuccess)
if (oldCursor && status == GrabSuccess)
FreeCursor(oldCursor, (Cursor) 0);

memset(&rep, 0, sizeof(xGrabPointerReply));
rep.type = X_Reply;
rep.status = status;
rep.sequenceNumber = client->sequence;
rep.length = 0;
WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
Expand Down Expand Up @@ -5059,6 +5061,7 @@ int
ProcGrabKeyboard(ClientPtr client)
{
xGrabKeyboardReply rep;
BYTE status;

REQUEST(xGrabKeyboardReq);
int result;
Expand All @@ -5067,17 +5070,19 @@ ProcGrabKeyboard(ClientPtr client)

REQUEST_SIZE_MATCH(xGrabKeyboardReq);

memset(&rep, 0, sizeof(xGrabKeyboardReply));
mask.core = KeyPressMask | KeyReleaseMask;

result = GrabDevice(client, keyboard, stuff->pointerMode,
stuff->keyboardMode, stuff->grabWindow,
stuff->ownerEvents, stuff->time, &mask, CORE, None,
None, &rep.status);
None, &status);

if (result != Success)
return result;

memset(&rep, 0, sizeof(xGrabKeyboardReply));
rep.type = X_Reply;
rep.status = status;
rep.sequenceNumber = client->sequence;
rep.length = 0;
WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep);
Expand Down
14 changes: 8 additions & 6 deletions hw/kdrive/ephyr/ephyrdriext.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
xXF86DRIOpenConnectionReply rep;
drm_handle_t hSAREA;
char *busIdString = NULL;
CARD32 busIdStringLength = 0;

REQUEST(xXF86DRIOpenConnectionReq);
REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq);
Expand All @@ -600,15 +601,16 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
return BadValue;
}

if (busIdString)
busIdStringLength = strlen(busIdString);

rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.busIdStringLength = 0;
if (busIdString)
rep.busIdStringLength = strlen(busIdString);
rep.busIdStringLength = busIdStringLength;
rep.length =
bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
SIZEOF(xGenericReply) +
pad_to_int32(rep.busIdStringLength));
pad_to_int32(busIdStringLength));

rep.hSAREALow = (CARD32) (hSAREA & 0xffffffff);
#if defined(LONG64) && !defined(__linux__)
Expand All @@ -618,8 +620,8 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
#endif

WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
if (rep.busIdStringLength)
WriteToClient(client, rep.busIdStringLength, busIdString);
if (busIdStringLength)
WriteToClient(client, busIdStringLength, busIdString);
free(busIdString);
EPHYR_LOG("leave\n");
return Success;
Expand Down
4 changes: 3 additions & 1 deletion hw/kdrive/ephyr/ephyrglxext.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) a_pc;
xGLXMakeCurrentReply reply;
DrawablePtr drawable = NULL;
GLXContextTag contextTag = 0;
int rc = 0;

EPHYR_LOG("enter\n");
Expand All @@ -525,13 +526,14 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
if (!ephyrHostGLXMakeCurrent(hostx_get_window(drawable->pScreen->myNum),
req->context,
req->oldContextTag,
(int *) &reply.contextTag)) {
(int *) &contextTag)) {
EPHYR_LOG_ERROR("ephyrHostGLXMakeCurrent() failed\n");
goto out;
}
reply.length = 0;
reply.type = X_Reply;
reply.sequenceNumber = a_cl->client->sequence;
reply.contextTag = contextTag;
if (a_do_swap) {
__GLX_DECLARE_SWAP_VARIABLES;
__GLX_SWAP_SHORT(&reply.sequenceNumber);
Expand Down
12 changes: 7 additions & 5 deletions hw/xfree86/dri/xf86dri.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
xXF86DRIOpenConnectionReply rep;
drm_handle_t hSAREA;
char *busIdString;
CARD32 busIdStringLength = 0;

REQUEST(xXF86DRIOpenConnectionReq);
REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq);
Expand All @@ -154,11 +155,12 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
return BadValue;
}

if (busIdString)
busIdStringLength = strlen(busIdString);

rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.busIdStringLength = 0;
if (busIdString)
rep.busIdStringLength = strlen(busIdString);
rep.busIdStringLength = busIdStringLength;
rep.length =
bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
SIZEOF(xGenericReply) +
Expand All @@ -172,8 +174,8 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
#endif

WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
if (rep.busIdStringLength)
WriteToClient(client, rep.busIdStringLength, busIdString);
if (busIdStringLength)
WriteToClient(client, busIdStringLength, busIdString);
return Success;
}

Expand Down
15 changes: 9 additions & 6 deletions randr/rrcrtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
TimeStamp time;
Rotation rotation;
int ret, i, j;
CARD8 status;

REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
numOutputs = (stuff->length - bytes_to_int32(SIZEOF(xRRSetCrtcConfigReq)));
Expand Down Expand Up @@ -1077,7 +1078,7 @@ ProcRRSetCrtcConfig(ClientPtr client)

if (!pScrPriv) {
time = currentTime;
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
goto sendReply;
}

Expand Down Expand Up @@ -1161,17 +1162,17 @@ ProcRRSetCrtcConfig(ClientPtr client)

if (!RRCrtcSet(crtc, mode, stuff->x, stuff->y,
rotation, numOutputs, outputs)) {
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
goto sendReply;
}
rep.status = RRSetConfigSuccess;
status = RRSetConfigSuccess;
pScrPriv->lastSetTime = time;

sendReply:
free(outputs);

rep.type = X_Reply;
/* rep.status has already been filled in */
rep.status = status;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
Expand Down Expand Up @@ -1266,6 +1267,7 @@ ProcRRSetPanning(ClientPtr client)
BoxRec total;
BoxRec tracking;
INT16 border[4];
CARD8 status;

REQUEST_SIZE_MATCH(xRRSetPanningReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
Expand All @@ -1278,7 +1280,7 @@ ProcRRSetPanning(ClientPtr client)

if (!pScrPriv) {
time = currentTime;
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
goto sendReply;
}

Expand All @@ -1305,10 +1307,11 @@ ProcRRSetPanning(ClientPtr client)

pScrPriv->lastSetTime = time;

rep.status = RRSetConfigSuccess;
status = RRSetConfigSuccess;

sendReply:
rep.type = X_Reply;
rep.status = status;
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
Expand Down
19 changes: 10 additions & 9 deletions randr/rrscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ ProcRRSetScreenConfig(ClientPtr client)
Rotation rotation;
int rate;
Bool has_rate;
CARD8 status;
RROutputPtr output;
RRCrtcPtr crtc;
RRModePtr mode;
Expand Down Expand Up @@ -912,7 +913,7 @@ ProcRRSetScreenConfig(ClientPtr client)

if (!pScrPriv) {
time = currentTime;
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
goto sendReply;
}
if (!RRGetInfo(pScreen, FALSE))
Expand All @@ -921,7 +922,7 @@ ProcRRSetScreenConfig(ClientPtr client)
output = RRFirstOutput(pScreen);
if (!output) {
time = currentTime;
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
goto sendReply;
}

Expand All @@ -937,7 +938,7 @@ ProcRRSetScreenConfig(ClientPtr client)
* stop working after several hours have passed (freedesktop bug #6502).
*/
if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) {
rep.status = RRSetConfigInvalidConfigTime;
status = RRSetConfigInvalidConfigTime;
goto sendReply;
}

Expand Down Expand Up @@ -1016,7 +1017,7 @@ ProcRRSetScreenConfig(ClientPtr client)
* the last set-time
*/
if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) {
rep.status = RRSetConfigInvalidTime;
status = RRSetConfigInvalidTime;
goto sendReply;
}

Expand Down Expand Up @@ -1048,24 +1049,24 @@ ProcRRSetScreenConfig(ClientPtr client)
for (c = 0; c < pScrPriv->numCrtcs; c++) {
if (!RRCrtcSet(pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0,
0, NULL)) {
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
/* XXX recover from failure */
goto sendReply;
}
}
if (!RRScreenSizeSet(pScreen, width, height,
pScreen->mmWidth, pScreen->mmHeight)) {
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
/* XXX recover from failure */
goto sendReply;
}
}

if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output))
rep.status = RRSetConfigFailed;
status = RRSetConfigFailed;
else {
pScrPriv->lastSetTime = time;
rep.status = RRSetConfigSuccess;
status = RRSetConfigSuccess;
}

/*
Expand All @@ -1077,7 +1078,7 @@ ProcRRSetScreenConfig(ClientPtr client)
free(pData);

rep.type = X_Reply;
/* rep.status has already been filled in */
rep.status = status;
rep.length = 0;
rep.sequenceNumber = client->sequence;

Expand Down
Loading

0 comments on commit 5b86c07

Please sign in to comment.