From 731e5c40bc9275770fa67f9bcbd222aa3e8c0bb3 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 9 Mar 2012 18:53:47 +0000 Subject: [PATCH] Stringify public name types Ensure that all names under xkb_desc are strings, rather than atoms. Signed-off-by: Daniel Stone --- include/xkbcommon/xkbcommon.h | 10 +++++----- src/alloc.c | 14 ++++++++++++-- src/malloc.c | 14 +++++++++++--- src/text.c | 22 ++++++++-------------- src/xkbcomp/indicators.c | 20 +++++++++++--------- src/xkbcomp/keycodes.c | 3 ++- src/xkbcomp/keytypes.c | 18 +++++++++++------- src/xkbcomp/symbols.c | 21 +++++++++++---------- src/xkbcomp/vmod.c | 13 ++++++++----- 9 files changed, 79 insertions(+), 56 deletions(-) diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h index ebe9674..a8f6738 100644 --- a/include/xkbcommon/xkbcommon.h +++ b/include/xkbcommon/xkbcommon.h @@ -222,8 +222,8 @@ struct xkb_key_type { unsigned char map_count; struct xkb_kt_map_entry * map; struct xkb_mods * preserve; - uint32_t name; - uint32_t *level_names; + const char *name; + const char **level_names; }; struct xkb_sym_interpret { @@ -329,9 +329,9 @@ struct xkb_key_alias { }; struct xkb_names { - uint32_t vmods[XkbNumVirtualMods]; - uint32_t indicators[XkbNumIndicators]; - uint32_t groups[XkbNumKbdGroups]; + const char *vmods[XkbNumVirtualMods]; + const char *indicators[XkbNumIndicators]; + const char *groups[XkbNumKbdGroups]; struct xkb_key_name * keys; struct xkb_key_alias * key_aliases; diff --git a/src/alloc.c b/src/alloc.c index 84bb9e1..c623eb0 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -122,7 +122,7 @@ XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases) type = xkb->map->types; for (i = 0; i < xkb->map->num_types; i++, type++) { if (!type->level_names) { - type->level_names = _XkbTypedCalloc(type->num_levels, uint32_t); + type->level_names = _XkbTypedCalloc(type->num_levels, const char *); if (!type->level_names) return BadAlloc; } @@ -171,6 +171,7 @@ XkbcFreeNames(struct xkb_desc * xkb) { struct xkb_names * names; struct xkb_client_map * map; + int i; if (!xkb || !xkb->names) return; @@ -179,15 +180,24 @@ XkbcFreeNames(struct xkb_desc * xkb) map = xkb->map; if (map && map->types) { - int i; struct xkb_key_type * type = map->types; for (i = 0; i < map->num_types; i++, type++) { + int j; + for (j = 0; j < type->num_levels; j++) + free((char *) type->level_names[i]); free(type->level_names); type->level_names = NULL; } } + for (i = 0; i < XkbNumVirtualMods; i++) + free((char *) names->vmods[i]); + for (i = 0; i < XkbNumIndicators; i++) + free((char *) names->indicators[i]); + for (i = 0; i < XkbNumKbdGroups; i++) + free((char *) names->groups[i]); + free(names->keys); free(names->key_aliases); free(names); diff --git a/src/malloc.c b/src/malloc.c index 737ad8b..1f830e6 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -214,6 +214,8 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions) int XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into) { + int i; + if (!from || !into) return BadMatch; @@ -221,6 +223,8 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into) into->map = NULL; free(into->preserve); into->preserve= NULL; + for (i = 0; i < into->num_levels; i++) + free((char *) into->level_names[i]); free(into->level_names); into->level_names = NULL; @@ -243,11 +247,11 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into) } if (from->level_names && (into->num_levels > 0)) { - into->level_names = _XkbTypedCalloc(into->num_levels, uint32_t); + into->level_names = _XkbTypedCalloc(into->num_levels, const char *); if (!into->level_names) return BadAlloc; - memcpy(into->level_names, from->level_names, - into->num_levels * sizeof(uint32_t)); + for (i = 0; i < into->num_levels; i++) + into->level_names[i] = strdup(from->level_names[i]); } return Success; @@ -392,9 +396,13 @@ XkbcFreeClientMap(struct xkb_desc * xkb) map = xkb->map; for (i = 0, type = map->types; i < map->num_types && type; i++, type++) { + int j; free(type->map); free(type->preserve); + for (j = 0; j < type->num_levels; j++) + free((char *) type->level_names[j]); free(type->level_names); + free((char *) type->name); } free(map->types); free(map->key_sym_map); diff --git a/src/text.c b/src/text.c index a41faca..15421f9 100644 --- a/src/text.c +++ b/src/text.c @@ -59,22 +59,18 @@ static const char * XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx) { int len; - uint32_t *vmodNames; - char *rtrn, *tmp = NULL; - - if (xkb && xkb->names) - vmodNames = xkb->names->vmods; - else - vmodNames = NULL; + char *rtrn; + const char *tmp = NULL; + char buf[20]; if (ndx >= XkbNumVirtualMods) - tmp = strdup("illegal"); - else if (vmodNames && (vmodNames[ndx] != None)) - tmp = XkbcAtomGetString(vmodNames[ndx]); + tmp = "illegal"; + else if (xkb && xkb->names) + tmp = xkb->names->vmods[ndx]; if (!tmp) { - tmp = malloc(20 * sizeof(char)); - snprintf(tmp, 20, "%d", ndx); + snprintf(buf, sizeof(buf) - 1, "%d", ndx); + tmp = buf; } len = strlen(tmp) + 1; @@ -84,8 +80,6 @@ XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx) rtrn = tbGetBuffer(len); strncpy(rtrn, tmp, len); - free(tmp); - return rtrn; } diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c index e4df035..d1ecc75 100644 --- a/src/xkbcomp/indicators.c +++ b/src/xkbcomp/indicators.c @@ -421,7 +421,10 @@ CopyIndicatorMapDefs(struct xkb_desc * xkb, LEDInfo *leds, LEDInfo **unboundRtrn im->mods.vmods = led->vmods; im->ctrls = led->ctrls; if (xkb->names != NULL) - xkb->names->indicators[led->indicator - 1] = led->name; + { + free((char *) xkb->names->indicators[led->indicator - 1]); + xkb->names->indicators[led->indicator-1] = XkbcAtomGetString(led->name); + } free(led); } } @@ -447,7 +450,7 @@ BindIndicators(struct xkb_desc * xkb, Bool force, LEDInfo *unbound, { for (i = 0; i < XkbNumIndicators; i++) { - if (xkb->names->indicators[i] == led->name) + if (xkb->names->indicators[i] == XkbcAtomText(led->name)) { led->indicator = i + 1; break; @@ -463,9 +466,9 @@ BindIndicators(struct xkb_desc * xkb, Bool force, LEDInfo *unbound, { for (i = 0; i < XkbNumIndicators; i++) { - if (xkb->names->indicators[i] == None) + if (xkb->names->indicators[i] == NULL) { - xkb->names->indicators[i] = led->name; + xkb->names->indicators[i] = XkbcAtomGetString(led->name); led->indicator = i + 1; xkb->indicators->phys_indicators &= ~(1 << i); break; @@ -505,14 +508,13 @@ BindIndicators(struct xkb_desc * xkb, Bool force, LEDInfo *unbound, else { if ((xkb->names != NULL) && - (xkb->names->indicators[led->indicator - 1] != led->name)) + (strcmp(xkb->names->indicators[led->indicator - 1], + XkbcAtomText(led->name)) != 0)) { - uint32_t old = xkb->names->indicators[led->indicator - 1]; + const char *old = xkb->names->indicators[led->indicator - 1]; ERROR("Multiple names bound to indicator %d\n", (unsigned int) led->indicator); - ACTION("Using %s, ignoring %s\n", - XkbcAtomText(old), - XkbcAtomText(led->name)); + ACTION("Using %s, ignoring %s\n", old, XkbcAtomText(led->name)); led->indicator = _LED_NotBound; if (force) { diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 339fa37..b207fdc 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -914,7 +914,8 @@ CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge) for (ii = info.leds; ii != NULL; ii = (IndicatorNameInfo *) ii->defs.next) { - xkb->names->indicators[ii->ndx - 1] = ii->name; + free((char *) xkb->names->indicators[ii->ndx - 1]); + xkb->names->indicators[ii->ndx - 1] = XkbcAtomGetString(ii->name); if (xkb->indicators != NULL) { unsigned bit; diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c index 762ecf0..5b10818 100644 --- a/src/xkbcomp/keytypes.c +++ b/src/xkbcomp/keytypes.c @@ -1119,15 +1119,15 @@ CopyDefToKeyType(struct xkb_desc * xkb, struct xkb_key_type * type, KeyTypeInfo } else type->preserve = NULL; - type->name = (uint32_t) def->name; + type->name = XkbcAtomGetString(def->name); if (def->szNames > 0) { - type->level_names = uTypedCalloc(def->numLevels, uint32_t); + type->level_names = uTypedCalloc(def->numLevels, const char *); /* assert def->szNames<=def->numLevels */ for (i = 0; i < def->szNames; i++) { - type->level_names[i] = (uint32_t) def->lvlNames[i]; + type->level_names[i] = XkbcAtomGetString(def->lvlNames[i]); } } else @@ -1184,13 +1184,17 @@ CompileKeyTypes(XkbFile *file, struct xkb_desc * xkb, unsigned merge) return False; } if (missing & XkbOneLevelMask) - xkb->map->types[XkbOneLevelIndex].name = tok_ONE_LEVEL; + xkb->map->types[XkbOneLevelIndex].name = + XkbcAtomGetString(tok_ONE_LEVEL); if (missing & XkbTwoLevelMask) - xkb->map->types[XkbTwoLevelIndex].name = tok_TWO_LEVEL; + xkb->map->types[XkbTwoLevelIndex].name = + XkbcAtomGetString(tok_TWO_LEVEL); if (missing & XkbAlphabeticMask) - xkb->map->types[XkbAlphabeticIndex].name = tok_ALPHABETIC; + xkb->map->types[XkbAlphabeticIndex].name = + XkbcAtomGetString(tok_ALPHABETIC); if (missing & XkbKeypadMask) - xkb->map->types[XkbKeypadIndex].name = tok_KEYPAD; + xkb->map->types[XkbKeypadIndex].name = + XkbcAtomGetString(tok_KEYPAD); } next = &xkb->map->types[XkbLastRequiredType + 1]; for (i = 0, def = info.types; i < info.nTypes; i++) diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index c49c940..1d6c6d8 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1668,21 +1668,22 @@ FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn) /** * Find the given name in the xkb->map->types and return its index. * - * @param name The atom to search for. + * @param atom The atom to search for. * @param type_rtrn Set to the index of the name if found. * * @return True if found, False otherwise. */ static Bool -FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn) +FindNamedType(struct xkb_desc * xkb, uint32_t atom, unsigned *type_rtrn) { unsigned n; + const char *name = XkbcAtomText(atom); if (xkb && xkb->map && xkb->map->types) { for (n = 0; n < xkb->map->num_types; n++) { - if (xkb->map->types[n].name == (uint32_t) name) + if (strcmp(xkb->map->types[n].name, name) == 0) { *type_rtrn = n; return True; @@ -1942,12 +1943,9 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from) { if (warningLevel > 0) { - WARN - ("Type \"%s\" has %d levels, but %s has %d symbols\n", - XkbcAtomText(type->name), - (unsigned int) type->num_levels, - longText(key->name), - (unsigned int) key->numLevels[i]); + WARN("Type \"%s\" has %d levels, but %s has %d symbols\n", + type->name, type->num_levels, + XkbcAtomText(key->name), key->numLevels[i]); ACTION("Ignoring extra symbols\n"); } key->numLevels[i] = type->num_levels; @@ -2163,7 +2161,10 @@ CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge) for (i = 0; i < XkbNumKbdGroups; i++) { if (info.groupNames[i] != None) - xkb->names->groups[i] = info.groupNames[i]; + { + free((char *) xkb->names->groups[i]); + xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]); + } } /* sanitize keys */ for (key = info.keys, i = 0; i < info.nKeys; i++, key++) diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index b6476cb..039da91 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -59,7 +59,7 @@ ClearVModInfo(VModInfo * info, struct xkb_desc * xkb) int bit; for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { - if (xkb->names->vmods[i] != None) + if (xkb->names->vmods[i] != NULL) info->defined |= bit; } } @@ -90,7 +90,8 @@ HandleVModDef(VModDef * stmt, struct xkb_desc *xkb, unsigned mergeMode, { if (info->defined & bit) { - if (names->vmods[i] == stmt->name) + if (names->vmods[i] && + strcmp(names->vmods[i], XkbcAtomText(stmt->name)) == 0) { /* already defined */ info->available |= bit; if (stmt->value == NULL) @@ -135,7 +136,7 @@ HandleVModDef(VModDef * stmt, struct xkb_desc *xkb, unsigned mergeMode, info->defined |= (1 << nextFree); info->newlyDefined |= (1 << nextFree); info->available |= (1 << nextFree); - names->vmods[nextFree] = stmt->name; + names->vmods[nextFree] = XkbcAtomGetString(stmt->name); if (stmt->value == NULL) return True; if (ExprResolveModMask(stmt->value, &mod)) @@ -163,6 +164,7 @@ LookupVModIndex(const struct xkb_desc *xkb, uint32_t field, unsigned type, ExprResult * val_rtrn) { int i; + const char *name = XkbcAtomText(field); if ((xkb == NULL) || (xkb->names == NULL) || (type != TypeInt)) { @@ -175,7 +177,7 @@ LookupVModIndex(const struct xkb_desc *xkb, uint32_t field, unsigned type, */ for (i = 0; i < XkbNumVirtualMods; i++) { - if (xkb->names->vmods[i] == field) + if (xkb->names->vmods[i] && strcmp(xkb->names->vmods[i], name) == 0) { val_rtrn->uval = i; return True; @@ -235,9 +237,10 @@ ResolveVirtualModifier(ExprDef * def, struct xkb_desc *xkb, if (def->op == ExprIdent) { int i, bit; + const char *name = XkbcAtomText(def->value.str); for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) { - if ((info->available & bit) && names->vmods[i] == def->value.str) + if ((info->available & bit) && strcmp(names->vmods[i], name) == 0) { val_rtrn->uval = i; return True; -- 2.7.4