From 558ded4dbf95a0cf5a48db8273faae89e7d8ea1f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 28 Aug 2024 13:25:06 +0200 Subject: [PATCH] glx: assign at declaration Assigning structs at declaration is quicker to read/understand. No need to support ancient compilers that couldn't do that, anymore. Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- glx/glxcmds.c | 31 ++++++++++++------------------- glx/indirect_util.c | 26 ++++++++++++++------------ glx/single2.c | 8 ++++---- glx/single2swap.c | 5 ++--- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/glx/glxcmds.c b/glx/glxcmds.c index ab1ed6410..12b3c7dc5 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -702,14 +702,13 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc; - xGLXIsDirectReply reply; __GLXcontext *glxc; int err; if (!validGlxContext(cl->client, req->context, DixReadAccess, &glxc, &err)) return err; - reply = (xGLXIsDirectReply) { + xGLXIsDirectReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = 0, @@ -731,13 +730,11 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc; - xGLXQueryVersionReply reply; - GLuint major, minor; REQUEST_SIZE_MATCH(xGLXQueryVersionReq); - major = req->majorVersion; - minor = req->minorVersion; + GLuint major = req->majorVersion; + GLuint minor = req->minorVersion; (void) major; (void) minor; @@ -746,7 +743,7 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc) ** client if it wants to work with older clients; however, in this ** implementation the server just returns its version number. */ - reply = (xGLXQueryVersionReply) { + xGLXQueryVersionReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = 0, @@ -906,7 +903,6 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc) { xGLXGetVisualConfigsReq *req = (xGLXGetVisualConfigsReq *) pc; ClientPtr client = cl->client; - xGLXGetVisualConfigsReply reply; __GLXscreen *pGlxScreen; __GLXconfig *modes; CARD32 buf[GLX_VIS_CONFIG_TOTAL]; @@ -918,7 +914,7 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc) if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err)) return err; - reply = (xGLXGetVisualConfigsReply) { + xGLXGetVisualConfigsReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = (pGlxScreen->numVisuals * @@ -1021,7 +1017,6 @@ static int DoGetFBConfigs(__GLXclientState * cl, unsigned screen) { ClientPtr client = cl->client; - xGLXGetFBConfigsReply reply; __GLXscreen *pGlxScreen; CARD32 buf[__GLX_FBCONFIG_ATTRIBS_LENGTH]; int p, err; @@ -1033,7 +1028,7 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen) if (!validGlxScreen(cl->client, screen, &pGlxScreen, &err)) return err; - reply = (xGLXGetFBConfigsReply) { + xGLXGetFBConfigsReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = __GLX_FBCONFIG_ATTRIBS_LENGTH * pGlxScreen->numFBConfigs, @@ -1662,7 +1657,6 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) { ClientPtr client = cl->client; __GLXcontext *ctx; - xGLXQueryContextInfoEXTReply reply; int nProps = 5; int sendBuf[nProps * 2]; int nReplyBytes; @@ -1671,7 +1665,7 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId) if (!validGlxContext(cl->client, gcId, DixReadAccess, &ctx, &err)) return err; - reply = (xGLXQueryContextInfoEXTReply) { + xGLXQueryContextInfoEXTReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = nProps << 1, @@ -1877,7 +1871,6 @@ static int DoGetDrawableAttributes(__GLXclientState * cl, XID drawId) { ClientPtr client = cl->client; - xGLXGetDrawableAttributesReply reply; __GLXdrawable *pGlxDraw = NULL; DrawablePtr pDraw; CARD32 attributes[20]; @@ -1927,7 +1920,7 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId) ATTRIB(GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT); #undef ATTRIB - reply = (xGLXGetDrawableAttributesReply) { + xGLXGetDrawableAttributesReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = num << 1, @@ -2373,7 +2366,6 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; xGLXQueryExtensionsStringReq *req = (xGLXQueryExtensionsStringReq *) pc; - xGLXQueryExtensionsStringReply reply; __GLXscreen *pGlxScreen; size_t n, length; char *buf; @@ -2384,7 +2376,8 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc) n = strlen(pGlxScreen->GLXextensions) + 1; length = __GLX_PAD(n) >> 2; - reply = (xGLXQueryExtensionsStringReply) { + + xGLXQueryExtensionsStringReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = length, @@ -2425,7 +2418,6 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *) pc; - xGLXQueryServerStringReply reply; size_t n, length; const char *ptr; char *buf; @@ -2457,7 +2449,8 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc) n = strlen(ptr) + 1; length = __GLX_PAD(n) >> 2; - reply = (xGLXQueryServerStringReply) { + + xGLXQueryServerStringReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = length, diff --git a/glx/indirect_util.c b/glx/indirect_util.c index 50b8e3f1c..56ef179cd 100644 --- a/glx/indirect_util.c +++ b/glx/indirect_util.c @@ -112,7 +112,6 @@ __glXSendReply(ClientPtr client, const void *data, size_t elements, size_t element_size, GLboolean always_array, CARD32 retval) { size_t reply_ints = 0; - xGLXSingleReply reply = { 0, }; if (__glXErrorOccured()) { elements = 0; @@ -121,11 +120,13 @@ __glXSendReply(ClientPtr client, const void *data, size_t elements, reply_ints = bytes_to_int32(elements * element_size); } - reply.length = reply_ints; - reply.type = X_Reply; - reply.sequenceNumber = client->sequence; - reply.size = elements; - reply.retval = retval; + xGLXSingleReply reply = { + .length = reply_ints, + .type = X_Reply, + .sequenceNumber = client->sequence, + .size = elements, + .retval = retval, + }; /* It is faster on almost always every architecture to just copy the 8 * bytes, even when not necessary, than check to see of the value of @@ -159,7 +160,6 @@ __glXSendReplySwap(ClientPtr client, const void *data, size_t elements, size_t element_size, GLboolean always_array, CARD32 retval) { size_t reply_ints = 0; - xGLXSingleReply reply = { 0, }; if (__glXErrorOccured()) { elements = 0; @@ -168,11 +168,13 @@ __glXSendReplySwap(ClientPtr client, const void *data, size_t elements, reply_ints = bytes_to_int32(elements * element_size); } - reply.length = bswap_32(reply_ints); - reply.type = X_Reply; - reply.sequenceNumber = bswap_16(client->sequence); - reply.size = bswap_32(elements); - reply.retval = bswap_32(retval); + xGLXSingleReply reply = { + .length = bswap_32(reply_ints), + .type = X_Reply, + .sequenceNumber = bswap_16(client->sequence), + .size = bswap_32(elements), + .retval = bswap_32(retval), + }; /* It is faster on almost always every architecture to just copy the 8 * bytes, even when not necessary, than check to see of the value of diff --git a/glx/single2.c b/glx/single2.c index 7c9e24549..ef355b470 100644 --- a/glx/single2.c +++ b/glx/single2.c @@ -106,7 +106,6 @@ int __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; - xGLXRenderModeReply reply; __GLXcontext *cx; GLint nitems = 0, retBytes = 0, retval, newModeCheck; GLubyte *retBuffer = NULL; @@ -191,7 +190,7 @@ __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc) ** selection array, as per the API for glRenderMode itself. */ noChangeAllowed:; - reply = (xGLXRenderModeReply) { + xGLXRenderModeReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = nitems, @@ -230,7 +229,6 @@ __glXDisp_Finish(__GLXclientState * cl, GLbyte * pc) ClientPtr client = cl->client; __GLXcontext *cx; int error; - xGLXSingleReply reply = { 0, }; REQUEST_SIZE_MATCH(xGLXSingleReq); @@ -244,6 +242,8 @@ __glXDisp_Finish(__GLXclientState * cl, GLbyte * pc) /* Send empty reply packet to indicate finish is finished */ client = cl->client; + + xGLXSingleReply reply = { 0 }; __GLX_BEGIN_REPLY(0); __GLX_SEND_HEADER(); return Success; @@ -327,7 +327,6 @@ DoGetString(__GLXclientState * cl, GLbyte * pc, GLboolean need_swap) __GLXcontext *cx; GLenum name; const char *string; - xGLXSingleReply reply = { 0, }; __GLX_DECLARE_SWAP_VARIABLES; int error; @@ -381,6 +380,7 @@ DoGetString(__GLXclientState * cl, GLbyte * pc, GLboolean need_swap) length = strlen((const char *) string) + 1; } + xGLXSingleReply reply = { 0 }; __GLX_BEGIN_REPLY(length); __GLX_PUT_SIZE(length); diff --git a/glx/single2swap.c b/glx/single2swap.c index b7c7c00da..fc9e584b0 100644 --- a/glx/single2swap.c +++ b/glx/single2swap.c @@ -112,7 +112,6 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; __GLXcontext *cx; - xGLXRenderModeReply reply; GLint nitems = 0, retBytes = 0, retval, newModeCheck; GLubyte *retBuffer = NULL; GLenum newMode; @@ -203,7 +202,7 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc) ** selection array, as per the API for glRenderMode itself. */ noChangeAllowed:; - reply = (xGLXRenderModeReply) { + xGLXRenderModeReply reply = { .type = X_Reply, .sequenceNumber = client->sequence, .length = nitems, @@ -250,7 +249,6 @@ __glXDispSwap_Finish(__GLXclientState * cl, GLbyte * pc) ClientPtr client = cl->client; __GLXcontext *cx; int error; - xGLXSingleReply reply = { 0, }; __GLX_DECLARE_SWAP_VARIABLES; @@ -266,6 +264,7 @@ __glXDispSwap_Finish(__GLXclientState * cl, GLbyte * pc) glFinish(); /* Send empty reply packet to indicate finish is finished */ + xGLXSingleReply reply = { 0 }; __GLX_BEGIN_REPLY(0); __GLX_PUT_RETVAL(0); __GLX_SWAP_REPLY_HEADER();