[PATCH 08/19] Use C99 designated initializers in glx Replies
Alan Coopersmith
alan.coopersmith at oracle.com
Sun Jun 24 10:25:15 PDT 2012
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
glx/glxcmds.c | 352 +++++++++++++++++++++++++++--------------------------
glx/single2.c | 28 +++--
glx/single2swap.c | 38 +++---
3 files changed, 217 insertions(+), 201 deletions(-)
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 0a26a3b..397e50b 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -525,7 +525,6 @@ DoMakeCurrent(__GLXclientState * cl,
GLXContextID contextId, GLXContextTag tag)
{
ClientPtr client = cl->client;
- xGLXMakeCurrentReply reply;
__GLXcontext *glxc, *prevglxc;
__GLXdrawable *drawPriv = NULL;
__GLXdrawable *readPriv = NULL;
@@ -641,23 +640,25 @@ DoMakeCurrent(__GLXclientState * cl,
StopUsingContext(prevglxc);
- if (glxc) {
- StartUsingContext(cl, glxc);
- reply.contextTag = glxc->id;
- }
- else {
- reply.contextTag = 0;
- }
-
- reply.length = 0;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
+ {
+ xGLXMakeCurrentReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = 0,
+ .contextTag = 0
+ };
+
+ if (glxc) {
+ StartUsingContext(cl, glxc);
+ reply.contextTag = glxc->id;
+ }
- if (client->swapped) {
- __glXSwapMakeCurrentReply(client, &reply);
- }
- else {
- WriteToClient(client, sz_xGLXMakeCurrentReply, &reply);
+ if (client->swapped) {
+ __glXSwapMakeCurrentReply(client, &reply);
+ }
+ else {
+ WriteToClient(client, sz_xGLXMakeCurrentReply, &reply);
+ }
}
return Success;
}
@@ -703,7 +704,6 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc)
{
ClientPtr client = cl->client;
xGLXIsDirectReq *req = (xGLXIsDirectReq *) pc;
- xGLXIsDirectReply reply;
__GLXcontext *glxc;
int err;
@@ -711,20 +711,23 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc)
if (!validGlxContext(cl->client, req->context, DixReadAccess, &glxc, &err))
return err;
+ else {
+ xGLXIsDirectReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = 0,
+ .isDirect = glxc->isDirect
+ };
- reply.isDirect = glxc->isDirect;
- reply.length = 0;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
+ if (client->swapped) {
+ __glXSwapIsDirectReply(client, &reply);
+ }
+ else {
+ WriteToClient(client, sz_xGLXIsDirectReply, &reply);
+ }
- if (client->swapped) {
- __glXSwapIsDirectReply(client, &reply);
- }
- else {
- WriteToClient(client, sz_xGLXIsDirectReply, &reply);
+ return Success;
}
-
- return Success;
}
int
@@ -732,7 +735,6 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc)
{
ClientPtr client = cl->client;
xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc;
- xGLXQueryVersionReply reply;
GLuint major, minor;
REQUEST_SIZE_MATCH(xGLXQueryVersionReq);
@@ -747,19 +749,23 @@ __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.majorVersion = glxMajorVersion;
- reply.minorVersion = glxMinorVersion;
- reply.length = 0;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
+ {
+ xGLXQueryVersionReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = 0,
+ .majorVersion = glxMajorVersion,
+ .minorVersion = glxMinorVersion
+ };
- if (client->swapped) {
- __glXSwapQueryVersionReply(client, &reply);
- }
- else {
- WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
+ if (client->swapped) {
+ __glXSwapQueryVersionReply(client, &reply);
+ }
+ else {
+ WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
+ }
+ return Success;
}
- return Success;
}
int
@@ -911,7 +917,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];
@@ -924,23 +929,26 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
return err;
+ else {
+ xGLXGetVisualConfigsReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = (pGlxScreen->numVisuals *
+ __GLX_SIZE_CARD32 * GLX_VIS_CONFIG_TOTAL) >> 2,
+ .numVisuals = pGlxScreen->numVisuals,
+ .numProps = GLX_VIS_CONFIG_TOTAL
+ };
- reply.numVisuals = pGlxScreen->numVisuals;
- reply.numProps = GLX_VIS_CONFIG_TOTAL;
- reply.length =
- (reply.numVisuals * __GLX_SIZE_CARD32 * GLX_VIS_CONFIG_TOTAL) >> 2;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
+ if (client->swapped) {
+ __GLX_SWAP_SHORT(&reply.sequenceNumber);
+ __GLX_SWAP_INT(&reply.length);
+ __GLX_SWAP_INT(&reply.numVisuals);
+ __GLX_SWAP_INT(&reply.numProps);
+ }
- if (client->swapped) {
- __GLX_SWAP_SHORT(&reply.sequenceNumber);
- __GLX_SWAP_INT(&reply.length);
- __GLX_SWAP_INT(&reply.numVisuals);
- __GLX_SWAP_INT(&reply.numProps);
+ WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
}
- WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
-
for (i = 0; i < pGlxScreen->numVisuals; i++) {
modes = pGlxScreen->visuals[i];
@@ -1017,7 +1025,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;
@@ -1028,22 +1035,25 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen)
if (!validGlxScreen(cl->client, screen, &pGlxScreen, &err))
return err;
+ else {
+ xGLXGetFBConfigsReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = __GLX_FBCONFIG_ATTRIBS_LENGTH * pGlxScreen->numFBConfigs,
+ .numFBConfigs = pGlxScreen->numFBConfigs,
+ .numAttribs = __GLX_TOTAL_FBCONFIG_ATTRIBS
+ };
- reply.numFBConfigs = pGlxScreen->numFBConfigs;
- reply.numAttribs = __GLX_TOTAL_FBCONFIG_ATTRIBS;
- reply.length = (__GLX_FBCONFIG_ATTRIBS_LENGTH * reply.numFBConfigs);
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
+ if (client->swapped) {
+ __GLX_SWAP_SHORT(&reply.sequenceNumber);
+ __GLX_SWAP_INT(&reply.length);
+ __GLX_SWAP_INT(&reply.numFBConfigs);
+ __GLX_SWAP_INT(&reply.numAttribs);
+ }
- if (client->swapped) {
- __GLX_SWAP_SHORT(&reply.sequenceNumber);
- __GLX_SWAP_INT(&reply.length);
- __GLX_SWAP_INT(&reply.numFBConfigs);
- __GLX_SWAP_INT(&reply.numAttribs);
+ WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply);
}
- WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply);
-
for (modes = pGlxScreen->fbconfigs; modes != NULL; modes = modes->next) {
p = 0;
@@ -1643,44 +1653,45 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
{
ClientPtr client = cl->client;
__GLXcontext *ctx;
- xGLXQueryContextInfoEXTReply reply;
- int nProps;
int *sendBuf, *pSendBuf;
int nReplyBytes;
int err;
if (!validGlxContext(cl->client, gcId, DixReadAccess, &ctx, &err))
return err;
+ else {
+ int nProps = 3;
+ xGLXQueryContextInfoEXTReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = nProps << 1,
+ .n = nProps
+ };
+
+ nReplyBytes = reply.length << 2;
+ sendBuf = (int *) malloc((size_t) nReplyBytes);
+ if (sendBuf == NULL) {
+ return __glXError(GLXBadContext); /* XXX: Is this correct? */
+ }
+ pSendBuf = sendBuf;
+ *pSendBuf++ = GLX_SHARE_CONTEXT_EXT;
+ *pSendBuf++ = (int) (ctx->share_id);
+ *pSendBuf++ = GLX_VISUAL_ID_EXT;
+ *pSendBuf++ = (int) (ctx->config->visualID);
+ *pSendBuf++ = GLX_SCREEN_EXT;
+ *pSendBuf++ = (int) (ctx->pGlxScreen->pScreen->myNum);
- nProps = 3;
- reply.length = nProps << 1;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.n = nProps;
-
- nReplyBytes = reply.length << 2;
- sendBuf = (int *) malloc((size_t) nReplyBytes);
- if (sendBuf == NULL) {
- return __glXError(GLXBadContext); /* XXX: Is this correct? */
- }
- pSendBuf = sendBuf;
- *pSendBuf++ = GLX_SHARE_CONTEXT_EXT;
- *pSendBuf++ = (int) (ctx->share_id);
- *pSendBuf++ = GLX_VISUAL_ID_EXT;
- *pSendBuf++ = (int) (ctx->config->visualID);
- *pSendBuf++ = GLX_SCREEN_EXT;
- *pSendBuf++ = (int) (ctx->pGlxScreen->pScreen->myNum);
+ if (client->swapped) {
+ __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
+ }
+ else {
+ WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
+ WriteToClient(client, nReplyBytes, sendBuf);
+ }
+ free((char *) sendBuf);
- if (client->swapped) {
- __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
- }
- else {
- WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
- WriteToClient(client, nReplyBytes, sendBuf);
+ return Success;
}
- free((char *) sendBuf);
-
- return Success;
}
int
@@ -1850,40 +1861,40 @@ static int
DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
{
ClientPtr client = cl->client;
- xGLXGetDrawableAttributesReply reply;
__GLXdrawable *pGlxDraw;
CARD32 attributes[6];
- int numAttribs, error;
+ int error;
if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
DixGetAttrAccess, &pGlxDraw, &error))
return error;
+ else {
+ int numAttribs = 3;
+ xGLXGetDrawableAttributesReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = numAttribs << 1,
+ .numAttribs = numAttribs
+ };
+
+ attributes[0] = GLX_TEXTURE_TARGET_EXT;
+ attributes[1] = pGlxDraw->target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT :
+ GLX_TEXTURE_RECTANGLE_EXT;
+ attributes[2] = GLX_Y_INVERTED_EXT;
+ attributes[3] = GL_FALSE;
+ attributes[4] = GLX_EVENT_MASK;
+ attributes[5] = pGlxDraw->eventMask;
- numAttribs = 3;
- reply.length = numAttribs << 1;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.numAttribs = numAttribs;
-
- attributes[0] = GLX_TEXTURE_TARGET_EXT;
- attributes[1] = pGlxDraw->target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT :
- GLX_TEXTURE_RECTANGLE_EXT;
- attributes[2] = GLX_Y_INVERTED_EXT;
- attributes[3] = GL_FALSE;
- attributes[4] = GLX_EVENT_MASK;
- attributes[5] = pGlxDraw->eventMask;
+ if (client->swapped) {
+ __glXSwapGetDrawableAttributesReply(client, &reply, attributes);
+ }
+ else {
+ WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply);
+ WriteToClient(client, reply.length * sizeof(CARD32), attributes);
+ }
- if (client->swapped) {
- __glXSwapGetDrawableAttributesReply(client, &reply, attributes);
- }
- else {
- WriteToClient(client, sz_xGLXGetDrawableAttributesReply,
- (char *) &reply);
- WriteToClient(client, reply.length * sizeof(CARD32),
- (char *) attributes);
+ return Success;
}
-
- return Success;
}
int
@@ -2288,41 +2299,40 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
{
ClientPtr client = cl->client;
xGLXQueryExtensionsStringReq *req = (xGLXQueryExtensionsStringReq *) pc;
- xGLXQueryExtensionsStringReply reply;
__GLXscreen *pGlxScreen;
- size_t n, length;
- char *buf;
int err;
REQUEST_SIZE_MATCH(xGLXQueryExtensionsStringReq);
if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
return err;
+ else {
+ size_t n = strlen(pGlxScreen->GLXextensions) + 1;
+ size_t length = __GLX_PAD(n) >> 2;
+ xGLXQueryExtensionsStringReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = length,
+ .n = n
+ };
+
+ /* Allocate buffer to make sure it's a multiple of 4 bytes big. */
+ char *buf = calloc(length, 4);
+ if (buf == NULL)
+ return BadAlloc;
+ memcpy(buf, pGlxScreen->GLXextensions, n);
- n = strlen(pGlxScreen->GLXextensions) + 1;
- length = __GLX_PAD(n) >> 2;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.length = length;
- reply.n = n;
-
- /* Allocate buffer to make sure it's a multiple of 4 bytes big. */
- buf = (char *) malloc(length << 2);
- if (buf == NULL)
- return BadAlloc;
- memcpy(buf, pGlxScreen->GLXextensions, n);
+ if (client->swapped) {
+ glxSwapQueryExtensionsStringReply(client, &reply, buf);
+ }
+ else {
+ WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply);
+ WriteToClient(client, (int) (length << 2), buf);
+ }
- if (client->swapped) {
- glxSwapQueryExtensionsStringReply(client, &reply, buf);
- }
- else {
- WriteToClient(client, sz_xGLXQueryExtensionsStringReply,
- (char *) &reply);
- WriteToClient(client, (int) (length << 2), buf);
+ free(buf);
+ return Success;
}
-
- free(buf);
- return Success;
}
int
@@ -2330,10 +2340,7 @@ __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;
__GLXscreen *pGlxScreen;
int err;
char ver_str[16];
@@ -2361,29 +2368,34 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc)
return BadValue;
}
- n = strlen(ptr) + 1;
- length = __GLX_PAD(n) >> 2;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.length = length;
- reply.n = n;
- buf = (char *) malloc(length << 2);
- if (buf == NULL) {
- return BadAlloc;
- }
- memcpy(buf, ptr, n);
+ {
+ size_t n = strlen(ptr) + 1;
+ size_t length = __GLX_PAD(n) >> 2;
+ xGLXQueryServerStringReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = length,
+ .n = n
+ };
- if (client->swapped) {
- glxSwapQueryServerStringReply(client, &reply, buf);
- }
- else {
- WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
- WriteToClient(client, (int) (length << 2), buf);
- }
+ char *buf = calloc(length, 4);
+ if (buf == NULL) {
+ return BadAlloc;
+ }
+ memcpy(buf, ptr, n);
- free(buf);
- return Success;
+ if (client->swapped) {
+ glxSwapQueryServerStringReply(client, &reply, buf);
+ }
+ else {
+ WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
+ WriteToClient(client, (int) (length << 2), buf);
+ }
+
+ free(buf);
+ return Success;
+ }
}
int
diff --git a/glx/single2.c b/glx/single2.c
index 4d8ea4e..10af310 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -108,8 +108,6 @@ __glXDisp_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
int
__glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client;
- xGLXRenderModeReply reply;
__GLXcontext *cx;
GLint nitems = 0, retBytes = 0, retval, newModeCheck;
GLubyte *retBuffer = NULL;
@@ -192,18 +190,22 @@ __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc)
** selection array, as per the API for glRenderMode itself.
*/
noChangeAllowed:;
- client = cl->client;
- reply.length = nitems;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.retval = retval;
- reply.size = nitems;
- reply.newMode = newMode;
- WriteToClient(client, sz_xGLXRenderModeReply, &reply);
- if (retBytes) {
- WriteToClient(client, retBytes, retBuffer);
+ {
+ ClientPtr client = cl->client;
+ xGLXRenderModeReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = nitems,
+ .retval = retval,
+ .size = nitems,
+ .newMode = newMode
+ };
+ WriteToClient(client, sz_xGLXRenderModeReply, &reply);
+ if (retBytes) {
+ WriteToClient(client, retBytes, retBuffer);
+ }
+ return Success;
}
- return Success;
}
int
diff --git a/glx/single2swap.c b/glx/single2swap.c
index 9da2afd..6bfbf7a 100644
--- a/glx/single2swap.c
+++ b/glx/single2swap.c
@@ -113,9 +113,7 @@ __glXDispSwap_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
int
__glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client;
__GLXcontext *cx;
- xGLXRenderModeReply reply;
GLint nitems = 0, retBytes = 0, retval, newModeCheck;
GLubyte *retBuffer = NULL;
GLenum newMode;
@@ -204,23 +202,27 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc)
** selection array, as per the API for glRenderMode itself.
*/
noChangeAllowed:;
- client = cl->client;
- reply.length = nitems;
- reply.type = X_Reply;
- reply.sequenceNumber = client->sequence;
- reply.retval = retval;
- reply.size = nitems;
- reply.newMode = newMode;
- __GLX_SWAP_SHORT(&reply.sequenceNumber);
- __GLX_SWAP_INT(&reply.length);
- __GLX_SWAP_INT(&reply.retval);
- __GLX_SWAP_INT(&reply.size);
- __GLX_SWAP_INT(&reply.newMode);
- WriteToClient(client, sz_xGLXRenderModeReply, &reply);
- if (retBytes) {
- WriteToClient(client, retBytes, retBuffer);
+ {
+ ClientPtr client = cl->client;
+ xGLXRenderModeReply reply = {
+ .type = X_Reply,
+ .sequenceNumber = client->sequence,
+ .length = nitems,
+ .retval = retval,
+ .size = nitems,
+ .newMode = newMode
+ };
+ __GLX_SWAP_SHORT(&reply.sequenceNumber);
+ __GLX_SWAP_INT(&reply.length);
+ __GLX_SWAP_INT(&reply.retval);
+ __GLX_SWAP_INT(&reply.size);
+ __GLX_SWAP_INT(&reply.newMode);
+ WriteToClient(client, sz_xGLXRenderModeReply, &reply);
+ if (retBytes) {
+ WriteToClient(client, retBytes, retBuffer);
+ }
+ return Success;
}
- return Success;
}
int
--
1.7.9.2
More information about the xorg-devel
mailing list