Merge remote branch 'dottedmag/for-keithp'

This commit is contained in:
Keith Packard 2010-05-12 16:48:08 -07:00
commit 59857ee5da
7 changed files with 40 additions and 35 deletions

View File

@ -68,7 +68,7 @@ typedef struct _Node {
} NodeRec, *NodePtr; } NodeRec, *NodePtr;
static Atom lastAtom = None; static Atom lastAtom = None;
static NodePtr atomRoot = (NodePtr)NULL; static NodePtr atomRoot = NULL;
static unsigned long tableLength; static unsigned long tableLength;
static NodePtr *nodeTable; static NodePtr *nodeTable;
@ -88,7 +88,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit)
fp = fp * 27 + string[i]; fp = fp * 27 + string[i];
fp = fp * 27 + string[len - 1 - i]; fp = fp * 27 + string[len - 1 - i];
} }
while (*np != (NodePtr) NULL) while (*np != NULL)
{ {
if (fp < (*np)->fingerPrint) if (fp < (*np)->fingerPrint)
np = &((*np)->left); np = &((*np)->left);
@ -130,11 +130,12 @@ MakeAtom(const char *string, unsigned len, Bool makeit)
if ((lastAtom + 1) >= tableLength) { if ((lastAtom + 1) >= tableLength) {
NodePtr *table; NodePtr *table;
table = (NodePtr *) realloc(nodeTable, table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr)));
tableLength * (2 * sizeof(NodePtr)));
if (!table) { if (!table) {
if (nd->string != string) if (nd->string != string) {
free(nd->string); /* nd->string has been strdup'ed */
free((char *)nd->string);
}
free(nd); free(nd);
return BAD_RESOURCE; return BAD_RESOURCE;
} }
@ -142,10 +143,10 @@ MakeAtom(const char *string, unsigned len, Bool makeit)
nodeTable = table; nodeTable = table;
} }
*np = nd; *np = nd;
nd->left = nd->right = (NodePtr) NULL; nd->left = nd->right = NULL;
nd->fingerPrint = fp; nd->fingerPrint = fp;
nd->a = (++lastAtom); nd->a = ++lastAtom;
*(nodeTable+lastAtom) = nd; nodeTable[lastAtom] = nd;
return nd->a; return nd->a;
} }
else else
@ -163,7 +164,7 @@ NameForAtom(Atom atom)
{ {
NodePtr node; NodePtr node;
if (atom > lastAtom) return 0; if (atom > lastAtom) return 0;
if ((node = nodeTable[atom]) == (NodePtr)NULL) return 0; if ((node = nodeTable[atom]) == NULL) return 0;
return node->string; return node->string;
} }
@ -180,20 +181,25 @@ FreeAtom(NodePtr patom)
FreeAtom(patom->left); FreeAtom(patom->left);
if(patom->right) if(patom->right)
FreeAtom(patom->right); FreeAtom(patom->right);
if (patom->a > XA_LAST_PREDEFINED) if (patom->a > XA_LAST_PREDEFINED) {
free(patom->string); /*
* All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to
* cast here
*/
free((char *)patom->string);
}
free(patom); free(patom);
} }
void void
FreeAllAtoms(void) FreeAllAtoms(void)
{ {
if(atomRoot == (NodePtr)NULL) if (atomRoot == NULL)
return; return;
FreeAtom(atomRoot); FreeAtom(atomRoot);
atomRoot = (NodePtr)NULL; atomRoot = NULL;
free(nodeTable); free(nodeTable);
nodeTable = (NodePtr *)NULL; nodeTable = NULL;
lastAtom = None; lastAtom = None;
} }
@ -202,11 +208,11 @@ InitAtoms(void)
{ {
FreeAllAtoms(); FreeAllAtoms();
tableLength = InitialTableSize; tableLength = InitialTableSize;
nodeTable = malloc(InitialTableSize*sizeof(NodePtr)); nodeTable = malloc(InitialTableSize * sizeof(NodePtr));
if (!nodeTable) if (!nodeTable)
AtomError(); AtomError();
nodeTable[None] = (NodePtr)NULL; nodeTable[None] = NULL;
MakePredeclaredAtoms(); MakePredeclaredAtoms();
if (lastAtom != XA_LAST_PREDEFINED) if (lastAtom != XA_LAST_PREDEFINED)
AtomError (); AtomError();
} }

View File

@ -106,6 +106,12 @@ typedef unsigned long ATOM;
#define X_DEPRECATED #define X_DEPRECATED
#endif #endif
#if defined(__GNUC__) && (__GNUC__ > 2)
#define X_NORETURN __attribute__((noreturn))
#else
#define X_NORETURN
#endif
#ifndef _XTYPEDEF_CALLBACKLISTPTR #ifndef _XTYPEDEF_CALLBACKLISTPTR
typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
#define _XTYPEDEF_CALLBACKLISTPTR #define _XTYPEDEF_CALLBACKLISTPTR

View File

@ -299,7 +299,7 @@ extern _X_EXPORT void OsBlockSignals (void);
extern _X_EXPORT void OsReleaseSignals (void); extern _X_EXPORT void OsReleaseSignals (void);
extern _X_EXPORT void OsAbort (void); extern _X_EXPORT void OsAbort (void) X_NORETURN;
#if !defined(WIN32) #if !defined(WIN32)
extern _X_EXPORT int System(char *); extern _X_EXPORT int System(char *);
@ -547,10 +547,7 @@ extern _X_EXPORT void FreeAuditTimer(void);
extern _X_EXPORT void AuditF(const char *f, ...) _printf_attribute(1,2); extern _X_EXPORT void AuditF(const char *f, ...) _printf_attribute(1,2);
extern _X_EXPORT void VAuditF(const char *f, va_list args); extern _X_EXPORT void VAuditF(const char *f, va_list args);
extern _X_EXPORT void FatalError(const char *f, ...) _printf_attribute(1,2) extern _X_EXPORT void FatalError(const char *f, ...) _printf_attribute(1,2)
#if defined(__GNUC__) && (__GNUC__ > 2) X_NORETURN;
__attribute((noreturn))
#endif
;
#ifdef DEBUG #ifdef DEBUG
#define DebugF ErrorF #define DebugF ErrorF

View File

@ -73,7 +73,7 @@ miPolyPoint(
int i; int i;
xPoint *ppt; xPoint *ppt;
if(!(pwidthInit = xalloc(npt * sizeof(int)))) if(!(pwidthInit = malloc(npt * sizeof(int))))
return; return;
/* make pointlist origin relative */ /* make pointlist origin relative */

View File

@ -402,9 +402,8 @@ LogMessage(MessageType type, const char *format, ...)
va_end(ap); va_end(ap);
} }
#ifdef __GNUC__ void
void AbortServer(void) __attribute__((noreturn)); AbortServer(void) X_NORETURN;
#endif
void void
AbortServer(void) AbortServer(void)

View File

@ -161,7 +161,6 @@ void
OsInit(void) OsInit(void)
{ {
static Bool been_here = FALSE; static Bool been_here = FALSE;
static char* admpath = ADMPATH;
static char* devnull = "/dev/null"; static char* devnull = "/dev/null";
char fname[PATH_MAX]; char fname[PATH_MAX];
@ -229,8 +228,8 @@ OsInit(void)
{ {
FILE *err; FILE *err;
if (strlen (display) + strlen (admpath) + 1 < sizeof fname) if (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname)
sprintf (fname, admpath, display); sprintf (fname, ADMPATH, display);
else else
strcpy (fname, devnull); strcpy (fname, devnull);
/* /*

View File

@ -186,7 +186,7 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX]; char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX];
const char *emptystring = ""; const char *emptystring = "";
const char *xkbbasedirflag = emptystring; char *xkbbasedirflag = NULL;
const char *xkbbindir = emptystring; const char *xkbbindir = emptystring;
const char *xkbbindirsep = emptystring; const char *xkbbindirsep = emptystring;
@ -230,13 +230,11 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
xkbbindir, xkbbindirsep, xkbbindir, xkbbindirsep,
( (xkbDebugFlags < 2) ? 1 : ( (xkbDebugFlags < 2) ? 1 :
((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ), ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ),
xkbbasedirflag, xkmfile, xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1, PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
xkm_output_dir, keymap); xkm_output_dir, keymap);
if (xkbbasedirflag != emptystring) { free(xkbbasedirflag);
free(xkbbasedirflag);
}
#ifndef WIN32 #ifndef WIN32
out= Popen(buf,"w"); out= Popen(buf,"w");