[PATCH 10/19] Use C99 designated initializers in randr Replies

Alan Coopersmith alan.coopersmith at oracle.com
Sun Jun 24 10:25:17 PDT 2012


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 randr/rrcrtc.c     |  141 ++++++++++++++++-------------
 randr/rrdispatch.c |    9 +-
 randr/rrmode.c     |   31 +++----
 randr/rroutput.c   |   86 +++++++++---------
 randr/rrproperty.c |   66 ++++++++------
 randr/rrscreen.c   |  254 ++++++++++++++++++++++++++++------------------------
 randr/rrxinerama.c |  167 ++++++++++++++++++----------------
 7 files changed, 409 insertions(+), 345 deletions(-)

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index b31f389..76b5921 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -705,7 +705,12 @@ int
 ProcRRGetCrtcInfo(ClientPtr client)
 {
     REQUEST(xRRGetCrtcInfoReq);
-    xRRGetCrtcInfoReply rep;
+    xRRGetCrtcInfoReply rep = {
+        .type = X_Reply,
+        .status = RRSetConfigSuccess,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     RRCrtcPtr crtc;
     CARD8 *extra;
     unsigned long extraLen;
@@ -729,10 +734,6 @@ ProcRRGetCrtcInfo(ClientPtr client)
 
     mode = crtc->mode;
 
-    rep.type = X_Reply;
-    rep.status = RRSetConfigSuccess;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
     rep.timestamp = pScrPriv->lastSetTime.milliseconds;
     if (pScrPriv->rrGetPanning &&
         pScrPriv->rrGetPanning(pScreen, crtc, &panned_area, NULL, NULL) &&
@@ -817,7 +818,7 @@ int
 ProcRRSetCrtcConfig(ClientPtr client)
 {
     REQUEST(xRRSetCrtcConfigReq);
-    xRRSetCrtcConfigReply rep;
+    CARD8 status;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
     RRCrtcPtr crtc;
@@ -908,7 +909,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -982,28 +983,30 @@ 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.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.newTimestamp);
+    {
+        xRRSetCrtcConfigReply rep = {
+            .type = X_Reply,
+            .status = status,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .newTimestamp = pScrPriv->lastSetTime.milliseconds
+        };
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.newTimestamp);
+        }
+        WriteToClient(client, sizeof(xRRSetCrtcConfigReply), &rep);
     }
-    WriteToClient(client, sizeof(xRRSetCrtcConfigReply), &rep);
-
     return Success;
 }
 
@@ -1011,7 +1014,12 @@ int
 ProcRRGetPanning(ClientPtr client)
 {
     REQUEST(xRRGetPanningReq);
-    xRRGetPanningReply rep;
+    xRRGetPanningReply rep = {
+        .type = X_Reply,
+        .status = RRSetConfigSuccess,
+        .sequenceNumber = client->sequence,
+        .length = 1
+    };
     RRCrtcPtr crtc;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
@@ -1031,11 +1039,6 @@ ProcRRGetPanning(ClientPtr client)
     if (!pScrPriv)
         return RRErrorBase + BadRRCrtc;
 
-    memset(&rep, 0, sizeof(rep));
-    rep.type = X_Reply;
-    rep.status = RRSetConfigSuccess;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 1;
     rep.timestamp = pScrPriv->lastSetTime.milliseconds;
 
     if (pScrPriv->rrGetPanning &&
@@ -1079,7 +1082,7 @@ int
 ProcRRSetPanning(ClientPtr client)
 {
     REQUEST(xRRSetPanningReq);
-    xRRSetPanningReply rep;
+    CARD8 status;
     RRCrtcPtr crtc;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
@@ -1099,7 +1102,7 @@ ProcRRSetPanning(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -1126,28 +1129,32 @@ ProcRRSetPanning(ClientPtr client)
 
     pScrPriv->lastSetTime = time;
 
-    rep.status = RRSetConfigSuccess;
+    status = RRSetConfigSuccess;
 
  sendReply:
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.newTimestamp);
+    {
+        xRRSetPanningReply rep = {
+            .type = X_Reply,
+            .status = status,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .newTimestamp = pScrPriv->lastSetTime.milliseconds
+        };
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.newTimestamp);
+        }
+        WriteToClient(client, sizeof(xRRSetPanningReply), &rep);
+        return Success;
     }
-    WriteToClient(client, sizeof(xRRSetPanningReply), &rep);
-    return Success;
 }
 
 int
 ProcRRGetCrtcGammaSize(ClientPtr client)
 {
     REQUEST(xRRGetCrtcGammaSizeReq);
-    xRRGetCrtcGammaSizeReply reply;
     RRCrtcPtr crtc;
 
     REQUEST_SIZE_MATCH(xRRGetCrtcGammaSizeReq);
@@ -1156,25 +1163,27 @@ ProcRRGetCrtcGammaSize(ClientPtr client)
     /* Gamma retrieval failed, any better error? */
     if (!RRCrtcGammaGet(crtc))
         return RRErrorBase + BadRRCrtc;
-
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = 0;
-    reply.size = crtc->gammaSize;
-    if (client->swapped) {
-        swaps(&reply.sequenceNumber);
-        swapl(&reply.length);
-        swaps(&reply.size);
+    else {
+        xRRGetCrtcGammaSizeReply reply = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .size = crtc->gammaSize
+        };
+        if (client->swapped) {
+            swaps(&reply.sequenceNumber);
+            swapl(&reply.length);
+            swaps(&reply.size);
+        }
+        WriteToClient(client, sizeof(xRRGetCrtcGammaSizeReply), &reply);
+        return Success;
     }
-    WriteToClient(client, sizeof(xRRGetCrtcGammaSizeReply), &reply);
-    return Success;
 }
 
 int
 ProcRRGetCrtcGamma(ClientPtr client)
 {
     REQUEST(xRRGetCrtcGammaReq);
-    xRRGetCrtcGammaReply reply;
     RRCrtcPtr crtc;
     unsigned long len;
     char *extra = NULL;
@@ -1194,16 +1203,20 @@ ProcRRGetCrtcGamma(ClientPtr client)
             return BadAlloc;
     }
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = bytes_to_int32(len);
-    reply.size = crtc->gammaSize;
-    if (client->swapped) {
-        swaps(&reply.sequenceNumber);
-        swapl(&reply.length);
-        swaps(&reply.size);
+    {
+        xRRGetCrtcGammaReply reply = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(len),
+            .size = crtc->gammaSize
+        };
+        if (client->swapped) {
+            swaps(&reply.sequenceNumber);
+            swapl(&reply.length);
+            swaps(&reply.size);
+        }
+        WriteToClient(client, sizeof(xRRGetCrtcGammaReply), &reply);
     }
-    WriteToClient(client, sizeof(xRRGetCrtcGammaReply), &reply);
     if (crtc->gammaSize) {
         memcpy(extra, crtc->gammaRed, len);
         client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write;
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index d4b9feb..fc9bcf3 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -35,16 +35,17 @@ RRClientKnowsRates(ClientPtr pClient)
 static int
 ProcRRQueryVersion(ClientPtr client)
 {
-    xRRQueryVersionReply rep = { 0 };
+    xRRQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     REQUEST(xRRQueryVersionReq);
     rrClientPriv(client);
 
     REQUEST_SIZE_MATCH(xRRQueryVersionReq);
     pRRClient->major_version = stuff->majorVersion;
     pRRClient->minor_version = stuff->minorVersion;
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if (version_compare(stuff->majorVersion, stuff->minorVersion,
                         SERVER_RANDR_MAJOR_VERSION,
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 3b3738a..50f0ea9 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -282,7 +282,6 @@ int
 ProcRRCreateMode(ClientPtr client)
 {
     REQUEST(xRRCreateModeReq);
-    xRRCreateModeReply rep = { 0 };
     WindowPtr pWin;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
@@ -311,21 +310,23 @@ ProcRRCreateMode(ClientPtr client)
     mode = RRModeCreateUser(pScreen, modeInfo, name, &error);
     if (!mode)
         return error;
-
-    rep.type = X_Reply;
-    rep.pad0 = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.mode = mode->mode.id;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.mode);
+    else {
+	xRRCreateModeReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .mode = mode->mode.id
+	};
+	if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.mode);
+        }
+        WriteToClient(client, sizeof(xRRCreateModeReply), &rep);
+        /* Drop out reference to this mode */
+        RRModeDestroy(mode);
+        return Success;
     }
-    WriteToClient(client, sizeof(xRRCreateModeReply), &rep);
-    /* Drop out reference to this mode */
-    RRModeDestroy(mode);
-    return Success;
 }
 
 int
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 31636c4..b7c364a 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -407,7 +407,6 @@ int
 ProcRRGetOutputInfo(ClientPtr client)
 {
     REQUEST(xRRGetOutputInfoReq);
-    xRRGetOutputInfoReply rep;
     RROutputPtr output;
     CARD8 *extra;
     unsigned long extraLen;
@@ -425,27 +424,11 @@ ProcRRGetOutputInfo(ClientPtr client)
     pScreen = output->pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(OutputInfoExtra);
-    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-    rep.crtc = output->crtc ? output->crtc->id : None;
-    rep.mmWidth = output->mmWidth;
-    rep.mmHeight = output->mmHeight;
-    rep.connection = output->connection;
-    rep.subpixelOrder = output->subpixelOrder;
-    rep.nCrtcs = output->numCrtcs;
-    rep.nModes = output->numModes + output->numUserModes;
-    rep.nPreferred = output->numPreferred;
-    rep.nClones = output->numClones;
-    rep.nameLength = output->nameLength;
-
     extraLen = ((output->numCrtcs +
                  output->numModes + output->numUserModes +
-                 output->numClones + bytes_to_int32(rep.nameLength)) << 2);
+                 output->numClones + bytes_to_int32(output->nameLength)) << 2);
 
     if (extraLen) {
-        rep.length += bytes_to_int32(extraLen);
         extra = malloc(extraLen);
         if (!extra)
             return BadAlloc;
@@ -477,19 +460,39 @@ ProcRRGetOutputInfo(ClientPtr client)
             swapl(&clones[i]);
     }
     memcpy(name, output->name, output->nameLength);
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.timestamp);
-        swapl(&rep.crtc);
-        swapl(&rep.mmWidth);
-        swapl(&rep.mmHeight);
-        swaps(&rep.nCrtcs);
-        swaps(&rep.nModes);
-        swaps(&rep.nClones);
-        swaps(&rep.nameLength);
+    {
+        xRRGetOutputInfoReply rep = {
+            .type = X_Reply,
+            /* .status = ? */
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(OutputInfoExtra) +
+                      bytes_to_int32(extraLen),
+            .timestamp = pScrPriv->lastSetTime.milliseconds,
+            .crtc = output->crtc ? output->crtc->id : None,
+            .mmWidth = output->mmWidth,
+            .mmHeight = output->mmHeight,
+            .connection = output->connection,
+            .subpixelOrder = output->subpixelOrder,
+            .nCrtcs = output->numCrtcs,
+            .nModes = output->numModes + output->numUserModes,
+            .nPreferred = output->numPreferred,
+            .nClones = output->numClones,
+            .nameLength = output->nameLength
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.timestamp);
+            swapl(&rep.crtc);
+            swapl(&rep.mmWidth);
+            swapl(&rep.mmHeight);
+            swaps(&rep.nCrtcs);
+            swaps(&rep.nModes);
+            swaps(&rep.nClones);
+            swaps(&rep.nameLength);
+        }
+        WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep);
     }
-    WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep);
     if (extraLen) {
         WriteToClient(client, extraLen, extra);
         free(extra);
@@ -557,7 +560,6 @@ ProcRRGetOutputPrimary(ClientPtr client)
     REQUEST(xRRGetOutputPrimaryReq);
     WindowPtr pWin;
     rrScrPrivPtr pScrPriv;
-    xRRGetOutputPrimaryReply rep;
     RROutputPtr primary = NULL;
     int rc;
 
@@ -571,17 +573,19 @@ ProcRRGetOutputPrimary(ClientPtr client)
     if (pScrPriv)
         primary = pScrPriv->primaryOutput;
 
-    memset(&rep, 0, sizeof(rep));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.output = primary ? primary->id : None;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.output);
-    }
+    {
+        xRRGetOutputPrimaryReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .output = primary ? primary->id : None
+        };
 
-    WriteToClient(client, sizeof(xRRGetOutputPrimaryReply), &rep);
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.output);
+        }
 
+        WriteToClient(client, sizeof(xRRGetOutputPrimaryReply), &rep);
+    }
     return Success;
 }
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index e8f0578..df60fec 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -378,8 +378,7 @@ int
 ProcRRListOutputProperties(ClientPtr client)
 {
     REQUEST(xRRListOutputPropertiesReq);
-    Atom *pAtoms = NULL, *temppAtoms;
-    xRRListOutputPropertiesReply rep;
+    Atom *pAtoms = NULL;
     int numProps = 0;
     RROutputPtr output;
     RRPropertyPtr prop;
@@ -394,21 +393,26 @@ ProcRRListOutputProperties(ClientPtr client)
         if (!(pAtoms = (Atom *) malloc(numProps * sizeof(Atom))))
             return BadAlloc;
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(numProps * sizeof(Atom));
-    rep.sequenceNumber = client->sequence;
-    rep.nAtoms = numProps;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swaps(&rep.nAtoms);
+    {
+        xRRListOutputPropertiesReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(numProps * sizeof(Atom)),
+            .nAtoms = numProps
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swaps(&rep.nAtoms);
+        }
+        WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep);
     }
-    temppAtoms = pAtoms;
-    for (prop = output->properties; prop; prop = prop->next)
-        *temppAtoms++ = prop->propertyName;
 
-    WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep);
     if (numProps) {
+        Atom *temppAtoms = pAtoms;
+        for (prop = output->properties; prop; prop = prop->next)
+            *temppAtoms++ = prop->propertyName;
+
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
         WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
         free(pAtoms);
@@ -420,7 +424,6 @@ int
 ProcRRQueryOutputProperty(ClientPtr client)
 {
     REQUEST(xRRQueryOutputPropertyReq);
-    xRRQueryOutputPropertyReply rep;
     RROutputPtr output;
     RRPropertyPtr prop;
     char *extra = NULL;
@@ -438,17 +441,23 @@ ProcRRQueryOutputProperty(ClientPtr client)
         if (!extra)
             return BadAlloc;
     }
-    rep.type = X_Reply;
-    rep.length = prop->num_valid;
-    rep.sequenceNumber = client->sequence;
-    rep.pending = prop->is_pending;
-    rep.range = prop->range;
-    rep.immutable = prop->immutable;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
+
+    {
+        xRRQueryOutputPropertyReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = prop->num_valid,
+            .pending = prop->is_pending,
+            .range = prop->range,
+            .immutable = prop->immutable
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+        }
+        WriteToClient(client, sizeof(xRRQueryOutputPropertyReply), &rep);
     }
-    WriteToClient(client, sizeof(xRRQueryOutputPropertyReply), &rep);
+
     if (prop->num_valid) {
         memcpy(extra, prop->valid_values, prop->num_valid * sizeof(INT32));
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
@@ -568,7 +577,10 @@ ProcRRGetOutputProperty(ClientPtr client)
     RRPropertyValuePtr prop_value;
     unsigned long n, len, ind;
     RROutputPtr output;
-    xRRGetOutputPropertyReply reply;
+    xRRGetOutputPropertyReply reply = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
     char *extra = NULL;
 
     REQUEST_SIZE_MATCH(xRRGetOutputPropertyReq);
@@ -594,8 +606,6 @@ ProcRRGetOutputProperty(ClientPtr client)
         if (prop->propertyName == stuff->property)
             break;
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
     if (!prop) {
         reply.nItems = 0;
         reply.length = 0;
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 52a9079..2ebb62b 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -189,7 +189,11 @@ int
 ProcRRGetScreenSizeRange(ClientPtr client)
 {
     REQUEST(xRRGetScreenSizeRangeReq);
-    xRRGetScreenSizeRangeReply rep;
+    xRRGetScreenSizeRangeReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     WindowPtr pWin;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
@@ -203,11 +207,6 @@ ProcRRGetScreenSizeRange(ClientPtr client)
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
 
-    rep.type = X_Reply;
-    rep.pad = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-
     if (pScrPriv) {
         if (!RRGetInfo(pScreen, FALSE))
             return BadAlloc;
@@ -293,17 +292,10 @@ static int
 rrGetScreenResources(ClientPtr client, Bool query)
 {
     REQUEST(xRRGetScreenResourcesReq);
-    xRRGetScreenResourcesReply rep;
     WindowPtr pWin;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
-    CARD8 *extra;
-    unsigned long extraLen;
-    int i, rc, has_primary = 0;
-    RRCrtc *crtcs;
-    RROutput *outputs;
-    xRRModeInfo *modeinfos;
-    CARD8 *names;
+    int rc;
 
     REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
@@ -312,42 +304,57 @@ rrGetScreenResources(ClientPtr client, Bool query)
 
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
-    rep.pad = 0;
 
     if (query && pScrPriv)
         if (!RRGetInfo(pScreen, query))
             return BadAlloc;
 
     if (!pScrPriv) {
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.timestamp = currentTime.milliseconds;
-        rep.configTimestamp = currentTime.milliseconds;
-        rep.nCrtcs = 0;
-        rep.nOutputs = 0;
-        rep.nModes = 0;
-        rep.nbytesNames = 0;
-        extra = NULL;
-        extraLen = 0;
+        xRRGetScreenResourcesReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .timestamp = currentTime.milliseconds,
+            .configTimestamp = currentTime.milliseconds,
+            .nCrtcs = 0,
+            .nOutputs = 0,
+            .nModes = 0,
+            .nbytesNames = 0
+        };
+        if (client->swapped) {
+            /* only need to byte swap non-zero values */
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.timestamp);
+            swapl(&rep.configTimestamp);
+        }
+        WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep);
     }
     else {
         RRModePtr *modes;
         int num_modes;
+        CARD8 *extra;
+        unsigned long extraLen;
+        int i, has_primary = 0;
+        RRCrtc *crtcs;
+        RROutput *outputs;
+        xRRModeInfo *modeinfos;
+        CARD8 *names;
+        xRRGetScreenResourcesReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            /* .length filled in below */
+            .timestamp = pScrPriv->lastSetTime.milliseconds,
+            .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+            .nCrtcs = pScrPriv->numCrtcs,
+            .nOutputs = pScrPriv->numOutputs,
+            /* .nModes filled in below */
+            .nbytesNames = 0
+        };
 
         modes = RRModesForScreen(pScreen, &num_modes);
         if (!modes)
             return BadAlloc;
-
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-        rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-        rep.nCrtcs = pScrPriv->numCrtcs;
-        rep.nOutputs = pScrPriv->numOutputs;
         rep.nModes = num_modes;
-        rep.nbytesNames = 0;
 
         for (i = 0; i < num_modes; i++)
             rep.nbytesNames += modes[i]->mode.nameLength;
@@ -421,22 +428,22 @@ rrGetScreenResources(ClientPtr client, Bool query)
         }
         free(modes);
         assert(bytes_to_int32((char *) names - (char *) extra) == rep.length);
-    }
 
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.timestamp);
-        swapl(&rep.configTimestamp);
-        swaps(&rep.nCrtcs);
-        swaps(&rep.nOutputs);
-        swaps(&rep.nModes);
-        swaps(&rep.nbytesNames);
-    }
-    WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep);
-    if (extraLen) {
-        WriteToClient(client, extraLen, extra);
-        free(extra);
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.timestamp);
+            swapl(&rep.configTimestamp);
+            swaps(&rep.nCrtcs);
+            swaps(&rep.nOutputs);
+            swaps(&rep.nModes);
+            swaps(&rep.nbytesNames);
+        }
+        WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep);
+        if (extraLen) {
+            WriteToClient(client, extraLen, extra);
+            free(extra);
+        }
     }
     return Success;
 }
@@ -556,13 +563,10 @@ int
 ProcRRGetScreenInfo(ClientPtr client)
 {
     REQUEST(xRRGetScreenInfoReq);
-    xRRGetScreenInfoReply rep;
     WindowPtr pWin;
     int rc;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
-    CARD8 *extra;
-    unsigned long extraLen;
     RROutputPtr output;
 
     REQUEST_SIZE_MATCH(xRRGetScreenInfoReq);
@@ -572,7 +576,6 @@ ProcRRGetScreenInfo(ClientPtr client)
 
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
-    rep.pad = 0;
 
     if (pScrPriv)
         if (!RRGetInfo(pScreen, TRUE))
@@ -581,20 +584,28 @@ ProcRRGetScreenInfo(ClientPtr client)
     output = RRFirstOutput(pScreen);
 
     if (!pScrPriv || !output) {
-        rep.type = X_Reply;
-        rep.setOfRotations = RR_Rotate_0;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.root = pWin->drawable.pScreen->root->drawable.id;
-        rep.timestamp = currentTime.milliseconds;
-        rep.configTimestamp = currentTime.milliseconds;
-        rep.nSizes = 0;
-        rep.sizeID = 0;
-        rep.rotation = RR_Rotate_0;
-        rep.rate = 0;
-        rep.nrateEnts = 0;
-        extra = 0;
-        extraLen = 0;
+        xRRGetScreenInfoReply rep = {
+            .type = X_Reply,
+            .setOfRotations = RR_Rotate_0,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .root = pWin->drawable.pScreen->root->drawable.id,
+            .timestamp = currentTime.milliseconds,
+            .configTimestamp = currentTime.milliseconds,
+            .nSizes = 0,
+            .sizeID = 0,
+            .rotation = RR_Rotate_0,
+            .rate = 0,
+            .nrateEnts = 0
+        };
+        if (client->swapped) {
+            /* only need to byte swap non-zero values */
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.timestamp);
+            swapl(&rep.configTimestamp);
+            swaps(&rep.rotation);
+        }
+        WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep);
     }
     else {
         int i, j;
@@ -604,19 +615,23 @@ ProcRRGetScreenInfo(ClientPtr client)
         Bool has_rate = RRClientKnowsRates(client);
         RR10DataPtr pData;
         RRScreenSizePtr pSize;
+        CARD8 *extra;
+        unsigned long extraLen;
+        xRRGetScreenInfoReply rep = {
+            .type = X_Reply,
+            .setOfRotations = output->crtc->rotations,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .root = pWin->drawable.pScreen->root->drawable.id,
+            .timestamp = pScrPriv->lastSetTime.milliseconds,
+            .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+            .rotation = output->crtc->rotation
+        };
 
         pData = RR10GetData(pScreen, output);
         if (!pData)
             return BadAlloc;
 
-        rep.type = X_Reply;
-        rep.setOfRotations = output->crtc->rotations;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.root = pWin->drawable.pScreen->root->drawable.id;
-        rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-        rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-        rep.rotation = output->crtc->rotation;
         rep.nSizes = pData->nsize;
         rep.nrateEnts = pData->nrefresh + pData->nsize;
         rep.sizeID = pData->size;
@@ -677,21 +692,23 @@ ProcRRGetScreenInfo(ClientPtr client)
             FatalError("RRGetScreenInfo bad extra len %ld != %ld\n",
                        (unsigned long) (data8 - (CARD8 *) extra), extraLen);
         rep.length = bytes_to_int32(extraLen);
-    }
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.timestamp);
-        swaps(&rep.rotation);
-        swaps(&rep.nSizes);
-        swaps(&rep.sizeID);
-        swaps(&rep.rate);
-        swaps(&rep.nrateEnts);
-    }
-    WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep);
-    if (extraLen) {
-        WriteToClient(client, extraLen, extra);
-        free(extra);
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.timestamp);
+            swapl(&rep.configTimestamp);
+            swaps(&rep.rotation);
+            swaps(&rep.nSizes);
+            swaps(&rep.sizeID);
+            swaps(&rep.rate);
+            swaps(&rep.nrateEnts);
+        }
+        WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep);
+        if (extraLen) {
+            WriteToClient(client, extraLen, extra);
+            free(extra);
+        }
     }
     return Success;
 }
@@ -700,7 +717,7 @@ int
 ProcRRSetScreenConfig(ClientPtr client)
 {
     REQUEST(xRRSetScreenConfigReq);
-    xRRSetScreenConfigReply rep;
+    CARD8 status;
     DrawablePtr pDraw;
     int rc;
     ScreenPtr pScreen;
@@ -740,7 +757,7 @@ ProcRRSetScreenConfig(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
     if (!RRGetInfo(pScreen, FALSE))
@@ -749,7 +766,7 @@ ProcRRSetScreenConfig(ClientPtr client)
     output = RRFirstOutput(pScreen);
     if (!output) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -765,7 +782,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;
     }
 
@@ -844,7 +861,7 @@ ProcRRSetScreenConfig(ClientPtr client)
      * the last set-time
      */
     if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) {
-        rep.status = RRSetConfigInvalidTime;
+        status = RRSetConfigInvalidTime;
         goto sendReply;
     }
 
@@ -876,24 +893,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;
     }
 
     /*
@@ -904,23 +921,28 @@ ProcRRSetScreenConfig(ClientPtr client)
 
     free(pData);
 
-    rep.type = X_Reply;
-    /* rep.status has already been filled in */
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
-    rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds;
-    rep.root = pDraw->pScreen->root->drawable.id;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.newTimestamp);
-        swapl(&rep.newConfigTimestamp);
-        swapl(&rep.root);
+    {
+        xRRSetScreenConfigReply rep = {
+            .type = X_Reply,
+            .status = status,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+
+            .newTimestamp = pScrPriv->lastSetTime.milliseconds,
+            .newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds,
+            .root = pDraw->pScreen->root->drawable.id,
+            /* .subpixelOrder = ?? */
+        };
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.newTimestamp);
+            swapl(&rep.newConfigTimestamp);
+            swapl(&rep.root);
+        }
+        WriteToClient(client, sizeof(xRRSetScreenConfigReply), &rep);
     }
-    WriteToClient(client, sizeof(xRRSetScreenConfigReply), &rep);
 
     return Success;
 }
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index 269a63f..9a7e367 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -89,14 +89,15 @@ static int SProcRRXineramaDispatch(ClientPtr client);
 int
 ProcRRXineramaQueryVersion(ClientPtr client)
 {
-    xPanoramiXQueryVersionReply rep;
+    xPanoramiXQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_RRXINERAMA_MAJOR_VERSION,
+        .minorVersion = SERVER_RRXINERAMA_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_RRXINERAMA_MAJOR_VERSION;
-    rep.minorVersion = SERVER_RRXINERAMA_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -112,7 +113,6 @@ ProcRRXineramaGetState(ClientPtr client)
 {
     REQUEST(xPanoramiXGetStateReq);
     WindowPtr pWin;
-    xPanoramiXGetStateReply rep;
     register int rc;
     ScreenPtr pScreen;
     rrScrPrivPtr pScrPriv;
@@ -130,17 +130,21 @@ ProcRRXineramaGetState(ClientPtr client)
         active = TRUE;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.state = active;
-    rep.window = stuff->window;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.window);
+    {
+        xPanoramiXGetStateReply rep = {
+            .type = X_Reply,
+            .state = active,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .window = stuff->window
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.window);
+        }
+        WriteToClient(client, sizeof(xPanoramiXGetStateReply), &rep);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetStateReply), &rep);
     return Success;
 }
 
@@ -176,83 +180,87 @@ ProcRRXineramaGetScreenCount(ClientPtr client)
 {
     REQUEST(xPanoramiXGetScreenCountReq);
     WindowPtr pWin;
-    xPanoramiXGetScreenCountReply rep;
     register int rc;
 
     REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
-
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.ScreenCount = RRXineramaScreenCount(pWin->drawable.pScreen);
-    rep.window = stuff->window;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.window);
+    else {
+        xPanoramiXGetScreenCountReply rep = {
+            .type = X_Reply,
+            .ScreenCount = RRXineramaScreenCount(pWin->drawable.pScreen),
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .window = stuff->window
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.window);
+        }
+        WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), &rep);
+        return Success;
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), &rep);
-    return Success;
 }
 
 int
 ProcRRXineramaGetScreenSize(ClientPtr client)
 {
     REQUEST(xPanoramiXGetScreenSizeReq);
-    WindowPtr pWin, pRoot;
-    ScreenPtr pScreen;
-    xPanoramiXGetScreenSizeReply rep;
+    WindowPtr pWin;
     register int rc;
 
     REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
-
-    pScreen = pWin->drawable.pScreen;
-    pRoot = pScreen->root;
-
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.width = pRoot->drawable.width;
-    rep.height = pRoot->drawable.height;
-    rep.window = stuff->window;
-    rep.screen = stuff->screen;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.width);
-        swapl(&rep.height);
-        swapl(&rep.window);
-        swapl(&rep.screen);
+    else {
+        ScreenPtr pScreen = pWin->drawable.pScreen;
+        WindowPtr pRoot = pScreen->root;
+        xPanoramiXGetScreenSizeReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .width = pRoot->drawable.width,
+            .height = pRoot->drawable.height,
+            .window = stuff->window,
+            .screen = stuff->screen
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.width);
+            swapl(&rep.height);
+            swapl(&rep.window);
+            swapl(&rep.screen);
+        }
+        WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), &rep);
+        return Success;
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), &rep);
-    return Success;
 }
 
 int
 ProcRRXineramaIsActive(ClientPtr client)
 {
-    xXineramaIsActiveReply rep;
-
     REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
-    memset(&rep, 0, sizeof(xXineramaIsActiveReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.state = RRXineramaScreenActive(screenInfo.screens[RR_XINERAMA_SCREEN]);
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.state);
+    {
+        xXineramaIsActiveReply rep = {
+            .type = X_Reply,
+            .length = 0,
+            .sequenceNumber = client->sequence,
+            .state =
+                RRXineramaScreenActive(screenInfo.screens[RR_XINERAMA_SCREEN])
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.state);
+        }
+        WriteToClient(client, sizeof(xXineramaIsActiveReply), &rep);
+        return Success;
     }
-    WriteToClient(client, sizeof(xXineramaIsActiveReply), &rep);
-    return Success;
 }
 
 static void
@@ -297,7 +305,7 @@ RRXineramaWriteCrtc(ClientPtr client, RRCrtcPtr crtc)
 int
 ProcRRXineramaQueryScreens(ClientPtr client)
 {
-    xXineramaQueryScreensReply rep;
+    int n;
     ScreenPtr pScreen = screenInfo.screens[RR_XINERAMA_SCREEN];
 
     REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
@@ -305,18 +313,23 @@ ProcRRXineramaQueryScreens(ClientPtr client)
     if (RRXineramaScreenActive(pScreen))
         RRGetInfo(pScreen, FALSE);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.number = RRXineramaScreenCount(pScreen);
-    rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.number);
+    n = RRXineramaScreenCount(pScreen);
+    {
+        xXineramaQueryScreensReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(n * sz_XineramaScreenInfo),
+            .number = n
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.number);
+        }
+        WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep);
     }
-    WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep);
 
-    if (rep.number) {
+    if (n) {
         rrScrPriv(pScreen);
         int i;
         int has_primary = 0;
-- 
1.7.9.2



More information about the xorg-devel mailing list