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:
Mikhail Gusarov
2010-05-06 01:44:06 +07:00
parent 96c7ab27c3
commit 3f3ff971ec
345 changed files with 3011 additions and 3011 deletions

View File

@@ -207,7 +207,7 @@ KdDoSwitchCmd (char *reason)
{
if (kdSwitchCmd)
{
char *command = xalloc (strlen (kdSwitchCmd) +
char *command = malloc(strlen (kdSwitchCmd) +
1 +
strlen (reason) +
1);
@@ -217,7 +217,7 @@ KdDoSwitchCmd (char *reason)
strcat (command, " ");
strcat (command, reason);
system (command);
xfree (command);
free(command);
}
}
@@ -699,7 +699,7 @@ KdAllocatePrivates (ScreenPtr pScreen)
if (kdGeneration != serverGeneration)
kdGeneration = serverGeneration;
pScreenPriv = xcalloc(1, sizeof (*pScreenPriv));
pScreenPriv = calloc(1, sizeof (*pScreenPriv));
if (!pScreenPriv)
return FALSE;
KdSetScreenPriv (pScreen, pScreenPriv);
@@ -788,7 +788,7 @@ KdCloseScreen (int index, ScreenPtr pScreen)
pScreenPriv->screen->pScreen = 0;
xfree ((pointer) pScreenPriv);
free((pointer) pScreenPriv);
return ret;
}

View File

@@ -33,7 +33,7 @@ KdCardInfoAdd (KdCardFuncs *funcs,
{
KdCardInfo *ci, **prev;
ci = xcalloc (1, sizeof (KdCardInfo));
ci = calloc(1, sizeof (KdCardInfo));
if (!ci)
return 0;
for (prev = &kdCardInfo; *prev; prev = &(*prev)->next);
@@ -66,7 +66,7 @@ KdCardInfoDispose (KdCardInfo *ci)
if (*prev == ci)
{
*prev = ci->next;
xfree (ci);
free(ci);
break;
}
}
@@ -77,7 +77,7 @@ KdScreenInfoAdd (KdCardInfo *ci)
KdScreenInfo *si, **prev;
int n;
si = xcalloc (1, sizeof (KdScreenInfo));
si = calloc(1, sizeof (KdScreenInfo));
if (!si)
return 0;
for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++);
@@ -98,7 +98,7 @@ KdScreenInfoDispose (KdScreenInfo *si)
if (*prev == si)
{
*prev = si->next;
xfree (si);
free(si);
if (!ci->screenList)
KdCardInfoDispose (ci);
break;
@@ -112,7 +112,7 @@ KdNewPointer (void)
KdPointerInfo *pi;
int i;
pi = (KdPointerInfo *)xcalloc(1, sizeof(KdPointerInfo));
pi = (KdPointerInfo *)calloc(1, sizeof(KdPointerInfo));
if (!pi)
return NULL;
@@ -136,28 +136,28 @@ KdFreePointer(KdPointerInfo *pi)
{
InputOption *option, *prev = NULL;
xfree(pi->name);
xfree(pi->path);
free(pi->name);
free(pi->path);
for (option = pi->options; option; option = option->next) {
xfree(prev);
xfree(option->key);
xfree(option->value);
free(prev);
free(option->key);
free(option->value);
prev = option;
}
xfree(prev);
xfree(pi);
free(prev);
free(pi);
}
void
KdFreeKeyboard(KdKeyboardInfo *ki)
{
xfree(ki->name);
xfree(ki->path);
xfree(ki->xkbRules);
xfree(ki->xkbModel);
xfree(ki->xkbLayout);
free(ki->name);
free(ki->path);
free(ki->xkbRules);
free(ki->xkbModel);
free(ki->xkbLayout);
ki->next = NULL;
xfree(ki);
free(ki);
}

View File

@@ -420,7 +420,7 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
"(unnamed)");
return !Success;
}
xfree(pi->driverPrivate);
free(pi->driverPrivate);
pi->driverPrivate = NULL;
}
@@ -433,12 +433,12 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
return !Success;
}
btn_labels = xcalloc(pi->nButtons, sizeof(Atom));
btn_labels = calloc(pi->nButtons, sizeof(Atom));
if (!btn_labels)
return BadAlloc;
axes_labels = xcalloc(pi->nAxes, sizeof(Atom));
axes_labels = calloc(pi->nAxes, sizeof(Atom));
if (!axes_labels) {
xfree(btn_labels);
free(btn_labels);
return BadAlloc;
}
@@ -472,8 +472,8 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
(PtrCtrlProcPtr)NoopDDA,
GetMotionHistorySize(), pi->nAxes, axes_labels);
xfree(btn_labels);
xfree(axes_labels);
free(btn_labels);
free(axes_labels);
if (pi->inputClass == KD_TOUCHSCREEN) {
InitAbsoluteClassDeviceStruct(pDevice);
@@ -736,7 +736,7 @@ KdKeyboardProc(DeviceIntPtr pDevice, int onoff)
"(unnamed)");
return !Success;
}
xfree(ki->driverPrivate);
free(ki->driverPrivate);
ki->driverPrivate = NULL;
}
@@ -887,7 +887,7 @@ KdRemoveKeyboardDriver (KdKeyboardDriver *driver)
KdKeyboardInfo *
KdNewKeyboard (void)
{
KdKeyboardInfo *ki = xcalloc(sizeof(KdKeyboardInfo), 1);
KdKeyboardInfo *ki = calloc(sizeof(KdKeyboardInfo), 1);
if (!ki)
return NULL;
@@ -915,7 +915,7 @@ KdAddConfigKeyboard (char *keyboard)
if (!keyboard)
return Success;
new = (struct KdConfigDevice *) xcalloc(sizeof(struct KdConfigDevice), 1);
new = (struct KdConfigDevice *) calloc(sizeof(struct KdConfigDevice), 1);
if (!new)
return BadAlloc;
@@ -983,7 +983,7 @@ KdAddConfigPointer (char *pointer)
if (!pointer)
return Success;
new = (struct KdConfigDevice *) xcalloc(sizeof(struct KdConfigDevice), 1);
new = (struct KdConfigDevice *) calloc(sizeof(struct KdConfigDevice), 1);
if (!new)
return BadAlloc;
@@ -1053,7 +1053,7 @@ KdGetOptions (InputOption **options, char *string)
InputOption *newopt = NULL, **tmpo = NULL;
int tam_key = 0;
newopt = xcalloc(1, sizeof (InputOption));
newopt = calloc(1, sizeof (InputOption));
if (!newopt)
return FALSE;
@@ -1064,7 +1064,7 @@ KdGetOptions (InputOption **options, char *string)
if (strchr(string, '='))
{
tam_key = (strchr(string, '=') - string);
newopt->key = (char *)xalloc(tam_key);
newopt->key = (char *)malloc(tam_key);
strncpy(newopt->key, string, tam_key);
newopt->key[tam_key] = '\0';
newopt->value = xstrdup(strchr(string, '=') + 1);

View File

@@ -36,11 +36,11 @@ KdShadowFbAlloc (KdScreenInfo *screen, Bool rotate)
/* use fb computation for width */
paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits);
buf = xalloc (paddedWidth * height);
buf = malloc(paddedWidth * height);
if (!buf)
return FALSE;
if (screen->fb.shadow)
xfree (screen->fb.frameBuffer);
free(screen->fb.frameBuffer);
screen->fb.shadow = TRUE;
screen->fb.frameBuffer = buf;
screen->fb.byteStride = paddedWidth;
@@ -53,7 +53,7 @@ KdShadowFbFree (KdScreenInfo *screen)
{
if (screen->fb.shadow)
{
xfree (screen->fb.frameBuffer);
free(screen->fb.frameBuffer);
screen->fb.frameBuffer = 0;
screen->fb.shadow = FALSE;
}

View File

@@ -134,7 +134,7 @@ KdXVRegisterGenericAdaptorDriver(
/* fprintf(stderr,"KdXVRegisterGenericAdaptorDriver\n"); */
newdrivers = xrealloc(GenDrivers, sizeof(KdXVInitGenericAdaptorPtr) *
newdrivers = realloc(GenDrivers, sizeof(KdXVInitGenericAdaptorPtr) *
(1 + NumGenDrivers));
if (!newdrivers)
return 0;
@@ -159,7 +159,7 @@ KdXVListGenericAdaptors(
n = GenDrivers[i](screen,&DrivAdap);
if (0 == n)
continue;
new = xrealloc(*adaptors, sizeof(KdVideoAdaptorPtr) * (num+n));
new = realloc(*adaptors, sizeof(KdVideoAdaptorPtr) * (num+n));
if (NULL == new)
continue;
*adaptors = new;
@@ -172,13 +172,13 @@ KdXVListGenericAdaptors(
KdVideoAdaptorPtr
KdXVAllocateVideoAdaptorRec(KdScreenInfo * screen)
{
return xcalloc(1, sizeof(KdVideoAdaptorRec));
return calloc(1, sizeof(KdVideoAdaptorRec));
}
void
KdXVFreeVideoAdaptorRec(KdVideoAdaptorPtr ptr)
{
xfree(ptr);
free(ptr);
}
@@ -218,7 +218,7 @@ KdXVScreenInit(
a CloseScreen hook so that we don't have to wrap it. I'm not
sure that I appreciate that. */
ScreenPriv = xalloc(sizeof(KdXVScreenRec));
ScreenPriv = malloc(sizeof(KdXVScreenRec));
pxvs->devPriv.ptr = (pointer)ScreenPriv;
if(!ScreenPriv) return FALSE;
@@ -247,18 +247,18 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
{
int i;
xfree(pAdaptor->name);
free(pAdaptor->name);
if(pAdaptor->pEncodings) {
XvEncodingPtr pEncode = pAdaptor->pEncodings;
for(i = 0; i < pAdaptor->nEncodings; i++, pEncode++) {
xfree(pEncode->name);
free(pEncode->name);
}
xfree(pAdaptor->pEncodings);
free(pAdaptor->pEncodings);
}
xfree(pAdaptor->pFormats);
free(pAdaptor->pFormats);
if(pAdaptor->pPorts) {
XvPortPtr pPort = pAdaptor->pPorts;
@@ -271,25 +271,25 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
REGION_DESTROY(pAdaptor->pScreen, pPriv->clientClip);
if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
REGION_DESTROY(pAdaptor->pScreen, pPriv->pCompositeClip);
xfree(pPriv);
free(pPriv);
}
}
xfree(pAdaptor->pPorts);
free(pAdaptor->pPorts);
}
if(pAdaptor->nAttributes) {
XvAttributePtr pAttribute = pAdaptor->pAttributes;
for(i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) {
xfree(pAttribute->name);
free(pAttribute->name);
}
xfree(pAdaptor->pAttributes);
free(pAdaptor->pAttributes);
}
xfree(pAdaptor->pImages);
free(pAdaptor->pImages);
xfree(pAdaptor->devPriv.ptr);
free(pAdaptor->devPriv.ptr);
}
static Bool
@@ -325,7 +325,7 @@ KdXVInitAdaptors(
pxvs->nAdaptors = 0;
pxvs->pAdaptors = NULL;
if(!(pAdaptor = xcalloc(number, sizeof(XvAdaptorRec))))
if(!(pAdaptor = calloc(number, sizeof(XvAdaptorRec))))
return FALSE;
for(pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) {
@@ -375,18 +375,18 @@ KdXVInitAdaptors(
pa->ddGetPortAttribute = KdXVGetPortAttribute;
pa->ddQueryBestSize = KdXVQueryBestSize;
pa->ddQueryImageAttributes = KdXVQueryImageAttributes;
if((pa->name = xalloc(strlen(adaptorPtr->name) + 1)))
if((pa->name = malloc(strlen(adaptorPtr->name) + 1)))
strcpy(pa->name, adaptorPtr->name);
if(adaptorPtr->nEncodings &&
(pEncode = xcalloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
(pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
for(pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0;
i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++)
{
pe->id = encodingPtr->id;
pe->pScreen = pScreen;
if((pe->name = xalloc(strlen(encodingPtr->name) + 1)))
if((pe->name = malloc(strlen(encodingPtr->name) + 1)))
strcpy(pe->name, encodingPtr->name);
pe->width = encodingPtr->width;
pe->height = encodingPtr->height;
@@ -398,7 +398,7 @@ KdXVInitAdaptors(
}
if(adaptorPtr->nImages &&
(pImage = xcalloc(adaptorPtr->nImages, sizeof(XvImageRec)))) {
(pImage = calloc(adaptorPtr->nImages, sizeof(XvImageRec)))) {
for(i = 0, pi = pImage, imagePtr = adaptorPtr->pImages;
i < adaptorPtr->nImages; i++, pi++, imagePtr++)
@@ -431,7 +431,7 @@ KdXVInitAdaptors(
}
if(adaptorPtr->nAttributes &&
(pAttribute = xcalloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec))))
(pAttribute = calloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec))))
{
for(pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = 0;
i < adaptorPtr->nAttributes; pat++, i++, attributePtr++)
@@ -439,7 +439,7 @@ KdXVInitAdaptors(
pat->flags = attributePtr->flags;
pat->min_value = attributePtr->min_value;
pat->max_value = attributePtr->max_value;
if((pat->name = xalloc(strlen(attributePtr->name) + 1)))
if((pat->name = malloc(strlen(attributePtr->name) + 1)))
strcpy(pat->name, attributePtr->name);
}
pa->nAttributes = adaptorPtr->nAttributes;
@@ -449,7 +449,7 @@ KdXVInitAdaptors(
totFormat = adaptorPtr->nFormats;
if(!(pFormat = xcalloc(totFormat, sizeof(XvFormatRec)))) {
if(!(pFormat = calloc(totFormat, sizeof(XvFormatRec)))) {
KdXVFreeAdaptor(pa);
continue;
}
@@ -466,7 +466,7 @@ KdXVInitAdaptors(
if(numFormat >= totFormat) {
void *moreSpace;
totFormat *= 2;
moreSpace = xrealloc(pFormat,
moreSpace = realloc(pFormat,
totFormat * sizeof(XvFormatRec));
if(!moreSpace) break;
pFormat = moreSpace;
@@ -489,7 +489,7 @@ KdXVInitAdaptors(
continue;
}
if(!(adaptorPriv = xcalloc(1, sizeof(XvAdaptorRecPrivate)))) {
if(!(adaptorPriv = calloc(1, sizeof(XvAdaptorRecPrivate)))) {
KdXVFreeAdaptor(pa);
continue;
}
@@ -509,7 +509,7 @@ KdXVInitAdaptors(
pa->devPriv.ptr = (pointer)adaptorPriv;
if(!(pPort = xcalloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) {
if(!(pPort = calloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) {
KdXVFreeAdaptor(pa);
continue;
}
@@ -519,11 +519,11 @@ KdXVInitAdaptors(
if(!(pp->id = FakeClientID(0)))
continue;
if(!(portPriv = xcalloc(1, sizeof(XvPortRecPrivate))))
if(!(portPriv = calloc(1, sizeof(XvPortRecPrivate))))
continue;
if(!AddResource(pp->id, PortResource, pp)) {
xfree(portPriv);
free(portPriv);
continue;
}
@@ -559,7 +559,7 @@ KdXVInitAdaptors(
pxvs->nAdaptors = numAdaptor;
pxvs->pAdaptors = pAdaptor;
} else {
xfree(pAdaptor);
free(pAdaptor);
return FALSE;
}
@@ -925,7 +925,7 @@ KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
}
if(!winPriv) {
winPriv = xalloc(sizeof(KdXVWindowRec));
winPriv = malloc(sizeof(KdXVWindowRec));
if(!winPriv) return BadAlloc;
winPriv->PortRec = portPriv;
winPriv->next = PrivRoot;
@@ -948,7 +948,7 @@ KdXVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
prevPriv->next = winPriv->next;
else
dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next);
xfree(winPriv);
free(winPriv);
break;
}
prevPriv = winPriv;
@@ -998,7 +998,7 @@ KdXVDestroyWindow(WindowPtr pWin)
pPriv->pDraw = NULL;
tmp = WinPriv;
WinPriv = WinPriv->next;
xfree(tmp);
free(tmp);
}
dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, NULL);
@@ -1063,7 +1063,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
pPrev->next = WinPriv->next;
tmp = WinPriv;
WinPriv = WinPriv->next;
xfree(tmp);
free(tmp);
continue;
}
break;
@@ -1112,7 +1112,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
pPrev->next = WinPriv->next;
tmp = WinPriv;
WinPriv = WinPriv->next;
xfree(tmp);
free(tmp);
continue;
}
}
@@ -1153,8 +1153,8 @@ KdXVCloseScreen(int i, ScreenPtr pScreen)
KdXVFreeAdaptor(pa);
}
xfree(pxvs->pAdaptors);
xfree(ScreenPriv);
free(pxvs->pAdaptors);
free(ScreenPriv);
return TRUE;
}
@@ -1872,7 +1872,7 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
BoxPtr pBox = REGION_RECTS (pRgn);
int nBox = REGION_NUM_RECTS (pRgn);
rects = xalloc (nBox * sizeof (xRectangle));
rects = malloc(nBox * sizeof (xRectangle));
if (!rects)
goto bail0;
r = rects;
@@ -1901,7 +1901,7 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
FreeScratchGC (pGC);
bail1:
xfree (rects);
free(rects);
bail0:
;
}