Commit e10e16ad2fc37d2941c0d2cb4cfdb61891a380e1

Kristian Høgsberg 2010-06-30T17:20:56

Constify XkbcAtomText() Atoms aren't mutable and this lets us put tbGetBuffer() back in the box.

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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
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 *