From 725bb2d20d37e096a45f85924c7e02f31087c3af Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 3 Apr 2025 19:36:17 +0200 Subject: [PATCH] dix: write out X_ListInstalledColormaps reply directly No need for using a complex callback machinery, if we just move the little pieces of byte-swapping directly into the request handler. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dispatch.c | 42 ++++++++++++++++++++++++++---------------- dix/swaprep.c | 10 ---------- dix/tables.c | 2 +- include/swaprep.h | 5 ----- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index e9bec35f7..f54240fc7 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -2572,7 +2572,7 @@ ProcUninstallColormap(ClientPtr client) int ProcListInstalledColormaps(ClientPtr client) { - int nummaps, rc; + int rc; WindowPtr pWin; REQUEST(xResourceReq); @@ -2586,23 +2586,33 @@ ProcListInstalledColormaps(ClientPtr client) if (rc != Success) return rc; - xListInstalledColormapsReply *preply = calloc(1, - sizeof(xListInstalledColormapsReply) + - pWin->drawable.pScreen->maxInstalledCmaps * - sizeof(Colormap)); - if (!preply) + Colormap *cm = calloc(pWin->drawable.pScreen->maxInstalledCmaps, + sizeof(Colormap)); + if (!cm) return BadAlloc; - preply->type = X_Reply; - preply->sequenceNumber = client->sequence; - nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) - (pWin->drawable.pScreen, (Colormap *) &preply[1]); - preply->nColormaps = nummaps; - preply->length = nummaps; - WriteReplyToClient(client, sizeof(xListInstalledColormapsReply), preply); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - free(preply); + const ScreenPtr pScreen = pWin->drawable.pScreen; + const int nummaps = pScreen->ListInstalledColormaps(pScreen, cm); + + xListInstalledColormapsReply rep = { + .type = X_Reply, + .sequenceNumber = client->sequence, + .nColormaps = nummaps, + .length = nummaps, + }; + + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.nColormaps); + } + + WriteToClient(client, sizeof(rep), &rep); + if (client->swapped) + Swap32Write(client, nummaps * sizeof(Colormap), cm); + else + WriteToClient(client, nummaps * sizeof(Colormap), cm); + free(cm); return Success; } diff --git a/dix/swaprep.c b/dix/swaprep.c index 790261b27..6a875a99d 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -310,16 +310,6 @@ SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep) WriteToClient(pClient, size, pRep); } -void _X_COLD -SListInstalledColormapsReply(ClientPtr pClient, int size, - xListInstalledColormapsReply * pRep) -{ - swaps(&pRep->sequenceNumber); - swapl(&pRep->length); - swaps(&pRep->nColormaps); - WriteToClient(pClient, size, pRep); -} - void _X_COLD SAllocColorReply(ClientPtr pClient, int size, xAllocColorReply * pRep) { diff --git a/dix/tables.c b/dix/tables.c index 9def465f1..970d8e5e0 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -798,7 +798,7 @@ ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, /* 80 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr) SListInstalledColormapsReply, + ReplyNotSwappd, (ReplySwapPtr) SAllocColorReply, (ReplySwapPtr) SAllocNamedColorReply, /* 85 */ (ReplySwapPtr) SAllocColorCellsReply, diff --git a/include/swaprep.h b/include/swaprep.h index ba0475510..d362bac55 100644 --- a/include/swaprep.h +++ b/include/swaprep.h @@ -68,11 +68,6 @@ extern void SGetFontPathReply(ClientPtr /* pClient */ , int /* size */ , xGetFontPathReply * /* pRep */ ); -extern void SListInstalledColormapsReply(ClientPtr /* pClient */ , - int /* size */ , - xListInstalledColormapsReply - * /* pRep */ ); - extern void SAllocColorReply(ClientPtr /* pClient */ , int /* size */ , xAllocColorReply * /* pRep */ );