From 5b86c072d1d586ce040d8831a05cf97ff8b17821 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 9 Jul 2012 19:12:42 -0700 Subject: Use temporary variables instead of parts of reply structures 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 Reviewed-by: Keith Packard Tested-by: Daniel Stone --- randr/rrcrtc.c | 15 +++++++++------ randr/rrscreen.c | 19 ++++++++++--------- randr/rrxinerama.c | 11 +++++++---- 3 files changed, 26 insertions(+), 19 deletions(-) (limited to 'randr') diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c index 7616e7c6a..ee29f37a3 100644 --- a/randr/rrcrtc.c +++ b/randr/rrcrtc.c @@ -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))); @@ -1077,7 +1078,7 @@ ProcRRSetCrtcConfig(ClientPtr client) if (!pScrPriv) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } @@ -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; @@ -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); @@ -1278,7 +1280,7 @@ ProcRRSetPanning(ClientPtr client) if (!pScrPriv) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } @@ -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; diff --git a/randr/rrscreen.c b/randr/rrscreen.c index ec07bb167..236794aff 100644 --- a/randr/rrscreen.c +++ b/randr/rrscreen.c @@ -882,6 +882,7 @@ ProcRRSetScreenConfig(ClientPtr client) Rotation rotation; int rate; Bool has_rate; + CARD8 status; RROutputPtr output; RRCrtcPtr crtc; RRModePtr mode; @@ -912,7 +913,7 @@ ProcRRSetScreenConfig(ClientPtr client) if (!pScrPriv) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } if (!RRGetInfo(pScreen, FALSE)) @@ -921,7 +922,7 @@ ProcRRSetScreenConfig(ClientPtr client) output = RRFirstOutput(pScreen); if (!output) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } @@ -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; } @@ -1016,7 +1017,7 @@ ProcRRSetScreenConfig(ClientPtr client) * the last set-time */ if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) { - rep.status = RRSetConfigInvalidTime; + status = RRSetConfigInvalidTime; goto sendReply; } @@ -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; } /* @@ -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; diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c index 269a63f78..da3942f6a 100644 --- a/randr/rrxinerama.c +++ b/randr/rrxinerama.c @@ -299,16 +299,19 @@ ProcRRXineramaQueryScreens(ClientPtr client) { xXineramaQueryScreensReply rep; ScreenPtr pScreen = screenInfo.screens[RR_XINERAMA_SCREEN]; + int n = 0; REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); - if (RRXineramaScreenActive(pScreen)) + if (RRXineramaScreenActive(pScreen)) { RRGetInfo(pScreen, FALSE); + n = RRXineramaScreenCount(pScreen); + } rep.type = X_Reply; rep.sequenceNumber = client->sequence; - rep.number = RRXineramaScreenCount(pScreen); - rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo); + rep.number = n; + rep.length = bytes_to_int32(n * sz_XineramaScreenInfo); if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); @@ -316,7 +319,7 @@ ProcRRXineramaQueryScreens(ClientPtr client) } WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep); - if (rep.number) { + if (n) { rrScrPriv(pScreen); int i; int has_primary = 0; -- cgit v1.2.3