Commit 731e5c40bc9275770fa67f9bcbd222aa3e8c0bb3

Daniel Stone 2012-03-09T18:53:47

Stringify public name types Ensure that all names under xkb_desc are strings, rather than atoms. Signed-off-by: Daniel Stone <daniel@fooishbar.org>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
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;