Replace X-allocation functions with their C89 counterparts
The only remaining X-functions used in server are XNF*, the rest is converted to plain alloc/calloc/realloc/free/strdup. X* functions are still exported from server and x* macros are still defined in header file, so both ABI and API are not affected by this change. Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
128
dix/colormap.c
128
dix/colormap.c
@@ -274,7 +274,7 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||
if ((class | DynamicClass) == DirectColor)
|
||||
sizebytes *= 3;
|
||||
sizebytes += sizeof(ColormapRec);
|
||||
pmap = xalloc(sizebytes);
|
||||
pmap = malloc(sizebytes);
|
||||
if (!pmap)
|
||||
return (BadAlloc);
|
||||
#if defined(_XSERVER64)
|
||||
@@ -310,10 +310,10 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||
for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
|
||||
pent->refcnt = AllocPrivate;
|
||||
pmap->freeRed = 0;
|
||||
ppix = xalloc(size * sizeof(Pixel));
|
||||
ppix = malloc(size * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
{
|
||||
xfree(pmap);
|
||||
free(pmap);
|
||||
return (BadAlloc);
|
||||
}
|
||||
pmap->clientPixelsRed[client] = ppix;
|
||||
@@ -356,11 +356,11 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||
for(pent = &pmap->green[size-1]; pent >= pmap->green; pent--)
|
||||
pent->refcnt = AllocPrivate;
|
||||
pmap->freeGreen = 0;
|
||||
ppix = xalloc(size * sizeof(Pixel));
|
||||
ppix = malloc(size * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
{
|
||||
xfree(pmap->clientPixelsRed[client]);
|
||||
xfree(pmap);
|
||||
free(pmap->clientPixelsRed[client]);
|
||||
free(pmap);
|
||||
return(BadAlloc);
|
||||
}
|
||||
pmap->clientPixelsGreen[client] = ppix;
|
||||
@@ -372,12 +372,12 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||
for(pent = &pmap->blue[size-1]; pent >= pmap->blue; pent--)
|
||||
pent->refcnt = AllocPrivate;
|
||||
pmap->freeBlue = 0;
|
||||
ppix = xalloc(size * sizeof(Pixel));
|
||||
ppix = malloc(size * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
{
|
||||
xfree(pmap->clientPixelsGreen[client]);
|
||||
xfree(pmap->clientPixelsRed[client]);
|
||||
xfree(pmap);
|
||||
free(pmap->clientPixelsGreen[client]);
|
||||
free(pmap->clientPixelsRed[client]);
|
||||
free(pmap);
|
||||
return(BadAlloc);
|
||||
}
|
||||
pmap->clientPixelsBlue[client] = ppix;
|
||||
@@ -439,7 +439,7 @@ FreeColormap (pointer value, XID mid)
|
||||
if(pmap->clientPixelsRed)
|
||||
{
|
||||
for(i = 0; i < MAXCLIENTS; i++)
|
||||
xfree(pmap->clientPixelsRed[i]);
|
||||
free(pmap->clientPixelsRed[i]);
|
||||
}
|
||||
|
||||
if ((pmap->class == PseudoColor) || (pmap->class == GrayScale))
|
||||
@@ -451,11 +451,11 @@ FreeColormap (pointer value, XID mid)
|
||||
if(pent->fShared)
|
||||
{
|
||||
if (--pent->co.shco.red->refcnt == 0)
|
||||
xfree(pent->co.shco.red);
|
||||
free(pent->co.shco.red);
|
||||
if (--pent->co.shco.green->refcnt == 0)
|
||||
xfree(pent->co.shco.green);
|
||||
free(pent->co.shco.green);
|
||||
if (--pent->co.shco.blue->refcnt == 0)
|
||||
xfree(pent->co.shco.blue);
|
||||
free(pent->co.shco.blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -463,13 +463,13 @@ FreeColormap (pointer value, XID mid)
|
||||
{
|
||||
for(i = 0; i < MAXCLIENTS; i++)
|
||||
{
|
||||
xfree(pmap->clientPixelsGreen[i]);
|
||||
xfree(pmap->clientPixelsBlue[i]);
|
||||
free(pmap->clientPixelsGreen[i]);
|
||||
free(pmap->clientPixelsBlue[i]);
|
||||
}
|
||||
}
|
||||
|
||||
dixFreePrivates(pmap->devPrivates);
|
||||
xfree(pmap);
|
||||
free(pmap);
|
||||
return(Success);
|
||||
}
|
||||
|
||||
@@ -720,11 +720,11 @@ FreeCell (ColormapPtr pmap, Pixel i, int channel)
|
||||
if (pent->fShared)
|
||||
{
|
||||
if(--pent->co.shco.red->refcnt == 0)
|
||||
xfree(pent->co.shco.red);
|
||||
free(pent->co.shco.red);
|
||||
if(--pent->co.shco.green->refcnt == 0)
|
||||
xfree(pent->co.shco.green);
|
||||
free(pent->co.shco.green);
|
||||
if(--pent->co.shco.blue->refcnt == 0)
|
||||
xfree(pent->co.shco.blue);
|
||||
free(pent->co.shco.blue);
|
||||
pent->fShared = FALSE;
|
||||
}
|
||||
pent->refcnt = 0;
|
||||
@@ -743,7 +743,7 @@ UpdateColors (ColormapPtr pmap)
|
||||
|
||||
pVisual = pmap->pVisual;
|
||||
size = pVisual->ColormapEntries;
|
||||
defs = xalloc(size * sizeof(xColorItem));
|
||||
defs = malloc(size * sizeof(xColorItem));
|
||||
if (!defs)
|
||||
return;
|
||||
n = 0;
|
||||
@@ -793,7 +793,7 @@ UpdateColors (ColormapPtr pmap)
|
||||
}
|
||||
if (n)
|
||||
(*pmap->pScreen->StoreColors)(pmap, n, defs);
|
||||
xfree(defs);
|
||||
free(defs);
|
||||
}
|
||||
|
||||
/* Get a read-only color from a ColorMap (probably slow for large maps)
|
||||
@@ -840,7 +840,7 @@ AllocColor (ColormapPtr pmap,
|
||||
*pgreen = pmap->red[pixR].co.local.green;
|
||||
*pblue = pmap->red[pixR].co.local.blue;
|
||||
npix = pmap->numPixelsRed[client];
|
||||
ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
|
||||
ppix = (Pixel *) realloc(pmap->clientPixelsRed[client],
|
||||
(npix + 1) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
return (BadAlloc);
|
||||
@@ -863,21 +863,21 @@ AllocColor (ColormapPtr pmap,
|
||||
*pgreen = pmap->green[pixG].co.local.green;
|
||||
*pblue = pmap->blue[pixB].co.local.blue;
|
||||
npix = pmap->numPixelsRed[client];
|
||||
ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
|
||||
ppix = (Pixel *) realloc(pmap->clientPixelsRed[client],
|
||||
(npix + 1) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
return (BadAlloc);
|
||||
ppix[npix] = pixR;
|
||||
pmap->clientPixelsRed[client] = ppix;
|
||||
npix = pmap->numPixelsGreen[client];
|
||||
ppix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client],
|
||||
ppix = (Pixel *) realloc(pmap->clientPixelsGreen[client],
|
||||
(npix + 1) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
return (BadAlloc);
|
||||
ppix[npix] = pixG;
|
||||
pmap->clientPixelsGreen[client] = ppix;
|
||||
npix = pmap->numPixelsBlue[client];
|
||||
ppix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client],
|
||||
ppix = (Pixel *) realloc(pmap->clientPixelsBlue[client],
|
||||
(npix + 1) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
return (BadAlloc);
|
||||
@@ -962,7 +962,7 @@ AllocColor (ColormapPtr pmap,
|
||||
{
|
||||
colorResource *pcr;
|
||||
|
||||
pcr = xalloc(sizeof(colorResource));
|
||||
pcr = malloc(sizeof(colorResource));
|
||||
if (!pcr)
|
||||
{
|
||||
(void)FreeColors(pmap, client, 1, pPix, (Pixel)0);
|
||||
@@ -1348,7 +1348,7 @@ gotit:
|
||||
break;
|
||||
}
|
||||
npix = nump[client];
|
||||
ppix = (Pixel *) xrealloc (pixp[client], (npix + 1) * sizeof(Pixel));
|
||||
ppix = (Pixel *) realloc(pixp[client], (npix + 1) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
{
|
||||
pent->refcnt--;
|
||||
@@ -1518,7 +1518,7 @@ FreePixels(ColormapPtr pmap, int client)
|
||||
}
|
||||
}
|
||||
|
||||
xfree(ppixStart);
|
||||
free(ppixStart);
|
||||
pmap->clientPixelsRed[client] = (Pixel *) NULL;
|
||||
pmap->numPixelsRed[client] = 0;
|
||||
if ((class | DynamicClass) == DirectColor)
|
||||
@@ -1527,7 +1527,7 @@ FreePixels(ColormapPtr pmap, int client)
|
||||
if (class & DynamicClass)
|
||||
for (ppix = ppixStart, n = pmap->numPixelsGreen[client]; --n >= 0;)
|
||||
FreeCell(pmap, *ppix++, GREENMAP);
|
||||
xfree(ppixStart);
|
||||
free(ppixStart);
|
||||
pmap->clientPixelsGreen[client] = (Pixel *) NULL;
|
||||
pmap->numPixelsGreen[client] = 0;
|
||||
|
||||
@@ -1535,7 +1535,7 @@ FreePixels(ColormapPtr pmap, int client)
|
||||
if (class & DynamicClass)
|
||||
for (ppix = ppixStart, n = pmap->numPixelsBlue[client]; --n >= 0; )
|
||||
FreeCell(pmap, *ppix++, BLUEMAP);
|
||||
xfree(ppixStart);
|
||||
free(ppixStart);
|
||||
pmap->clientPixelsBlue[client] = (Pixel *) NULL;
|
||||
pmap->numPixelsBlue[client] = 0;
|
||||
}
|
||||
@@ -1558,7 +1558,7 @@ FreeClientPixels (pointer value, XID fakeid)
|
||||
DixRemoveAccess);
|
||||
if (rc == Success)
|
||||
FreePixels((ColormapPtr)pmap, pcr->client);
|
||||
xfree(pcr);
|
||||
free(pcr);
|
||||
return Success;
|
||||
}
|
||||
|
||||
@@ -1580,7 +1580,7 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes,
|
||||
oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
|
||||
if (!oldcount && (CLIENT_ID(pmap->mid) != client))
|
||||
{
|
||||
pcr = xalloc(sizeof(colorResource));
|
||||
pcr = malloc(sizeof(colorResource));
|
||||
if (!pcr)
|
||||
return (BadAlloc);
|
||||
}
|
||||
@@ -1628,7 +1628,7 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes,
|
||||
if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
|
||||
ok = BadAlloc;
|
||||
} else if (pcr)
|
||||
xfree(pcr);
|
||||
free(pcr);
|
||||
|
||||
return (ok);
|
||||
}
|
||||
@@ -1655,7 +1655,7 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors,
|
||||
oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
|
||||
if (!oldcount && (CLIENT_ID(pmap->mid) != client))
|
||||
{
|
||||
pcr = xalloc(sizeof(colorResource));
|
||||
pcr = malloc(sizeof(colorResource));
|
||||
if (!pcr)
|
||||
return (BadAlloc);
|
||||
}
|
||||
@@ -1719,7 +1719,7 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors,
|
||||
if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
|
||||
ok = BadAlloc;
|
||||
} else if (pcr)
|
||||
xfree(pcr);
|
||||
free(pcr);
|
||||
|
||||
return (ok);
|
||||
}
|
||||
@@ -1747,14 +1747,14 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
|
||||
for(p = pixels; p < pixels + c; p++)
|
||||
*p = 0;
|
||||
|
||||
ppixRed = xalloc(npixR * sizeof(Pixel));
|
||||
ppixGreen = xalloc(npixG * sizeof(Pixel));
|
||||
ppixBlue = xalloc(npixB * sizeof(Pixel));
|
||||
ppixRed = malloc(npixR * sizeof(Pixel));
|
||||
ppixGreen = malloc(npixG * sizeof(Pixel));
|
||||
ppixBlue = malloc(npixB * sizeof(Pixel));
|
||||
if (!ppixRed || !ppixGreen || !ppixBlue)
|
||||
{
|
||||
if (ppixBlue) xfree(ppixBlue);
|
||||
if (ppixGreen) xfree(ppixGreen);
|
||||
if (ppixRed) xfree(ppixRed);
|
||||
if (ppixBlue) free(ppixBlue);
|
||||
if (ppixGreen) free(ppixGreen);
|
||||
if (ppixRed) free(ppixRed);
|
||||
return(BadAlloc);
|
||||
}
|
||||
|
||||
@@ -1764,17 +1764,17 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
|
||||
|
||||
if (okR && okG && okB)
|
||||
{
|
||||
rpix = (Pixel *) xrealloc(pmap->clientPixelsRed[client],
|
||||
rpix = (Pixel *) realloc(pmap->clientPixelsRed[client],
|
||||
(pmap->numPixelsRed[client] + (c << r)) *
|
||||
sizeof(Pixel));
|
||||
if (rpix)
|
||||
pmap->clientPixelsRed[client] = rpix;
|
||||
gpix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client],
|
||||
gpix = (Pixel *) realloc(pmap->clientPixelsGreen[client],
|
||||
(pmap->numPixelsGreen[client] + (c << g)) *
|
||||
sizeof(Pixel));
|
||||
if (gpix)
|
||||
pmap->clientPixelsGreen[client] = gpix;
|
||||
bpix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client],
|
||||
bpix = (Pixel *) realloc(pmap->clientPixelsBlue[client],
|
||||
(pmap->numPixelsBlue[client] + (c << b)) *
|
||||
sizeof(Pixel));
|
||||
if (bpix)
|
||||
@@ -1792,9 +1792,9 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
|
||||
if (okB)
|
||||
for(ppix = ppixBlue, npix = npixB; --npix >= 0; ppix++)
|
||||
pmap->blue[*ppix].refcnt = 0;
|
||||
xfree(ppixBlue);
|
||||
xfree(ppixGreen);
|
||||
xfree(ppixRed);
|
||||
free(ppixBlue);
|
||||
free(ppixGreen);
|
||||
free(ppixRed);
|
||||
return(BadAlloc);
|
||||
}
|
||||
|
||||
@@ -1836,9 +1836,9 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
|
||||
for (pDst = pixels; pDst < pixels + c; pDst++)
|
||||
*pDst |= ALPHAMASK(pmap->pVisual);
|
||||
|
||||
xfree(ppixBlue);
|
||||
xfree(ppixGreen);
|
||||
xfree(ppixRed);
|
||||
free(ppixBlue);
|
||||
free(ppixGreen);
|
||||
free(ppixRed);
|
||||
|
||||
return (Success);
|
||||
}
|
||||
@@ -1854,7 +1854,7 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig,
|
||||
npix = c << r;
|
||||
if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
|
||||
return(BadAlloc);
|
||||
if(!(ppixTemp = xalloc(npix * sizeof(Pixel))))
|
||||
if(!(ppixTemp = malloc(npix * sizeof(Pixel))))
|
||||
return(BadAlloc);
|
||||
ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask);
|
||||
|
||||
@@ -1863,7 +1863,7 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig,
|
||||
|
||||
/* all the allocated pixels are added to the client pixel list,
|
||||
* but only the unique ones are returned to the client */
|
||||
ppix = (Pixel *)xrealloc(pmap->clientPixelsRed[client],
|
||||
ppix = (Pixel *)realloc(pmap->clientPixelsRed[client],
|
||||
(pmap->numPixelsRed[client] + npix) * sizeof(Pixel));
|
||||
if (!ppix)
|
||||
{
|
||||
@@ -1884,7 +1884,7 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig,
|
||||
pmap->numPixelsRed[client] += npix;
|
||||
pmap->freeRed -= npix;
|
||||
}
|
||||
xfree(ppixTemp);
|
||||
free(ppixTemp);
|
||||
return (ok ? Success : BadAlloc);
|
||||
}
|
||||
|
||||
@@ -2084,16 +2084,16 @@ AllocShared (ColormapPtr pmap, Pixel *ppix, int c, int r, int g, int b,
|
||||
|
||||
npixClientNew = c << (r + g + b);
|
||||
npixShared = (c << r) + (c << g) + (c << b);
|
||||
psharedList = xalloc(npixShared * sizeof(SHAREDCOLOR *));
|
||||
psharedList = malloc(npixShared * sizeof(SHAREDCOLOR *));
|
||||
if (!psharedList)
|
||||
return FALSE;
|
||||
ppshared = psharedList;
|
||||
for (z = npixShared; --z >= 0; )
|
||||
{
|
||||
if (!(ppshared[z] = xalloc(sizeof(SHAREDCOLOR))))
|
||||
if (!(ppshared[z] = malloc(sizeof(SHAREDCOLOR))))
|
||||
{
|
||||
for (z++ ; z < npixShared; z++)
|
||||
xfree(ppshared[z]);
|
||||
free(ppshared[z]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -2198,7 +2198,7 @@ AllocShared (ColormapPtr pmap, Pixel *ppix, int c, int r, int g, int b,
|
||||
}
|
||||
}
|
||||
}
|
||||
xfree(psharedList);
|
||||
free(psharedList);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -2366,7 +2366,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe
|
||||
npix++;
|
||||
}
|
||||
}
|
||||
pptr = (Pixel *)xrealloc(ppixClient, npixNew * sizeof(Pixel));
|
||||
pptr = (Pixel *)realloc(ppixClient, npixNew * sizeof(Pixel));
|
||||
if (pptr)
|
||||
ppixClient = pptr;
|
||||
npixClient = npixNew;
|
||||
@@ -2374,7 +2374,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe
|
||||
else
|
||||
{
|
||||
npixClient = 0;
|
||||
xfree(ppixClient);
|
||||
free(ppixClient);
|
||||
ppixClient = (Pixel *)NULL;
|
||||
}
|
||||
switch(color)
|
||||
@@ -2673,7 +2673,7 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
|
||||
Colormap *pmaps;
|
||||
int imap, nummaps, found;
|
||||
|
||||
pmaps = xalloc(pWin->drawable.pScreen->maxInstalledCmaps*sizeof(Colormap));
|
||||
pmaps = malloc(pWin->drawable.pScreen->maxInstalledCmaps*sizeof(Colormap));
|
||||
if(!pmaps)
|
||||
return(FALSE);
|
||||
nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
|
||||
@@ -2687,7 +2687,7 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
|
||||
break;
|
||||
}
|
||||
}
|
||||
xfree(pmaps);
|
||||
free(pmaps);
|
||||
return (found);
|
||||
}
|
||||
|
||||
@@ -2727,7 +2727,7 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count,
|
||||
first_new_vid = depth->numVids;
|
||||
first_new_visual = pScreen->numVisuals;
|
||||
|
||||
vids = xrealloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID));
|
||||
vids = realloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID));
|
||||
if (!vids)
|
||||
return FALSE;
|
||||
|
||||
@@ -2735,7 +2735,7 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count,
|
||||
depth->vids = vids;
|
||||
|
||||
numVisuals = pScreen->numVisuals + new_visual_count;
|
||||
visuals = xrealloc(pScreen->visuals, numVisuals * sizeof(VisualRec));
|
||||
visuals = realloc(pScreen->visuals, numVisuals * sizeof(VisualRec));
|
||||
if (!visuals) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user