dix: write out X_ListFonts 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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-04-03 18:57:14 +02:00
parent 83569a31c8
commit 712febb9b4
4 changed files with 17 additions and 26 deletions

View File

@ -564,9 +564,6 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
int nnames; int nnames;
int stringLens; int stringLens;
int i; int i;
xListFontsReply reply;
char *bufptr;
char *bufferStart;
int aliascount = 0; int aliascount = 0;
if (client->clientGone) { if (client->clientGone) {
@ -748,16 +745,17 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
for (i = 0; i < nnames; i++) for (i = 0; i < nnames; i++)
stringLens += (names->length[i] <= 255) ? names->length[i] : 0; stringLens += (names->length[i] <= 255) ? names->length[i] : 0;
reply = (xListFontsReply) { xListFontsReply rep = {
.type = X_Reply, .type = X_Reply,
.length = bytes_to_int32(stringLens + nnames), .length = bytes_to_int32(stringLens + nnames),
.nFonts = nnames, .nFonts = nnames,
.sequenceNumber = client->sequence .sequenceNumber = client->sequence
}; };
bufptr = bufferStart = calloc(1, reply.length << 2); char *bufferStart = calloc(1, rep.length << 2);
char *bufptr = bufferStart;
if (!bufptr && reply.length) { if (!bufptr && rep.length) {
SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc);
goto bail; goto bail;
} }
@ -767,17 +765,23 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
*/ */
for (i = 0; i < nnames; i++) { for (i = 0; i < nnames; i++) {
if (names->length[i] > 255) if (names->length[i] > 255)
reply.nFonts--; rep.nFonts--;
else { else {
*bufptr++ = names->length[i]; *bufptr++ = names->length[i];
memcpy(bufptr, names->names[i], names->length[i]); memcpy(bufptr, names->names[i], names->length[i]);
bufptr += names->length[i]; bufptr += names->length[i];
} }
} }
nnames = reply.nFonts; nnames = rep.nFonts;
reply.length = bytes_to_int32(stringLens + nnames); rep.length = bytes_to_int32(stringLens + nnames);
client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swaps(&rep.nFonts);
}
WriteToClient(client, sizeof(rep), &rep);
WriteToClient(client, stringLens + nnames, bufferStart); WriteToClient(client, stringLens + nnames, bufferStart);
free(bufferStart); free(bufferStart);

View File

@ -258,7 +258,7 @@ SwapCharInfo(xCharInfo * pInfo)
swaps(&pInfo->attributes); swaps(&pInfo->attributes);
} }
static void _X_COLD void
SwapFontInfo(xQueryFontReply * pr) SwapFontInfo(xQueryFontReply * pr)
{ {
swaps(&pr->minCharOrByte2); swaps(&pr->minCharOrByte2);
@ -316,15 +316,6 @@ SQueryTextExtentsReply(ClientPtr pClient, int size,
WriteToClient(pClient, size, pRep); WriteToClient(pClient, size, pRep);
} }
void _X_COLD
SListFontsReply(ClientPtr pClient, int size, xListFontsReply * pRep)
{
swaps(&pRep->sequenceNumber);
swapl(&pRep->length);
swaps(&pRep->nFonts);
WriteToClient(pClient, size, pRep);
}
void _X_COLD void _X_COLD
SListFontsWithInfoReply(ClientPtr pClient, int size, SListFontsWithInfoReply(ClientPtr pClient, int size,
xListFontsWithInfoReply * pRep) xListFontsWithInfoReply * pRep)

View File

@ -764,7 +764,7 @@ ReplySwapPtr ReplySwapVector[256] = {
ReplyNotSwappd, ReplyNotSwappd,
ReplyNotSwappd, ReplyNotSwappd,
(ReplySwapPtr) SQueryTextExtentsReply, (ReplySwapPtr) SQueryTextExtentsReply,
(ReplySwapPtr) SListFontsReply, ReplyNotSwappd,
(ReplySwapPtr) SListFontsWithInfoReply, /* 50 */ (ReplySwapPtr) SListFontsWithInfoReply, /* 50 */
ReplyNotSwappd, ReplyNotSwappd,
(ReplySwapPtr) SGetFontPathReply, (ReplySwapPtr) SGetFontPathReply,

View File

@ -69,10 +69,6 @@ extern void SQueryTextExtentsReply(ClientPtr /* pClient */ ,
xQueryTextExtentsReply * /* pRep */ xQueryTextExtentsReply * /* pRep */
); );
extern void SListFontsReply(ClientPtr /* pClient */ ,
int /* size */ ,
xListFontsReply * /* pRep */ );
extern void SListFontsWithInfoReply(ClientPtr /* pClient */ , extern void SListFontsWithInfoReply(ClientPtr /* pClient */ ,
int /* size */ , int /* size */ ,
xListFontsWithInfoReply * xListFontsWithInfoReply *