[PATCH 07/19] Use C99 designated initializers in various extension Replies

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


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 composite/compext.c   |   63 ++++++++++++++++++++++++++-----------------------
 damageext/damageext.c |   10 ++++----
 dbe/dbe.c             |   51 ++++++++++++++++++++-------------------
 record/record.c       |   48 ++++++++++++++++++++-----------------
 render/render.c       |   10 ++++----
 xfixes/cursor.c       |   27 +++++++++++----------
 xfixes/xfixes.c       |   10 ++++----
 7 files changed, 119 insertions(+), 100 deletions(-)

diff --git a/composite/compext.c b/composite/compext.c
index be25b27..aa1265d 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -107,14 +107,15 @@ static int
 ProcCompositeQueryVersion(ClientPtr client)
 {
     CompositeClientPtr pCompositeClient = GetCompositeClient(client);
-    xCompositeQueryVersionReply rep;
+    xCompositeQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xCompositeQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xCompositeQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     if (stuff->majorVersion < SERVER_COMPOSITE_MAJOR_VERSION) {
         rep.majorVersion = stuff->majorVersion;
         rep.minorVersion = stuff->minorVersion;
@@ -275,7 +276,6 @@ static int
 ProcCompositeGetOverlayWindow(ClientPtr client)
 {
     REQUEST(xCompositeGetOverlayWindowReq);
-    xCompositeGetOverlayWindowReply rep;
     WindowPtr pWin;
     ScreenPtr pScreen;
     CompScreenPtr cs;
@@ -310,20 +310,23 @@ ProcCompositeGetOverlayWindow(ClientPtr client)
         FreeResource(pOc->resource, RT_NONE);
         return rc;
     }
+    else {
+        xCompositeGetOverlayWindowReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .overlayWin = cs->pOverlayWin->drawable.id
+        };
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.overlayWin);
+        }
+        WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.overlayWin = cs->pOverlayWin->drawable.id;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.overlayWin);
+        return Success;
     }
-    WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
-
-    return Success;
 }
 
 static int
@@ -768,7 +771,6 @@ static int
 PanoramiXCompositeGetOverlayWindow(ClientPtr client)
 {
     REQUEST(xCompositeGetOverlayWindowReq);
-    xCompositeGetOverlayWindowReply rep;
     WindowPtr pWin;
     ScreenPtr pScreen;
     CompScreenPtr cs;
@@ -842,18 +844,21 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
 
     cs = GetCompScreen(screenInfo.screens[0]);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.overlayWin = cs->pOverlayWin->drawable.id;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.overlayWin);
+    {
+        xCompositeGetOverlayWindowReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .overlayWin = cs->pOverlayWin->drawable.id
+        };
+
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.overlayWin);
+        }
+        WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
     }
-    WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
-
     return Success;
 }
 
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 70d2eee..2eddfb3 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -126,14 +126,16 @@ static int
 ProcDamageQueryVersion(ClientPtr client)
 {
     DamageClientPtr pDamageClient = GetDamageClient(client);
-    xDamageQueryVersionReply rep;
+    xDamageQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xDamageQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xDamageQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+
     if (stuff->majorVersion < SERVER_DAMAGE_MAJOR_VERSION) {
         rep.majorVersion = stuff->majorVersion;
         rep.minorVersion = stuff->minorVersion;
diff --git a/dbe/dbe.c b/dbe/dbe.c
index d8010ff..c8b401b 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -118,16 +118,16 @@ static int
 ProcDbeGetVersion(ClientPtr client)
 {
     /* REQUEST(xDbeGetVersionReq); */
-    xDbeGetVersionReply rep;
+    xDbeGetVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = DBE_MAJOR_VERSION,
+        .minorVersion = DBE_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xDbeGetVersionReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = DBE_MAJOR_VERSION;
-    rep.minorVersion = DBE_MINOR_VERSION;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
@@ -602,7 +602,6 @@ ProcDbeGetVisualInfo(ClientPtr client)
 {
     REQUEST(xDbeGetVisualInfoReq);
     DbeScreenPrivPtr pDbeScreenPriv;
-    xDbeGetVisualInfoReply rep;
     Drawable *drawables;
     DrawablePtr *pDrawables = NULL;
     register int i, j, rc;
@@ -667,19 +666,23 @@ ProcDbeGetVisualInfo(ClientPtr client)
         length += pScrVisInfo[i].count * sizeof(xDbeVisInfo);
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(length);
-    rep.m = count;
+    {
+        xDbeGetVisualInfoReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(length),
+            .m = count
+        };
 
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.m);
-    }
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.m);
+        }
 
-    /* Send off reply. */
-    WriteToClient(client, sizeof(xDbeGetVisualInfoReply), &rep);
+        /* Send off reply. */
+        WriteToClient(client, sizeof(xDbeGetVisualInfoReply), &rep);
+    }
 
     for (i = 0; i < count; i++) {
         CARD32 data32;
@@ -755,7 +758,11 @@ static int
 ProcDbeGetBackBufferAttributes(ClientPtr client)
 {
     REQUEST(xDbeGetBackBufferAttributesReq);
-    xDbeGetBackBufferAttributesReply rep;
+    xDbeGetBackBufferAttributesReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DbeWindowPrivPtr pDbeWindowPriv;
     int rc;
 
@@ -771,10 +778,6 @@ ProcDbeGetBackBufferAttributes(ClientPtr client)
         rep.attributes = None;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/record/record.c b/record/record.c
index a3ee4dd..5a62f0b 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1816,14 +1816,15 @@ static int
 ProcRecordQueryVersion(ClientPtr client)
 {
     /* REQUEST(xRecordQueryVersionReq); */
-    xRecordQueryVersionReply rep;
+    xRecordQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_RECORD_MAJOR_VERSION,
+        .minorVersion = SERVER_RECORD_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xRecordQueryVersionReq);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.majorVersion = SERVER_RECORD_MAJOR_VERSION;
-    rep.minorVersion = SERVER_RECORD_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.majorVersion);
@@ -2128,13 +2129,13 @@ ProcRecordGetContext(ClientPtr client)
     RecordContextPtr pContext;
 
     REQUEST(xRecordGetContextReq);
-    xRecordGetContextReply rep;
     RecordClientsAndProtocolPtr pRCAP;
     int nRCAPs = 0;
     GetContextRangeInfoPtr pRangeInfo;
     GetContextRangeInfoPtr pri;
     int i;
     int err;
+    CARD32 nClients, length;
 
     REQUEST_SIZE_MATCH(xRecordGetContextReq);
     VERIFY_CONTEXT(pContext, stuff->context, client);
@@ -2218,28 +2219,33 @@ ProcRecordGetContext(ClientPtr client)
 
     /* calculate number of clients and reply length */
 
-    rep.nClients = 0;
-    rep.length = 0;
+    nClients = 0;
+    length = 0;
     for (pRCAP = pContext->pListOfRCAP, pri = pRangeInfo;
          pRCAP; pRCAP = pRCAP->pNextRCAP, pri++) {
-        rep.nClients += pRCAP->numClients;
-        rep.length += pRCAP->numClients *
+        nClients += pRCAP->numClients;
+        length += pRCAP->numClients *
             (bytes_to_int32(sizeof(xRecordClientInfo)) +
              pri->nRanges * bytes_to_int32(sizeof(xRecordRange)));
     }
 
     /* write the reply header */
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.enabled = pContext->pRecordingClient != NULL;
-    rep.elementHeader = pContext->elemHeaders;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.nClients);
+    {
+        xRecordGetContextReply rep = {
+            .type = X_Reply,
+            .enabled = pContext->pRecordingClient != NULL,
+            .sequenceNumber = client->sequence,
+            .length = length,
+            .elementHeader = pContext->elemHeaders,
+            .nClients = nClients
+        };
+        if (client->swapped) {
+            swaps(&rep.sequenceNumber);
+            swapl(&rep.length);
+            swapl(&rep.nClients);
+        }
+        WriteToClient(client, sizeof(xRecordGetContextReply), &rep);
     }
-    WriteToClient(client, sizeof(xRecordGetContextReply), &rep);
 
     /* write all the CLIENT_INFOs */
 
diff --git a/render/render.c b/render/render.c
index 3bf0702..5301811 100644
--- a/render/render.c
+++ b/render/render.c
@@ -267,7 +267,11 @@ static int
 ProcRenderQueryVersion(ClientPtr client)
 {
     RenderClientPtr pRenderClient = GetRenderClient(client);
-    xRenderQueryVersionReply rep;
+    xRenderQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xRenderQueryVersionReq);
 
@@ -275,10 +279,6 @@ ProcRenderQueryVersion(ClientPtr client)
     pRenderClient->minor_version = stuff->minorVersion;
 
     REQUEST_SIZE_MATCH(xRenderQueryVersionReq);
-    memset(&rep, 0, sizeof(xRenderQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if ((stuff->majorVersion * 1000 + stuff->minorVersion) <
         (SERVER_RENDER_MAJOR_VERSION * 1000 + SERVER_RENDER_MINOR_VERSION)) {
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 402456d..2fa2595 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -460,7 +460,6 @@ int
 ProcXFixesGetCursorName(ClientPtr client)
 {
     CursorPtr pCursor;
-    xXFixesGetCursorNameReply reply;
 
     REQUEST(xXFixesGetCursorNameReq);
     const char *str;
@@ -474,18 +473,22 @@ ProcXFixesGetCursorName(ClientPtr client)
         str = "";
     len = strlen(str);
 
-    reply.type = X_Reply;
-    reply.length = bytes_to_int32(len);
-    reply.sequenceNumber = client->sequence;
-    reply.atom = pCursor->name;
-    reply.nbytes = len;
-    if (client->swapped) {
-        swaps(&reply.sequenceNumber);
-        swapl(&reply.length);
-        swapl(&reply.atom);
-        swaps(&reply.nbytes);
+    {
+        xXFixesGetCursorNameReply reply = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(len),
+            .atom = pCursor->name,
+            .nbytes = len
+        };
+        if (client->swapped) {
+            swaps(&reply.sequenceNumber);
+            swapl(&reply.length);
+            swapl(&reply.atom);
+            swaps(&reply.nbytes);
+        }
+        WriteReplyToClient(client, sizeof(xXFixesGetCursorNameReply), &reply);
     }
-    WriteReplyToClient(client, sizeof(xXFixesGetCursorNameReply), &reply);
     WriteToClient(client, len, str);
 
     return Success;
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 54f84f4..c6dd19e 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -61,15 +61,15 @@ static int
 ProcXFixesQueryVersion(ClientPtr client)
 {
     XFixesClientPtr pXFixesClient = GetXFixesClient(client);
-    xXFixesQueryVersionReply rep;
+    xXFixesQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xXFixesQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
-    memset(&rep, 0, sizeof(xXFixesQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if (version_compare(stuff->majorVersion, stuff->minorVersion,
                         SERVER_XFIXES_MAJOR_VERSION,
-- 
1.7.9.2



More information about the xorg-devel mailing list