Remove the Must_have_memory hack.

Also remove an astonishing amount of misunderstanding of how casts work.
This commit is contained in:
Adam Jackson 2008-10-03 16:05:19 -04:00
parent e6b1c1fada
commit 0ce61e21d6
6 changed files with 38 additions and 84 deletions

View File

@ -2640,11 +2640,8 @@ XYToWindow(DeviceIntPtr pDev, int x, int y)
if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize)
{ {
pSprite->spriteTraceSize += 10; pSprite->spriteTraceSize += 10;
Must_have_memory = TRUE; /* XXX */ pSprite->spriteTrace = xrealloc(pSprite->spriteTrace,
pSprite->spriteTrace = (WindowPtr *)xrealloc(
pSprite->spriteTrace,
pSprite->spriteTraceSize*sizeof(WindowPtr)); pSprite->spriteTraceSize*sizeof(WindowPtr));
Must_have_memory = FALSE; /* XXX */
} }
pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin; pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin;
pWin = pWin->firstChild; pWin = pWin->firstChild;
@ -3462,11 +3459,8 @@ CheckPassiveGrabsOnWindow(
{ {
if (grabinfo->sync.evcount < scount) if (grabinfo->sync.evcount < scount)
{ {
Must_have_memory = TRUE; /* XXX */ grabinfo->sync.event = xrealloc(grabinfo->sync.event,
grabinfo->sync.event = (xEvent *)xrealloc(grabinfo->sync.event, scount * sizeof(xEvent));
scount*
sizeof(xEvent));
Must_have_memory = FALSE; /* XXX */
} }
grabinfo->sync.evcount = scount; grabinfo->sync.evcount = scount;
/* we always store the XI event, never the core event */ /* we always store the XI event, never the core event */
@ -3792,10 +3786,8 @@ DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev,
FreezeThaw(thisDev, TRUE); FreezeThaw(thisDev, TRUE);
if (grabinfo->sync.evcount < count) if (grabinfo->sync.evcount < count)
{ {
Must_have_memory = TRUE; /* XXX */ grabinfo->sync.event = xrealloc(grabinfo->sync.event,
grabinfo->sync.event = (xEvent *)xrealloc(grabinfo->sync.event,
count * sizeof(xEvent)); count * sizeof(xEvent));
Must_have_memory = FALSE; /* XXX */
} }
grabinfo->sync.evcount = count; grabinfo->sync.evcount = count;
for (dxE = grabinfo->sync.event; --count >= 0; dxE++, xE++) for (dxE = grabinfo->sync.event; --count >= 0; dxE++, xE++)
@ -4953,11 +4945,8 @@ SetInputFocus(
if (depth > focus->traceSize) if (depth > focus->traceSize)
{ {
focus->traceSize = depth+1; focus->traceSize = depth+1;
Must_have_memory = TRUE; /* XXX */ focus->trace = xrealloc(focus->trace,
focus->trace = (WindowPtr *)xrealloc(focus->trace, focus->traceSize * sizeof(WindowPtr));
focus->traceSize *
sizeof(WindowPtr));
Must_have_memory = FALSE; /* XXX */
} }
focus->traceGood = depth; focus->traceGood = depth;
for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--) for (pWin = focusWin, depth--; pWin; pWin = pWin->parent, depth--)

View File

@ -333,7 +333,6 @@ _X_HIDDEN void *dixLookupTab[] = {
/* utils.c */ /* utils.c */
SYMFUNC(Xstrdup) SYMFUNC(Xstrdup)
SYMFUNC(XNFstrdup) SYMFUNC(XNFstrdup)
SYMVAR(Must_have_memory)
SYMFUNC(AdjustWaitForDelay) SYMFUNC(AdjustWaitForDelay)
SYMVAR(noTestExtensions) SYMVAR(noTestExtensions)
SYMFUNC(GiveUp) SYMFUNC(GiveUp)

View File

@ -19,7 +19,6 @@ extern char *defaultFontPath;
extern int monitorResolution; extern int monitorResolution;
extern int defaultColorVisualClass; extern int defaultColorVisualClass;
extern Bool Must_have_memory;
extern WindowPtr WindowTable[MAXSCREENS]; extern WindowPtr WindowTable[MAXSCREENS];
extern int GrabInProgress; extern int GrabInProgress;
extern Bool noTestExtensions; extern Bool noTestExtensions;

View File

@ -54,8 +54,6 @@ SOFTWARE.
#include "mi.h" #include "mi.h"
#include "inputstr.h" #include "inputstr.h"
extern Bool Must_have_memory;
_X_EXPORT void _X_EXPORT void
miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr, miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr,
CursorPtr pCurs, Bool displayed) CursorPtr pCurs, Bool displayed)
@ -64,11 +62,8 @@ miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr,
* This is guaranteed to correct any color-dependent state which may have * This is guaranteed to correct any color-dependent state which may have
* been bound up in private state created by RealizeCursor * been bound up in private state created by RealizeCursor
*/ */
(* pScr->UnrealizeCursor)( pDev, pScr, pCurs); pScr->UnrealizeCursor(pDev, pScr, pCurs);
Must_have_memory = TRUE; /* XXX */ pScr->RealizeCursor(pDev, pScr, pCurs);
(* pScr->RealizeCursor)( pDev, pScr, pCurs);
Must_have_memory = FALSE; /* XXX */
if (displayed) if (displayed)
(* pScr->DisplayCursor)( pDev, pScr, pCurs); pScr->DisplayCursor(pDev, pScr, pCurs);
} }

View File

@ -63,11 +63,9 @@ miCreateGCOps(GCOpsPtr prototype)
{ {
GCOpsPtr ret; GCOpsPtr ret;
/* XXX */ Must_have_memory = TRUE; ret = xalloc(sizeof(GCOps));
ret = (GCOpsPtr) xalloc(sizeof(GCOps));
/* XXX */ Must_have_memory = FALSE;
if (!ret) if (!ret)
return 0; return NULL;
*ret = *prototype; *ret = *prototype;
ret->devPrivate.val = 1; ret->devPrivate.val = 1;
return ret; return ret;

View File

@ -212,9 +212,6 @@ Bool PanoramiXExtensionDisabledHack = FALSE;
int auditTrailLevel = 1; int auditTrailLevel = 1;
_X_EXPORT Bool Must_have_memory = FALSE;
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
#define HAS_SAVED_IDS_AND_SETEUID #define HAS_SAVED_IDS_AND_SETEUID
#endif #endif
@ -1056,60 +1053,40 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client)
#endif /* TCPCONN */ #endif /* TCPCONN */
} }
/* XALLOC -- X's internal memory allocator. Why does it return unsigned
* long * instead of the more common char *? Well, if you read K&R you'll
* see they say that alloc must return a pointer "suitable for conversion"
* to whatever type you really want. In a full-blown generic allocator
* there's no way to solve the alignment problems without potentially
* wasting lots of space. But we have a more limited problem. We know
* we're only ever returning pointers to structures which will have to
* be long word aligned. So we are making a stronger guarantee. It might
* have made sense to make Xalloc return char * to conform with people's
* expectations of malloc, but this makes lint happier.
*/
#ifndef INTERNAL_MALLOC #ifndef INTERNAL_MALLOC
_X_EXPORT void * _X_EXPORT void *
Xalloc(unsigned long amount) Xalloc(unsigned long amount)
{ {
register pointer ptr; void *ptr;
if ((long)amount <= 0) { if ((long)amount <= 0) {
return (unsigned long *)NULL; return NULL;
} }
/* aligned extra on long word boundary */ /* aligned extra on long word boundary */
amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
if ((ptr = (pointer)malloc(amount))) { ptr = malloc(amount);
return (unsigned long *)ptr; return ptr;
}
if (Must_have_memory)
FatalError("Out of memory");
return (unsigned long *)NULL;
} }
/***************** /*****************
* XNFalloc * XNFalloc
* "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory * "no failure" realloc
*****************/ *****************/
_X_EXPORT void * _X_EXPORT void *
XNFalloc(unsigned long amount) XNFalloc(unsigned long amount)
{ {
register pointer ptr; void *ptr;
if ((long)amount <= 0) if ((long)amount <= 0)
{ return NULL;
return (unsigned long *)NULL;
}
/* aligned extra on long word boundary */ /* aligned extra on long word boundary */
amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
ptr = (pointer)malloc(amount); ptr = malloc(amount);
if (!ptr) if (!ptr)
{
FatalError("Out of memory"); FatalError("Out of memory");
} return ptr;
return ((unsigned long *)ptr);
} }
/***************** /*****************
@ -1119,11 +1096,11 @@ XNFalloc(unsigned long amount)
_X_EXPORT void * _X_EXPORT void *
Xcalloc(unsigned long amount) Xcalloc(unsigned long amount)
{ {
unsigned long *ret; void *ret;
ret = Xalloc (amount); ret = Xalloc (amount);
if (ret) if (ret)
bzero ((char *) ret, (int) amount); bzero (ret, (int) amount);
return ret; return ret;
} }
@ -1134,11 +1111,11 @@ Xcalloc(unsigned long amount)
_X_EXPORT void * _X_EXPORT void *
XNFcalloc(unsigned long amount) XNFcalloc(unsigned long amount)
{ {
unsigned long *ret; void *ret;
ret = Xalloc (amount); ret = Xalloc (amount);
if (ret) if (ret)
bzero ((char *) ret, (int) amount); bzero (ret, (int) amount);
else if ((long)amount > 0) else if ((long)amount > 0)
FatalError("Out of memory"); FatalError("Out of memory");
return ret; return ret;
@ -1155,34 +1132,31 @@ Xrealloc(pointer ptr, unsigned long amount)
{ {
if (ptr && !amount) if (ptr && !amount)
free(ptr); free(ptr);
return (unsigned long *)NULL; return NULL;
} }
amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1); amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
if (ptr) if (ptr)
ptr = (pointer)realloc((char *)ptr, amount); ptr = realloc(ptr, amount);
else else
ptr = (pointer)malloc(amount); ptr = malloc(amount);
if (ptr)
return (unsigned long *)ptr; return ptr;
if (Must_have_memory)
FatalError("Out of memory");
return (unsigned long *)NULL;
} }
/***************** /*****************
* XNFrealloc * XNFrealloc
* "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory * "no failure" realloc
*****************/ *****************/
_X_EXPORT void * _X_EXPORT void *
XNFrealloc(pointer ptr, unsigned long amount) XNFrealloc(pointer ptr, unsigned long amount)
{ {
if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL) if ((ptr = Xrealloc(ptr, amount)) == NULL)
{ {
if ((long)amount > 0) if ((long)amount > 0)
FatalError( "Out of memory" ); FatalError( "Out of memory" );
} }
return ((unsigned long *)ptr); return ptr;
} }
/***************** /*****************
@ -1194,7 +1168,7 @@ _X_EXPORT void
Xfree(pointer ptr) Xfree(pointer ptr)
{ {
if (ptr) if (ptr)
free((char *)ptr); free(ptr);
} }
#endif /* !INTERNAL_MALLOC */ #endif /* !INTERNAL_MALLOC */
@ -1207,7 +1181,7 @@ Xstrdup(const char *s)
if (s == NULL) if (s == NULL)
return NULL; return NULL;
sd = (char *)Xalloc(strlen(s) + 1); sd = Xalloc(strlen(s) + 1);
if (sd != NULL) if (sd != NULL)
strcpy(sd, s); strcpy(sd, s);
return sd; return sd;
@ -1222,7 +1196,7 @@ XNFstrdup(const char *s)
if (s == NULL) if (s == NULL)
return NULL; return NULL;
sd = (char *)XNFalloc(strlen(s) + 1); sd = XNFalloc(strlen(s) + 1);
strcpy(sd, s); strcpy(sd, s);
return sd; return sd;
} }