Add do-while loops to DIX macros

This ensures they will behave properly in conditionals and always
require a trailing semicolon.
This commit is contained in:
Demi Marie Obenour 2021-07-20 22:37:26 -04:00
parent d83c84bd9d
commit 5c2592cbb1

View File

@ -54,6 +54,7 @@ SOFTWARE.
#include "cursor.h" #include "cursor.h"
#include "geext.h" #include "geext.h"
#include "events.h" #include "events.h"
#include <dix-config.h>
#include <X11/extensions/XI.h> #include <X11/extensions/XI.h>
#define EARLIER -1 #define EARLIER -1
@ -61,60 +62,76 @@ SOFTWARE.
#define LATER 1 #define LATER 1
#define NullClient ((ClientPtr) 0) #define NullClient ((ClientPtr) 0)
#define REQUEST(type) \
type *stuff = (type *)client->requestBuffer #define REQUEST(type) \
type * stuff = (type *)client->requestBuffer;
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#define REQUEST_SIZE_MATCH(req)\ #define REQUEST_SIZE_MATCH(req) \
if ((sizeof(req) >> 2) != client->req_len)\ do { \
return(BadLength) if ((sizeof(req) >> 2) != client->req_len) \
return(BadLength); \
} while (0)
#define REQUEST_AT_LEAST_SIZE(req) \ #define REQUEST_AT_LEAST_SIZE(req) \
if ((sizeof(req) >> 2) > client->req_len )\ do { \
return(BadLength) if ((sizeof(req) >> 2) > client->req_len) \
return(BadLength); \
} while (0)
#define REQUEST_AT_LEAST_EXTRA_SIZE(req, extra) \ #define REQUEST_AT_LEAST_EXTRA_SIZE(req, extra) \
if (((sizeof(req) + ((uint64_t) extra)) >> 2) > client->req_len ) \ do { \
return(BadLength) if (((sizeof(req) + ((uint64_t) (extra))) >> 2) > client->req_len) \
return(BadLength); \
} while (0)
#define REQUEST_FIXED_SIZE(req, n)\ #define REQUEST_FIXED_SIZE(req, n) \
if (((sizeof(req) >> 2) > client->req_len) || \ do { \
(((n) >> 2) >= client->req_len) || \ if ((((sizeof(req)) >> 2) > client->req_len) || \
((((uint64_t) sizeof(req) + (n) + 3) >> 2) != (uint64_t) client->req_len)) \ (((n) >> 2) >= client->req_len) || \
return(BadLength) ((((uint64_t) sizeof(req) + (n) + 3) >> 2) != (uint64_t) client->req_len)) \
return(BadLength); \
} while (0)
#define LEGAL_NEW_RESOURCE(id,client)\ #define LEGAL_NEW_RESOURCE(id,client) \
if (!LegalNewID(id,client)) \ do { \
{\ if (!LegalNewID((id), (client))) { \
client->errorValue = id;\ (client)->errorValue = (id); \
return BadIDChoice;\ return BadIDChoice; \
} } \
} while (0)
#define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, mode)\ #define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, mode) \
{\ do { \
int tmprc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY, mode);\ int tmprc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY, mode); \
if (tmprc != Success)\ if (tmprc != Success) \
return tmprc;\ return tmprc; \
tmprc = dixLookupGC(&(pGC), stuff->gc, client, DixUseAccess);\ tmprc = dixLookupGC(&(pGC), stuff->gc, client, DixUseAccess); \
if (tmprc != Success)\ if (tmprc != Success) \
return tmprc;\ return tmprc; \
if ((pGC->depth != pDraw->depth) || (pGC->pScreen != pDraw->pScreen))\ if ((pGC->depth != pDraw->depth) || (pGC->pScreen != pDraw->pScreen)) \
return BadMatch;\ return BadMatch; \
}\ if (pGC->serialNumber != pDraw->serialNumber) \
if (pGC->serialNumber != pDraw->serialNumber)\ ValidateGC(pDraw, pGC); \
ValidateGC(pDraw, pGC); } while (0)
#define WriteReplyToClient(pClient, size, pReply) { \ #define WriteReplyToClient(pClient, size, pReply) \
if ((pClient)->swapped) \ do { \
(*ReplySwapVector[((xReq *)(pClient)->requestBuffer)->reqType]) \ if ((pClient)->swapped) \
(pClient, (int)(size), pReply); \ (*ReplySwapVector[((xReq *)(pClient)->requestBuffer)->reqType]) \
else WriteToClient(pClient, (int)(size), (pReply)); } (pClient, (int)(size), pReply); \
else \
WriteToClient(pClient, (int)(size), (pReply)); \
} while (0)
#define WriteSwappedDataToClient(pClient, size, pbuf) \ #define WriteSwappedDataToClient(pClient, size, pbuf) \
if ((pClient)->swapped) \ do { \
(*(pClient)->pSwapReplyFunc)(pClient, (int)(size), pbuf); \ if ((pClient)->swapped) \
else WriteToClient(pClient, (int)(size), (pbuf)); (*(pClient)->pSwapReplyFunc)(pClient, (int)(size), pbuf); \
else \
WriteToClient(pClient, (int)(size), (pbuf)); \
} while (0)
typedef struct _TimeStamp *TimeStampPtr; typedef struct _TimeStamp *TimeStampPtr;