From e10e16ad2fc37d2941c0d2cb4cfdb61891a380e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 30 Jun 2010 17:20:56 -0400 Subject: [PATCH] Constify XkbcAtomText() Atoms aren't mutable and this lets us put tbGetBuffer() back in the box. --- src/XKBcommonint.h | 2 -- src/atom.c | 24 +++--------------------- src/galloc.c | 10 +++++----- src/text.c | 2 +- src/xkbcomp/action.c | 6 +++--- src/xkbcomp/compat.c | 4 ++-- src/xkbcomp/expr.c | 14 +++++++------- src/xkbcomp/geometry.c | 13 ++++++------- src/xkbcomp/keytypes.c | 2 +- src/xkbcomp/misc.c | 7 ++++--- src/xkbcomp/misc.h | 16 ++++++++-------- src/xkbcomp/vmod.c | 2 +- src/xkbgeom.h | 8 ++++---- src/xkbmisc.h | 2 +- 14 files changed, 46 insertions(+), 66 deletions(-) diff --git a/src/XKBcommonint.h b/src/XKBcommonint.h index 4e899ab..c843298 100644 --- a/src/XKBcommonint.h +++ b/src/XKBcommonint.h @@ -44,6 +44,4 @@ authorization from the authors. #define _XkbDupString(s) ((s) ? strdup(s) : NULL) #define _XkbStrCaseCmp strcasecmp -extern char *tbGetBuffer(unsigned int len); - #endif /* _XKBCOMMONINT_H_ */ diff --git a/src/atom.c b/src/atom.c index baab640..8aa3aa1 100644 --- a/src/atom.c +++ b/src/atom.c @@ -107,8 +107,8 @@ XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value) } } -static const char * -_XkbcAtomGetString(uint32_t atom) +const char * +XkbcAtomText(uint32_t atom) { NodePtr node; @@ -125,28 +125,10 @@ _XkbcAtomGetString(uint32_t atom) char * XkbcAtomGetString(uint32_t atom) { - const char *ret = _XkbcAtomGetString(atom); + const char *ret = XkbcAtomText(atom); return ret ? strdup(ret) : NULL; } -char * -XkbcAtomText(uint32_t atom) -{ - const char *tmp; - char *ret; - - tmp = _XkbcAtomGetString(atom); - if (!tmp) - return ""; - - ret = tbGetBuffer(strlen(tmp) + 1); - if (!ret) - return ""; - - strcpy(ret, tmp); - return ret; -} - static uint32_t _XkbcMakeAtom(const char *string, unsigned len, Bool makeit) { diff --git a/src/galloc.c b/src/galloc.c index 30be962..eb3821a 100644 --- a/src/galloc.c +++ b/src/galloc.c @@ -606,7 +606,7 @@ bail: } XkbcPropertyPtr -XkbcAddGeomProperty(XkbcGeometryPtr geom,char *name,char *value) +XkbcAddGeomProperty(XkbcGeometryPtr geom,const char *name,const char *value) { register int i; register XkbcPropertyPtr prop; @@ -644,7 +644,7 @@ register XkbcPropertyPtr prop; } XkbKeyAliasPtr -XkbcAddGeomKeyAlias(XkbcGeometryPtr geom,char *aliasStr,char *realStr) +XkbcAddGeomKeyAlias(XkbcGeometryPtr geom,const char *aliasStr,const char *realStr) { register int i; register XkbKeyAliasPtr alias; @@ -671,7 +671,7 @@ register XkbKeyAliasPtr alias; } XkbcColorPtr -XkbcAddGeomColor(XkbcGeometryPtr geom,char *spec,unsigned int pixel) +XkbcAddGeomColor(XkbcGeometryPtr geom,const char *spec,unsigned int pixel) { register int i; register XkbcColorPtr color; @@ -856,8 +856,8 @@ register int i,nDoodads; XkbcOverlayKeyPtr XkbcAddGeomOverlayKey( XkbcOverlayPtr overlay, XkbcOverlayRowPtr row, - char * over, - char * under) + const char * over, + const char * under) { register int i; XkbcOverlayKeyPtr key; diff --git a/src/text.c b/src/text.c index 2e9ece9..b9d841b 100644 --- a/src/text.c +++ b/src/text.c @@ -39,7 +39,7 @@ static char textBuffer[BUFFER_SIZE]; static int tbNext = 0; -char * +static char * tbGetBuffer(unsigned int size) { char *rtrn; diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 3ff1980..28e5219 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -42,7 +42,7 @@ static ExprDef constFalse; /***====================================================================***/ static Bool -stringToAction(char *str, unsigned *type_rtrn) +stringToAction(const char *str, unsigned *type_rtrn) { if (str == NULL) return False; @@ -372,7 +372,7 @@ CheckModifierField(XkbcDescPtr xkb, if (value->op == ExprIdent) { - register char *valStr; + const char *valStr; valStr = XkbcAtomText(value->value.str); if (valStr && ((uStrCaseCmp(valStr, "usemodmapmods") == 0) || (uStrCaseCmp(valStr, "modmapmods") == 0))) @@ -1293,7 +1293,7 @@ HandleActionDef(ExprDef * def, struct xkb_any_action * action, unsigned mergeMode, ActionInfo * info) { ExprDef *arg; - register char *str; + const char *str; unsigned tmp, hndlrType; if (!actionsInitialized) diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index cfa7508..e26bf24 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -307,7 +307,7 @@ ResolveStateAndPredicate(ExprDef * expr, *pred_rtrn = XkbSI_Exactly; if (expr->op == ExprActionDecl) { - char *pred_txt = XkbcAtomText(expr->value.action.name); + const char *pred_txt = XkbcAtomText(expr->value.action.name); if (uStrCaseCmp(pred_txt, "noneof") == 0) *pred_rtrn = XkbSI_NoneOf; else if (uStrCaseCmp(pred_txt, "anyofornone") == 0) @@ -328,7 +328,7 @@ ResolveStateAndPredicate(ExprDef * expr, } else if (expr->op == ExprIdent) { - char *pred_txt = XkbcAtomText(expr->value.str); + const char *pred_txt = XkbcAtomText(expr->value.str); if ((pred_txt) && (uStrCaseCmp(pred_txt, "any") == 0)) { *pred_rtrn = XkbSI_AnyOf; diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 0de20cc..f08d040 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -159,7 +159,7 @@ SimpleLookup(char * priv, uint32_t elem, uint32_t field, unsigned type, ExprResult * val_rtrn) { LookupEntry *entry; - register char *str; + const char *str; if ((priv == NULL) || (field == None) || (elem != None) || @@ -186,7 +186,7 @@ Bool RadioLookup(char * priv, uint32_t elem, uint32_t field, unsigned type, ExprResult * val_rtrn) { - register char *str; + const char *str; int rg; if ((field == None) || (elem != None) || (type != TypeInt)) @@ -215,7 +215,7 @@ TableLookup(char * priv, uint32_t elem, uint32_t field, unsigned type, ExprResult * val_rtrn) { LookupTable *tbl = (LookupTable *) priv; - register char *str; + const char *str; if ((priv == NULL) || (field == None) || (type != TypeInt)) return False; @@ -385,7 +385,7 @@ ExprResolveBoolean(ExprDef * expr, IdentLookupFunc lookup, char * lookupPriv) { int ok = 0; - char *bogus = NULL; + const char *bogus = NULL; switch (expr->op) { @@ -489,7 +489,7 @@ ExprResolveFloat(ExprDef * expr, case ExprValue: if (expr->type == TypeString) { - char *str; + const char *str; str = XkbcAtomText(expr->value.str); if ((str != NULL) && (strlen(str) == 1)) { @@ -602,7 +602,7 @@ ExprResolveInteger(ExprDef * expr, case ExprValue: if (expr->type == TypeString) { - char *str; + const char *str; str = XkbcAtomText(expr->value.str); if (str != NULL) switch (strlen(str)) @@ -1053,7 +1053,7 @@ ExprResolveKeySym(ExprDef * expr, if (expr->op == ExprIdent) { - char *str; + const char *str; str = XkbcAtomText(expr->value.str); if ((str != NULL) && ((sym = XkbcStringToKeysym(str)) != NoSymbol)) { diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c index eb7d142..b4a95d3 100644 --- a/src/xkbcomp/geometry.c +++ b/src/xkbcomp/geometry.c @@ -249,7 +249,7 @@ typedef struct _GeometryInfo AliasInfo *aliases; } GeometryInfo; -static char * +static const char * ddText(DoodadInfo * di) { static char buf[64]; @@ -1402,7 +1402,7 @@ HandleIncludeGeometry(IncludeStmt * stmt, XkbcDescPtr xkb, GeometryInfo * info, static int SetShapeField(ShapeInfo * si, - char *field, + const char *field, ExprDef * arrayNdx, ExprDef * value, GeometryInfo * info) { ExprResult tmp; @@ -2446,7 +2446,7 @@ HandleShapeBody(ShapeDef * def, ShapeInfo * si, unsigned merge, } if (ol->field != None) { - char *str = XkbcAtomText(ol->field); + const char *str = XkbcAtomText(ol->field); if ((uStrCaseCmp(str, "approximation") == 0) || (uStrCaseCmp(str, "approx") == 0)) { @@ -2476,7 +2476,6 @@ HandleShapeBody(ShapeDef * def, ShapeInfo * si, unsigned merge, shText(si)); ACTION("Treated as a normal outline\n"); } - free(str); } } if (nOut != si->nOutlines) @@ -3121,7 +3120,7 @@ VerifyDoodadInfo(DoodadInfo * di, GeometryInfo * info) if ((di->defs.defined & _GD_Height) == 0) { unsigned size, nLines; - char *tmp; + const char *tmp; size = (di->fontSize * 120) / 100; size = (size * 254) / 720; /* convert to mm/10 */ for (nLines = 1, tmp = XkbcAtomText(di->text); *tmp; tmp++) @@ -3141,7 +3140,7 @@ VerifyDoodadInfo(DoodadInfo * di, GeometryInfo * info) if ((di->defs.defined & _GD_Width) == 0) { unsigned width, tmp; - char *str; + const char *str; width = tmp = 0; for (str = XkbcAtomText(di->text); *str; str++) { @@ -3261,7 +3260,7 @@ FontFromParts(uint32_t fontTok, uint32_t setWidthTok, uint32_t varTok, int size, uint32_t encodingTok) { int totalSize; - char *font, *weight, *slant, *setWidth, *variant, *encoding; + const char *font, *weight, *slant, *setWidth, *variant, *encoding; char *rtrn; font = (fontTok != None ? XkbcAtomText(fontTok) : DFLT_FONT); diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 35a7e07..ca0c396 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -813,7 +813,7 @@ AddLevelName(KeyTypeInfo * type, { if (warningLevel > 0) { - char *old, *new; + const char *old, *new; old = XkbcAtomText(type->lvlNames[level]); new = XkbcAtomText(name); WARN("Multiple names for level %d of key type %s\n", diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c index e8f4e7e..df0e5b4 100644 --- a/src/xkbcomp/misc.c +++ b/src/xkbcomp/misc.c @@ -134,7 +134,7 @@ ReportNotArray(const char *type, const char *field, const char *name) } int -ReportShouldBeArray(const char *type, const char *field, char *name) +ReportShouldBeArray(const char *type, const char *field, const char *name) { ERROR("Missing subscript for %s %s\n", type, field); ACTION("Ignoring illegal assignment in %s\n", name); @@ -151,7 +151,8 @@ ReportBadType(const char *type, const char *field, } int -ReportBadIndexType(char *type, char *field, char *name, char *wanted) +ReportBadIndexType(const char *type, const char *field, + const char *name, const char *wanted) { ERROR("Index for the %s %s field must be a %s\n", type, field, wanted); ACTION("Ignoring assignment to illegal field in %s\n", name); @@ -167,7 +168,7 @@ ReportBadField(const char *type, const char *field, const char *name) } int -ReportMultipleDefs(char *type, char *field, char *name) +ReportMultipleDefs(const char *type, const char *field, const char *name) { WARN("Multiple definitions of %s in %s \"%s\"\n", field, type, name); ACTION("Using last definition\n"); diff --git a/src/xkbcomp/misc.h b/src/xkbcomp/misc.h index 22c4848..b1297da 100644 --- a/src/xkbcomp/misc.h +++ b/src/xkbcomp/misc.h @@ -61,7 +61,7 @@ extern int ReportNotArray(const char * /* type */ , extern int ReportShouldBeArray(const char * /* type */ , const char * /* field */ , - char * /* name */ + const char * /* name */ ); extern int ReportBadType(const char * /* type */ , @@ -70,10 +70,10 @@ extern int ReportBadType(const char * /* type */ , const char * /* wanted */ ); -extern int ReportBadIndexType(char * /* type */ , - char * /* field */ , - char * /* name */ , - char * /* wanted */ +extern int ReportBadIndexType(const char * /* type */ , + const char * /* field */ , + const char * /* name */ , + const char * /* wanted */ ); extern int ReportBadField(const char * /* type */ , @@ -81,9 +81,9 @@ extern int ReportBadField(const char * /* type */ , const char * /* name */ ); -extern int ReportMultipleDefs(char * /* type */ , - char * /* field */ , - char * /* which */ +extern int ReportMultipleDefs(const char * /* type */ , + const char * /* field */ , + const char * /* which */ ); extern Bool ProcessIncludeFile(IncludeStmt * /* stmt */ , diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 7971c0d..c959224 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -100,7 +100,7 @@ HandleVModDef(VModDef * stmt, unsigned mergeMode, VModInfo * info) return True; else { - char *str1; + const char *str1; const char *str2 = ""; if (!ExprResolveModMask(stmt->value, &mod, NULL, NULL)) { diff --git a/src/xkbgeom.h b/src/xkbgeom.h index e476316..7d495e0 100644 --- a/src/xkbgeom.h +++ b/src/xkbgeom.h @@ -123,13 +123,13 @@ extern int XkbcAllocGeometry(XkbcDescPtr xkb, XkbcGeometrySizesPtr sizes); extern XkbcPropertyPtr -XkbcAddGeomProperty(XkbcGeometryPtr geom, char *name, char *value); +XkbcAddGeomProperty(XkbcGeometryPtr geom, const char *name, const char *value); extern XkbKeyAliasPtr -XkbcAddGeomKeyAlias(XkbcGeometryPtr geom, char *aliasStr, char *realStr); +XkbcAddGeomKeyAlias(XkbcGeometryPtr geom, const char *aliasStr, const char *realStr); extern XkbcColorPtr -XkbcAddGeomColor(XkbcGeometryPtr geom, char *spec, unsigned int pixel); +XkbcAddGeomColor(XkbcGeometryPtr geom, const char *spec, unsigned int pixel); extern XkbcOutlinePtr XkbcAddGeomOutline(XkbcShapePtr shape, int sz_points); @@ -152,7 +152,7 @@ XkbcAddGeomDoodad(XkbcGeometryPtr geom, XkbcSectionPtr section, uint32_t name); extern XkbcOverlayKeyPtr XkbcAddGeomOverlayKey(XkbcOverlayPtr overlay, XkbcOverlayRowPtr row, - char *over, char *under); + const char *over, const char *under); extern XkbcOverlayRowPtr XkbcAddGeomOverlayRow(XkbcOverlayPtr overlay, int row_under, int sz_keys); diff --git a/src/xkbmisc.h b/src/xkbmisc.h index 0671120..2096849 100644 --- a/src/xkbmisc.h +++ b/src/xkbmisc.h @@ -70,7 +70,7 @@ XkbcInternAtom(const char *name, Bool onlyIfExists); /***====================================================================***/ -extern char * +extern const char * XkbcAtomText(uint32_t atm); extern char * -- 2.7.4