[PATCH:xfs 6/7] Convert Reply initialization to use C99 struct initializers

Alan Coopersmith alan.coopersmith at oracle.com
Sat Jan 19 23:03:54 PST 2013


Much like we did for the X server, lets the compiler handle filling
in the entire struct, including zeroing out padding bytes.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 difs/dispatch.c   |  120 +++++++++++++++++++++++++++++------------------------
 difs/events.c     |   26 ++++++------
 difs/extensions.c |   27 ++++++------
 difs/fontinfo.c   |   71 +++++++++++++++----------------
 difs/fonts.c      |   81 +++++++++++++++++-------------------
 5 files changed, 167 insertions(+), 158 deletions(-)

diff --git a/difs/dispatch.c b/difs/dispatch.c
index 8c549fa..f22ec36 100644
--- a/difs/dispatch.c
+++ b/difs/dispatch.c
@@ -225,7 +225,6 @@ int
 ProcEstablishConnection(ClientPtr client)
 {
     fsConnClientPrefix *prefix;
-    fsConnSetup csp;
     int         ret;
     pointer     auth_data;
     char       *ad;
@@ -334,21 +333,23 @@ ProcEstablishConnection(ClientPtr client)
 	SendErrToClient(client, FSBadAlloc, (pointer) 0);
 	return FSBadAlloc;
     }
-    csp.status = auth_accept;
-    if (client->major_version == 1)
-	/* we implement backwards compatibility for version 1.0 */
-	csp.major_version = client->major_version;
-    else
-	csp.major_version = FS_PROTOCOL;
-    csp.minor_version = FS_PROTOCOL_MINOR;
-    csp.num_alternates = num_alts;
-    csp.alternate_len = altlen;
-    csp.auth_len = auth_len >> 2;
-    csp.auth_index = auth_index;
-    if (client->swapped) {
-	WriteSConnSetup(client, &csp);
-    } else {
-	(void) WriteToClient(client, SIZEOF(fsConnSetup), (char *) &csp);
+    else {
+	fsConnSetup csp = {
+	    .status = auth_accept,
+	    /* we implement backwards compatibility for version 1.0 */
+	    .major_version = (client->major_version == 1) ?
+	        client->major_version : FS_PROTOCOL,
+	    .minor_version = FS_PROTOCOL_MINOR,
+	    .num_alternates = num_alts,
+	    .alternate_len = altlen,
+	    .auth_len = auth_len >> 2,
+	    .auth_index = auth_index
+	};
+	if (client->swapped) {
+	    WriteSConnSetup(client, &csp);
+	} else {
+	    (void) WriteToClient(client, SIZEOF(fsConnSetup), (char *) &csp);
+	}
     }
 
     /* send the alternates info */
@@ -393,7 +394,14 @@ DoSendErrToClient(
     int         error,
     pointer     data)		/* resource id, format, resolution, etc */
 {
-    fsError     rep;
+    fsError     rep = {
+	.type = FS_Error,
+	.request = error,
+	.sequenceNumber = client->sequence,
+	.timestamp = GetTimeInMillis(),
+	.major_opcode = ((fsReq *) client->requestBuffer)->reqType,
+	.minor_opcode = MinorOpcodeOfRequest(client)
+    };
     int         extralen = 0;
 
     switch (error) {
@@ -435,12 +443,6 @@ DoSendErrToClient(
 	break;
     }
 
-    rep.type = FS_Error;
-    rep.sequenceNumber = client->sequence;
-    rep.request = error;
-    rep.major_opcode = ((fsReq *) client->requestBuffer)->reqType;
-    rep.minor_opcode = MinorOpcodeOfRequest(client),
-	rep.timestamp = GetTimeInMillis();
     rep.length = (SIZEOF(fsError) + extralen) >> 2;
 
     WriteErrorToClient(client, &rep);
@@ -472,7 +474,11 @@ ProcListCatalogues(ClientPtr client)
     int         len,
                 num;
     char       *catalogues;
-    fsListCataloguesReply rep;
+    fsListCataloguesReply rep = {
+	.type = FS_Reply,
+	.sequenceNumber = client->sequence,
+	.num_replies = 0
+    };
 
     REQUEST(fsListCataloguesReq);
     REQUEST_AT_LEAST_SIZE(fsListCataloguesReq);
@@ -480,10 +486,7 @@ ProcListCatalogues(ClientPtr client)
     num = ListCatalogues((char *)stuff + SIZEOF(fsListCataloguesReq),
 			 stuff->nbytes, stuff->maxNames,
 			 &catalogues, &len);
-    rep.type = FS_Reply;
-    rep.num_replies = 0;
     rep.num_catalogues = num;
-    rep.sequenceNumber = client->sequence;
     rep.length = (SIZEOF(fsListCataloguesReply) + len + 3) >> 2;
 
     WriteReplyToClient(client, SIZEOF(fsListCataloguesReply), &rep);
@@ -534,7 +537,6 @@ ProcGetCatalogues(ClientPtr client)
                 i,
                 size;
     char       *cp;
-    fsGetCataloguesReply rep;
 
     REQUEST(fsGetCataloguesReq);
     REQUEST_AT_LEAST_SIZE(fsGetCataloguesReq);
@@ -546,12 +548,16 @@ ProcGetCatalogues(ClientPtr client)
 	cp += size;
     }
 
-    rep.type = FS_Reply;
-    rep.num_catalogues = client->num_catalogues;
-    rep.sequenceNumber = client->sequence;
-    rep.length = (SIZEOF(fsGetCataloguesReply) + len + 3) >> 2;
-
-    WriteReplyToClient(client, SIZEOF(fsGetCataloguesReply), &rep);
+    {
+        fsGetCataloguesReply rep = {
+	    .type = FS_Reply,
+	    .num_catalogues = client->num_catalogues,
+	    .sequenceNumber = client->sequence,
+	    .length = (SIZEOF(fsGetCataloguesReply) + len + 3) >> 2
+	};
+
+	WriteReplyToClient(client, SIZEOF(fsGetCataloguesReply), &rep);
+    }
     (void) WriteToClient(client, len, client->catalogues);
 
     return client->noClientException;
@@ -560,7 +566,6 @@ ProcGetCatalogues(ClientPtr client)
 int
 ProcCreateAC(ClientPtr client)
 {
-    fsCreateACReply rep;
     AuthPtr     acp;
     AuthContextPtr authp;
     int         accept,
@@ -661,13 +666,17 @@ alloc_failure:
 	return FSBadAlloc;
     }
     DEALLOCATE_LOCAL(acp);
-    rep.type = FS_Reply;
-    rep.status = accept;
-    rep.auth_index = index;
-    rep.sequenceNumber = client->sequence;
-    rep.length = (SIZEOF(fsCreateACReply) + size) >> 2;
-
-    WriteReplyToClient(client, SIZEOF(fsCreateACReply), &rep);
+    {
+        fsCreateACReply rep = {
+	    .type = FS_Reply,
+	    .auth_index = index,
+	    .sequenceNumber = client->sequence,
+	    .status = accept,
+	    .length = (SIZEOF(fsCreateACReply) + size) >> 2
+	};
+
+	WriteReplyToClient(client, SIZEOF(fsCreateACReply), &rep);
+    }
     if (size)
 	(void) WriteToClient(client, size, auth_data);
 
@@ -759,8 +768,6 @@ ProcSetResolution(ClientPtr client)
 int
 ProcGetResolution(ClientPtr client)
 {
-    fsGetResolutionReply reply;
-
     REQUEST(fsReq);
     REQUEST_AT_LEAST_SIZE(fsReq);
 
@@ -771,13 +778,17 @@ ProcGetResolution(ClientPtr client)
 	SendErrToClient(client, FSBadLength, &lengthword);
 	return FSBadLength;
     }
-    reply.type = FS_Reply;
-    reply.num_resolutions = client->num_resolutions;
-    reply.sequenceNumber = client->sequence;
-    reply.length = (SIZEOF(fsGetResolutionReply) +
-		    client->num_resolutions * SIZEOF(fsResolution)) >> 2;
-
-    WriteReplyToClient(client, SIZEOF(fsGetResolutionReply), &reply);
+    else {
+	fsGetResolutionReply reply = {
+	    .type = FS_Reply,
+	    .num_resolutions = client->num_resolutions,
+	    .sequenceNumber = client->sequence,
+	    .length = (SIZEOF(fsGetResolutionReply) +
+		       client->num_resolutions * SIZEOF(fsResolution)) >> 2
+	};
+
+	WriteReplyToClient(client, SIZEOF(fsGetResolutionReply), &reply);
+    }
     if (client->swapped)
 	client->pSwapReplyFunc = CopySwap16Write;
 
@@ -855,7 +866,10 @@ ProcQueryXInfo(ClientPtr client)
     ClientFontPtr cfp;
     int         err,
                 lendata;
-    fsQueryXInfoReply reply;
+    fsQueryXInfoReply reply = {
+	.type = FS_Reply,
+	.sequenceNumber = client->sequence
+    };
     fsPropInfo *prop_info;
 
     REQUEST(fsQueryXInfoReq);
@@ -868,8 +882,6 @@ ProcQueryXInfo(ClientPtr client)
 	SendErrToClient(client, FSBadFont, (pointer) &aligned_id);
 	return FSBadFont;
     }
-    reply.type = FS_Reply;
-    reply.sequenceNumber = client->sequence;
 
     /* get the header */
     fsPack_XFontInfoHeader(&cfp->font->info, &reply, client->major_version);
diff --git a/difs/events.c b/difs/events.c
index d702842..01923b4 100644
--- a/difs/events.c
+++ b/difs/events.c
@@ -93,16 +93,16 @@ ProcSetEventMask(ClientPtr client)
 int
 ProcGetEventMask(ClientPtr client)
 {
-    fsGetEventMaskReply rep;
+    fsGetEventMaskReply rep = {
+        .type = FS_Reply,
+        .sequenceNumber = client->sequence,
+        .length = SIZEOF(fsGetEventMaskReply) >> 2,
+        .event_mask = client->eventmask
+    };
 
     REQUEST(fsGetEventMaskReq);
     REQUEST_AT_LEAST_SIZE(fsGetEventMaskReq);
 
-    rep.type = FS_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = SIZEOF(fsGetEventMaskReply) >> 2;
-    rep.event_mask = client->eventmask;
-
     WriteReplyToClient(client, SIZEOF(fsGetEventMaskReply), &rep);
     return client->noClientException;
 }
@@ -110,13 +110,13 @@ ProcGetEventMask(ClientPtr client)
 void
 SendKeepAliveEvent(ClientPtr client)
 {
-    fsKeepAliveEvent ev;
-
-    ev.type = FS_Event;
-    ev.event_code = KeepAlive;
-    ev.sequenceNumber = client->sequence;
-    ev.length = SIZEOF(fsKeepAliveEvent) >> 2;
-    ev.timestamp = GetTimeInMillis();
+    fsKeepAliveEvent ev = {
+        .type = FS_Event,
+        .event_code = KeepAlive,
+        .sequenceNumber = client->sequence,
+        .length = SIZEOF(fsKeepAliveEvent) >> 2,
+        .timestamp = GetTimeInMillis()
+    };
 
 #ifdef DEBUG
     fprintf(stderr, "client #%d is getting a KeepAlive\n", client->index);
diff --git a/difs/extensions.c b/difs/extensions.c
index 86ce68e..eb31e76 100644
--- a/difs/extensions.c
+++ b/difs/extensions.c
@@ -201,7 +201,12 @@ InitExtensions(void)
 int
 ProcQueryExtension(ClientPtr client)
 {
-    fsQueryExtensionReply reply;
+    fsQueryExtensionReply reply = {
+        .type = FS_Reply,
+        .sequenceNumber = client->sequence,
+        .length = SIZEOF(fsQueryExtensionReply) >> 2,
+        .major_opcode = 0
+    };
     int         i,
                 j;
 
@@ -209,11 +214,6 @@ ProcQueryExtension(ClientPtr client)
 
     REQUEST_AT_LEAST_SIZE(fsQueryExtensionReq);
 
-    reply.type = FS_Reply;
-    reply.length = SIZEOF(fsQueryExtensionReply) >> 2;
-    reply.major_opcode = 0;
-    reply.sequenceNumber = client->sequence;
-
     if (!NumExtensions) {
 	reply.present = fsFalse;
     } else {
@@ -248,20 +248,19 @@ ProcQueryExtension(ClientPtr client)
 int
 ProcListExtensions(ClientPtr client)
 {
-    fsListExtensionsReply reply;
+    fsListExtensionsReply reply = {
+        .type = FS_Reply,
+        .nExtensions = NumExtensions,
+        .sequenceNumber = client->sequence,
+        .length = SIZEOF(fsListExtensionsReply) >> 2
+    };
     char       *bufptr,
-               *buffer;
+               *buffer = NULL;
     int         total_length = 0;
 
     REQUEST(fsListExtensionsReq);
     REQUEST_SIZE_MATCH(fsListExtensionsReq);
 
-    reply.type = FS_Reply;
-    reply.nExtensions = NumExtensions;
-    reply.length = SIZEOF(fsListExtensionsReply) >> 2;
-    reply.sequenceNumber = client->sequence;
-    buffer = NULL;
-
     if (NumExtensions) {
 	int         i,
 	            j;
diff --git a/difs/fontinfo.c b/difs/fontinfo.c
index c5269bc..e950ae8 100644
--- a/difs/fontinfo.c
+++ b/difs/fontinfo.c
@@ -264,10 +264,8 @@ static Bool
 do_query_extents(ClientPtr client, pointer data)
 {
     int         err;
-    unsigned long lendata,
-                num_extents;
+    unsigned long num_extents;
     fsXCharInfo *extents;
-    fsQueryXExtents8Reply reply;
 
     err = GetExtents (pPtr->client, pPtr->pfont,
 		     pPtr->flags, pPtr->nranges, pPtr->range, &num_extents, &extents);
@@ -281,19 +279,21 @@ do_query_extents(ClientPtr client, pointer data)
     }
     if (err != Successful) {
 	SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
-	goto finish;
     }
-    reply.type = FS_Reply;
-    reply.sequenceNumber = pPtr->client->sequence;
-    reply.num_extents = num_extents;
-    lendata = SIZEOF(fsXCharInfo) * num_extents;
-    reply.length = (SIZEOF(fsQueryXExtents8Reply) + lendata) >> 2;
-    if (client->swapped)
-	SwapExtents(extents, num_extents);
-    WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXExtents8Reply), &reply);
-    (void) WriteToClient(pPtr->client, lendata, (char *) extents);
-    fsfree((char *) extents);
-finish:
+    else {
+	unsigned long lendata = SIZEOF(fsXCharInfo) * num_extents;
+	fsQueryXExtents8Reply reply = {
+	    .type = FS_Reply,
+	    .sequenceNumber = pPtr->client->sequence,
+	    .num_extents = num_extents,
+	    .length = (SIZEOF(fsQueryXExtents8Reply) + lendata) >> 2
+	};
+	if (client->swapped)
+	    SwapExtents(extents, num_extents);
+	WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXExtents8Reply), &reply);
+	WriteToClient(pPtr->client, lendata, (char *) extents);
+	fsfree((char *) extents);
+    }
     if (pPtr->slept)
 	ClientWakeup(pPtr->client);
     if (pPtr->pfont->unload_glyphs)  /* For rasterizers that want to save memory */
@@ -352,7 +352,6 @@ do_query_bitmaps(ClientPtr client, pointer data)
     int data_size;
     fsOffset32   *offsets;
     pointer     glyph_data;
-    fsQueryXBitmaps8Reply reply;
     int		freedata;
 
     err = GetBitmaps (pPtr->client, pPtr->pfont, pPtr->format,
@@ -369,26 +368,28 @@ do_query_bitmaps(ClientPtr client, pointer data)
     }
     if (err != Successful) {
 	SendErrToClient(pPtr->client, FontToFSError(err), (pointer) 0);
-	goto finish;
     }
-    reply.type = FS_Reply;
-    reply.sequenceNumber = pPtr->client->sequence;
-    reply.replies_hint = 0;
-    reply.num_chars = num_glyphs;
-    reply.nbytes = data_size;
-    reply.length = (SIZEOF(fsQueryXBitmaps8Reply) + data_size +
-		    (SIZEOF(fsOffset32) * num_glyphs) + 3) >> 2;
-
-    WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXBitmaps8Reply), &reply);
-    if (client->swapped)
-	SwapLongs((long *)offsets, num_glyphs * 2);
-    (void) WriteToClient(pPtr->client, (num_glyphs * SIZEOF(fsOffset32)),
-			 (char *) offsets);
-    (void) WriteToClient(pPtr->client, data_size, (char *) glyph_data);
-    fsfree((char *) offsets);
-    if (freedata)
-	fsfree((char *) glyph_data);
-finish:
+    else {
+	fsQueryXBitmaps8Reply reply = {
+	    .type = FS_Reply,
+	    .sequenceNumber = pPtr->client->sequence,
+	    .length = (SIZEOF(fsQueryXBitmaps8Reply) + data_size +
+		       (SIZEOF(fsOffset32) * num_glyphs) + 3) >> 2,
+	    .replies_hint = 0,
+	    .num_chars = num_glyphs,
+	    .nbytes = data_size
+	};
+
+	WriteReplyToClient(pPtr->client, SIZEOF(fsQueryXBitmaps8Reply), &reply);
+	if (client->swapped)
+	    SwapLongs((long *)offsets, num_glyphs * 2);
+	WriteToClient(pPtr->client, (num_glyphs * SIZEOF(fsOffset32)),
+		      (char *) offsets);
+	WriteToClient(pPtr->client, data_size, (char *) glyph_data);
+	fsfree((char *) offsets);
+	if (freedata)
+	    fsfree((char *) glyph_data);
+    }
     if (pPtr->slept)
 	ClientWakeup(pPtr->client);
     if (pPtr->pfont->unload_glyphs)  /* For rasterizers that want to save memory */
diff --git a/difs/fonts.c b/difs/fonts.c
index 3f898e5..6d46589 100644
--- a/difs/fonts.c
+++ b/difs/fonts.c
@@ -276,7 +276,6 @@ do_open_font(ClientPtr client, pointer data)
                *newname;
     int         newlen;
     ClientFontPtr cfp;
-    fsOpenBitmapFontReply rep;
     Font        orig;
     FontIDListPtr *idlist,
                 ids;
@@ -385,25 +384,26 @@ do_open_font(ClientPtr client, pointer data)
 	err = AllocError;
 	goto dropout;
     }
-    add_id_to_list(ids, cPtr->fontid);
-    /* send the reply */
-    rep.type = FS_Reply;
-    rep.otherid = orig;
-    if (orig)
-	rep.otherid_valid = TRUE;
-    else
-	rep.otherid_valid = FALSE;
-    rep.cachable = pfont->info.cachable;
-    rep.sequenceNumber = client->sequence;
-    rep.length = SIZEOF(fsOpenBitmapFontReply) >> 2;
-    WriteReplyToClient(client,
-		       SIZEOF(fsOpenBitmapFontReply), &rep);
-    if (pfont->refcnt == 0) {
-	if (!pfont->fpe)
-	    pfont->fpe = fpe;
-	UseFPE(pfont->fpe);
+    else {
+        /* send the reply */
+	fsOpenBitmapFontReply rep = {
+	    .type = FS_Reply,
+	    .otherid_valid = orig ? TRUE : FALSE,
+	    .sequenceNumber = client->sequence,
+	    .length = SIZEOF(fsOpenBitmapFontReply) >> 2,
+	    .otherid = orig,
+	    .cachable = pfont->info.cachable
+	};
+	WriteReplyToClient(client,
+			   SIZEOF(fsOpenBitmapFontReply), &rep);
+	add_id_to_list(ids, cPtr->fontid);
+	if (pfont->refcnt == 0) {
+	    if (!pfont->fpe)
+		pfont->fpe = fpe;
+	    UseFPE(pfont->fpe);
+	}
+	pfont->refcnt++;
     }
-    pfont->refcnt++;
 dropout:
     if (err != Successful) {
 	SendErrToClient(cPtr->client, FontToFSError(err), (pointer) &(cPtr->fontid));
@@ -429,7 +429,6 @@ OpenFont(
     char       *name)
 {
     FontPtr     pfont = (FontPtr)0;
-    fsOpenBitmapFontReply rep;
     OFclosurePtr c;
     FontIDListPtr *idlist,
                 ids;
@@ -487,24 +486,20 @@ OpenFont(
 	if (!add_id_to_list(ids, fid)) {
 	    goto lowmem;
 	}
-	pfont->refcnt++;
-	rep.type = FS_Reply;
-	if (ids->num > 1)
-	{
-	    rep.otherid = ids->client_list[0];
-	    rep.otherid_valid = TRUE;
-	}
-	else
-	{
-	    rep.otherid = 0;
-	    rep.otherid_valid = FALSE;
+	else {
+	    fsOpenBitmapFontReply rep = {
+		.type = FS_Reply,
+		.otherid_valid = (ids->num > 1) ? TRUE : FALSE,
+		.sequenceNumber = client->sequence,
+		.length = SIZEOF(fsOpenBitmapFontReply) >> 2,
+		.otherid = (ids->num > 1) ? ids->client_list[0] : 0,
+		.cachable = TRUE	/* XXX */
+	    };
+	    WriteReplyToClient(client,
+			       SIZEOF(fsOpenBitmapFontReply), &rep);
+	    pfont->refcnt++;
+	    return FSSuccess;
 	}
-	rep.cachable = TRUE;	/* XXX */
-	rep.sequenceNumber = client->sequence;
-	rep.length = SIZEOF(fsOpenBitmapFontReply) >> 2;
-	WriteReplyToClient(client,
-			   SIZEOF(fsOpenBitmapFontReply), &rep);
-	return FSSuccess;
     }
     c = (OFclosurePtr) fsalloc(sizeof(OFclosureRec));
     if (!c)
@@ -996,11 +991,13 @@ finish:
     for (i = 0; i < nnames; i++)
 	stringLens += (names->length[i] <= 255) ? names->length[i] : 0;
 
-    reply.type = FS_Reply;
-    reply.length = (SIZEOF(fsListFontsReply) + stringLens + nnames + 3) >> 2;
-    reply.following = 0;
-    reply.nFonts = nnames;
-    reply.sequenceNumber = client->sequence;
+    reply = (fsListFontsReply) {
+	.type = FS_Reply,
+	.sequenceNumber = client->sequence,
+	.length = (SIZEOF(fsListFontsReply) + stringLens + nnames + 3) >> 2,
+	.following = 0,
+	.nFonts = nnames
+    };
 
     bufptr = bufferStart = (char *) ALLOCATE_LOCAL(reply.length << 2);
 
-- 
1.7.9.2



More information about the xorg-devel mailing list