Commit 3104a8ef181622805f39eba608523eec51591944

Ran Benita 2012-03-24T00:12:08

Move utility macro from XKBcommonint.h to utils.h And merge all the similar ones into the same name. The u* prefix is chosen over the _Xkb prefix because it has more uses throughout the codebase. But It should now be simple to choose a nice prefix and stay consistent. Signed-off-by: Ran Benita <ran234@gmail.com> [daniels: fixed for the case where we have strcasecmp]

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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
diff --git a/src/XKBcommonint.h b/src/XKBcommonint.h
index 3205a01..f900a69 100644
--- a/src/XKBcommonint.h
+++ b/src/XKBcommonint.h
@@ -89,15 +89,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define False 0
 #endif
 
-#define _XkbTypedAlloc(t)       ((t *)malloc(sizeof(t)))
-#define _XkbTypedCalloc(n,t)    ((t *)calloc((n),sizeof(t)))
-#define _XkbTypedRealloc(o,n,t) \
-    ((o)?(t *)realloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
-#define _XkbClearElems(a,f,l,t) memset(&(a)[f], 0, ((l) - (f) + 1) * sizeof(t))
-
-#define _XkbDupString(s)        ((s) ? strdup(s) : NULL)
-#define _XkbStrCaseCmp          strcasecmp
-
 /* From XKM.h */
 #define	XkmFileVersion		15
 
diff --git a/src/alloc.c b/src/alloc.c
index 8dd4b5f..1a46fbb 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -26,6 +26,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#include "utils.h"
 #include "xkballoc.h"
 #include "xkbcommon/xkbcommon.h"
 #include "XKBcommonint.h"
@@ -50,27 +51,24 @@ XkbcAllocCompatMap(struct xkb_desc * xkb, unsigned which, unsigned nSI)
             compat->num_si = 0;
 
         prev_interpret = compat->sym_interpret;
-        compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret,
-                                                 nSI, struct xkb_sym_interpret);
+        compat->sym_interpret = uTypedRecalloc(compat->sym_interpret,
+                                               compat->num_si, nSI,
+                                               struct xkb_sym_interpret);
         if (!compat->sym_interpret) {
             free(prev_interpret);
             compat->size_si = compat->num_si = 0;
             return BadAlloc;
         }
 
-        if (compat->num_si != 0)
-            _XkbClearElems(compat->sym_interpret, compat->num_si,
-                           compat->size_si - 1, struct xkb_sym_interpret);
-
         return Success;
     }
 
-    compat = _XkbTypedCalloc(1, struct xkb_compat_map);
+    compat = uTypedCalloc(1, struct xkb_compat_map);
     if (!compat)
         return BadAlloc;
 
     if (nSI > 0) {
-        compat->sym_interpret = _XkbTypedCalloc(nSI, struct xkb_sym_interpret);
+        compat->sym_interpret = uTypedCalloc(nSI, struct xkb_sym_interpret);
         if (!compat->sym_interpret) {
             free(compat);
             return BadAlloc;
@@ -109,7 +107,7 @@ XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases)
         return BadMatch;
 
     if (!xkb->names) {
-        xkb->names = _XkbTypedCalloc(1, struct xkb_names);
+        xkb->names = uTypedCalloc(1, struct xkb_names);
         if (!xkb->names)
             return BadAlloc;
     }
@@ -122,7 +120,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, const char *);
+                type->level_names = uTypedCalloc(type->num_levels, const char *);
                 if (!type->level_names)
                     return BadAlloc;
             }
@@ -133,25 +131,23 @@ XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases)
         if (!xkb_keymap_keycode_range_is_legal(xkb))
             return BadMatch;
 
-        names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
+        names->keys = uTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
         if (!names->keys)
             return BadAlloc;
     }
 
     if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) {
         if (!names->key_aliases)
-            names->key_aliases = _XkbTypedCalloc(nTotalAliases,
+            names->key_aliases = uTypedCalloc(nTotalAliases,
                                                  struct xkb_key_alias);
         else if (nTotalAliases > names->num_key_aliases) {
             struct xkb_key_alias *prev_aliases = names->key_aliases;
 
-            names->key_aliases = _XkbTypedRealloc(names->key_aliases,
-                                                  nTotalAliases,
-                                                  struct xkb_key_alias);
-            if (names->key_aliases)
-                _XkbClearElems(names->key_aliases, names->num_key_aliases,
-                               nTotalAliases - 1, struct xkb_key_alias);
-            else
+            names->key_aliases = uTypedRecalloc(names->key_aliases,
+                                                names->num_key_aliases,
+                                                nTotalAliases,
+                                                struct xkb_key_alias);
+            if (!names->key_aliases)
                 free(prev_aliases);
         }
 
@@ -211,14 +207,14 @@ XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
         return BadMatch;
 
     if (!xkb->ctrls) {
-        xkb->ctrls = _XkbTypedCalloc(1, struct xkb_controls);
+        xkb->ctrls = uTypedCalloc(1, struct xkb_controls);
         if (!xkb->ctrls)
             return BadAlloc;
     }
 
     if (!xkb->ctrls->per_key_repeat) {
-        xkb->ctrls->per_key_repeat = _XkbTypedCalloc(xkb->max_key_code << 3,
-                                                     unsigned char);
+        xkb->ctrls->per_key_repeat = uTypedCalloc(xkb->max_key_code << 3,
+                                                  unsigned char);
         if (!xkb->ctrls->per_key_repeat)
             return BadAlloc;
     }
@@ -243,7 +239,7 @@ XkbcAllocIndicatorMaps(struct xkb_desc * xkb)
         return BadMatch;
 
     if (!xkb->indicators) {
-        xkb->indicators = _XkbTypedCalloc(1, struct xkb_indicator);
+        xkb->indicators = uTypedCalloc(1, struct xkb_indicator);
         if (!xkb->indicators)
             return BadAlloc;
     }
@@ -265,7 +261,7 @@ XkbcAllocKeyboard(void)
 {
     struct xkb_desc *xkb;
 
-    xkb = _XkbTypedCalloc(1, struct xkb_desc);
+    xkb = uTypedCalloc(1, struct xkb_desc);
     if (xkb) {
         xkb->device_spec = XkbUseCoreKbd;
         xkb->refcnt = 1;
diff --git a/src/malloc.c b/src/malloc.c
index 40f0f7b..cff30d7 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -24,6 +24,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 ********************************************************/
 
+#include "utils.h"
 #include "xkballoc.h"
 #include "xkbcommon/xkbcommon.h"
 #include "XKBcommonint.h"
@@ -46,7 +47,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
     }
 
     if (!xkb->map) {
-        map = _XkbTypedCalloc(1, struct xkb_client_map);
+        map = uTypedCalloc(1, struct xkb_client_map);
         if (!map)
             return BadAlloc;
         xkb->map = map;
@@ -56,7 +57,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
 
     if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
         if (!map->types) {
-            map->types = _XkbTypedCalloc(nTotalTypes, struct xkb_key_type);
+            map->types = uTypedCalloc(nTotalTypes, struct xkb_key_type);
             if (!map->types)
                 return BadAlloc;
 
@@ -66,7 +67,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
         else if (map->size_types < nTotalTypes) {
             struct xkb_key_type *prev_types = map->types;
 
-            map->types = _XkbTypedRealloc(map->types, nTotalTypes,
+            map->types = uTypedRealloc(map->types, nTotalTypes,
                                           struct xkb_key_type);
             if (!map->types) {
                 free(prev_types);
@@ -85,7 +86,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
 
         if (!map->syms) {
             map->size_syms = (nKeys * 15) / 10;
-            map->syms = _XkbTypedCalloc(map->size_syms, xkb_keysym_t);
+            map->syms = uTypedCalloc(map->size_syms, xkb_keysym_t);
             if (!map->syms) {
                 map->size_syms = 0;
                 return BadAlloc;
@@ -96,7 +97,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
 
         if (!map->key_sym_map) {
             i = xkb->max_key_code + 1;
-            map->key_sym_map = _XkbTypedCalloc(i, struct xkb_sym_map);
+            map->key_sym_map = uTypedCalloc(i, struct xkb_sym_map);
             if (!map->key_sym_map)
                 return BadAlloc;
         }
@@ -108,7 +109,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
 
         if (!map->modmap) {
             i = xkb->max_key_code + 1;
-            map->modmap = _XkbTypedCalloc(i, unsigned char);
+            map->modmap = uTypedCalloc(i, unsigned char);
             if (!map->modmap)
                 return BadAlloc;
         }
@@ -127,7 +128,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
         return BadMatch;
 
     if (!xkb->server) {
-        map = _XkbTypedCalloc(1, struct xkb_server_map);
+        map = uTypedCalloc(1, struct xkb_server_map);
         if (!map)
             return BadAlloc;
 
@@ -148,7 +149,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
     if (which & XkbExplicitComponentsMask) {
         if (!map->explicit) {
             i = xkb->max_key_code + 1;
-            map->explicit = _XkbTypedCalloc(i, unsigned char);
+            map->explicit = uTypedCalloc(i, unsigned char);
             if (!map->explicit)
                 return BadAlloc;
         }
@@ -159,7 +160,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
             nNewActions = 1;
 
         if (!map->acts) {
-            map->acts = _XkbTypedCalloc(nNewActions + 1, union xkb_action);
+            map->acts = uTypedCalloc(nNewActions + 1, union xkb_action);
             if (!map->acts)
                 return BadAlloc;
             map->num_acts = 1;
@@ -170,7 +171,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
             union xkb_action *prev_acts = map->acts;
 
             need = map->num_acts + nNewActions;
-            map->acts = _XkbTypedRealloc(map->acts, need, union xkb_action);
+            map->acts = uTypedRealloc(map->acts, need, union xkb_action);
             if (!map->acts) {
                 free(prev_acts);
                 map->num_acts = map->size_acts = 0;
@@ -184,7 +185,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
 
         if (!map->key_acts) {
             i = xkb->max_key_code + 1;
-            map->key_acts = _XkbTypedCalloc(i, unsigned short);
+            map->key_acts = uTypedCalloc(i, unsigned short);
             if (!map->key_acts)
                 return BadAlloc;
         }
@@ -193,7 +194,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
     if (which & XkbKeyBehaviorsMask) {
         if (!map->behaviors) {
             i = xkb->max_key_code + 1;
-            map->behaviors = _XkbTypedCalloc(i, struct xkb_behavior);
+            map->behaviors = uTypedCalloc(i, struct xkb_behavior);
             if (!map->behaviors)
                 return BadAlloc;
         }
@@ -202,7 +203,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
     if (which & XkbVirtualModMapMask) {
         if (!map->vmodmap) {
             i = xkb->max_key_code + 1;
-            map->vmodmap = _XkbTypedCalloc(i, uint32_t);
+            map->vmodmap = uTypedCalloc(i, uint32_t);
             if (!map->vmodmap)
                 return BadAlloc;
         }
@@ -231,7 +232,7 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into)
     *into = *from;
 
     if (from->map && (into->map_count > 0)) {
-        into->map = _XkbTypedCalloc(into->map_count, struct xkb_kt_map_entry);
+        into->map = uTypedCalloc(into->map_count, struct xkb_kt_map_entry);
         if (!into->map)
             return BadAlloc;
         memcpy(into->map, from->map,
@@ -239,7 +240,7 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into)
     }
 
     if (from->preserve && (into->map_count > 0)) {
-        into->preserve = _XkbTypedCalloc(into->map_count, struct xkb_mods);
+        into->preserve = uTypedCalloc(into->map_count, struct xkb_mods);
         if (!into->preserve)
             return BadAlloc;
         memcpy(into->preserve, from->preserve,
@@ -247,7 +248,7 @@ 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, const char *);
+        into->level_names = uTypedCalloc(into->num_levels, const char *);
         if (!into->level_names)
             return BadAlloc;
         for (i = 0; i < into->num_levels; i++)
@@ -290,7 +291,7 @@ XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key,
     }
 
     xkb->map->size_syms += (needed > 32 ? needed : 32);
-    newSyms = _XkbTypedCalloc(xkb->map->size_syms, xkb_keysym_t);
+    newSyms = uTypedCalloc(xkb->map->size_syms, xkb_keysym_t);
     if (!newSyms)
         return NULL;
 
@@ -346,7 +347,7 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed)
     }
 
     xkb->server->size_acts = xkb->server->num_acts + needed + 8;
-    newActs = _XkbTypedCalloc(xkb->server->size_acts, union xkb_action);
+    newActs = uTypedCalloc(xkb->server->size_acts, union xkb_action);
     if (!newActs)
         return NULL;
     newActs[0].type = XkbSA_NoAction;
diff --git a/src/map.c b/src/map.c
index 7f1d85a..ece711f 100644
--- a/src/map.c
+++ b/src/map.c
@@ -53,6 +53,7 @@
 #include <config.h>
 #endif
 
+#include "utils.h"
 #include "xkbcommon/xkbcommon.h"
 #include "XKBcommonint.h"
 #include "xkballoc.h"
diff --git a/src/maprules.c b/src/maprules.c
index dfb32e1..80e2cb3 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -27,6 +27,7 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#include "utils.h"
 #include "xkbrules.h"
 #include "xkbcommon/xkbcommon.h"
 #include "XKBcommonint.h"
@@ -407,8 +408,8 @@ CheckLine(	InputLine *		line,
             }
             if (*words == '\0')
                 return False;
-            group->name = _XkbDupString(gname);
-            group->words = _XkbDupString(words);
+            group->name = uDupString(gname);
+            group->words = uDupString(words);
             for (i = 1, words = group->words; *words; words++) {
                  if ( *words == ' ') {
                      *words++ = '\0';
@@ -459,16 +460,16 @@ CheckLine(	InputLine *		line,
 	 rule->flags|= XkbRF_Append;
     else
 	 rule->flags|= XkbRF_Normal;
-    rule->model= _XkbDupString(tmp.name[MODEL]);
-    rule->layout= _XkbDupString(tmp.name[LAYOUT]);
-    rule->variant= _XkbDupString(tmp.name[VARIANT]);
-    rule->option= _XkbDupString(tmp.name[OPTION]);
+    rule->model= uDupString(tmp.name[MODEL]);
+    rule->layout= uDupString(tmp.name[LAYOUT]);
+    rule->variant= uDupString(tmp.name[VARIANT]);
+    rule->option= uDupString(tmp.name[OPTION]);
 
-    rule->keycodes= _XkbDupString(tmp.name[KEYCODES]);
-    rule->symbols= _XkbDupString(tmp.name[SYMBOLS]);
-    rule->types= _XkbDupString(tmp.name[TYPES]);
-    rule->compat= _XkbDupString(tmp.name[COMPAT]);
-    rule->keymap= _XkbDupString(tmp.name[KEYMAP]);
+    rule->keycodes= uDupString(tmp.name[KEYCODES]);
+    rule->symbols= uDupString(tmp.name[SYMBOLS]);
+    rule->types= uDupString(tmp.name[TYPES]);
+    rule->compat= uDupString(tmp.name[COMPAT]);
+    rule->keymap= uDupString(tmp.name[KEYMAP]);
 
     rule->layout_num = rule->variant_num = 0;
     for (i = 0; i < nread; i++) {
@@ -490,7 +491,7 @@ _Concat(char *str1,char *str2)
     if ((!str1)||(!str2))
 	return str1;
     len= strlen(str1)+strlen(str2)+1;
-    str1= _XkbTypedRealloc(str1,len,char);
+    str1 = uTypedRealloc(str1, len, char);
     if (str1)
 	strcat(str1,str2);
     return str1;
@@ -512,7 +513,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
 {
    memset(mdefs, 0, sizeof(XkbRF_MultiDefsRec));
    mdefs->model = defs->model;
-   mdefs->options = _XkbDupString(defs->options);
+   mdefs->options = uDupString(defs->options);
    if (mdefs->options) squeeze_spaces(mdefs->options);
 
    if (defs->layout) {
@@ -521,7 +522,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           p = _XkbDupString(defs->layout);
+           p = uDupString(defs->layout);
            if (p == NULL)
               return False;
            squeeze_spaces(p);
@@ -545,7 +546,7 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           p = _XkbDupString(defs->variant);
+           p = uDupString(defs->variant);
            if (p == NULL)
               return False;
            squeeze_spaces(p);
@@ -582,7 +583,7 @@ Apply(char *src, char **dst)
 	    *dst= _Concat(*dst, src);
         } else {
             if (*dst == NULL)
-	        *dst= _XkbDupString(src);
+	        *dst= uDupString(src);
         }
     }
 }
@@ -881,11 +882,11 @@ XkbcRF_AddRule(XkbRF_RulesPtr	rules)
     if (rules->sz_rules<1) {
 	rules->sz_rules= 16;
 	rules->num_rules= 0;
-	rules->rules= _XkbTypedCalloc(rules->sz_rules,XkbRF_RuleRec);
+	rules->rules= uTypedCalloc(rules->sz_rules,XkbRF_RuleRec);
     }
     else if (rules->num_rules>=rules->sz_rules) {
 	rules->sz_rules*= 2;
-	rules->rules= _XkbTypedRealloc(rules->rules,rules->sz_rules,
+	rules->rules= uTypedRealloc(rules->rules,rules->sz_rules,
 							XkbRF_RuleRec);
     }
     if (!rules->rules) {
@@ -905,12 +906,12 @@ XkbcRF_AddGroup(XkbRF_RulesPtr	rules)
     if (rules->sz_groups<1) {
 	rules->sz_groups= 16;
 	rules->num_groups= 0;
-	rules->groups= _XkbTypedCalloc(rules->sz_groups,XkbRF_GroupRec);
+	rules->groups= uTypedCalloc(rules->sz_groups,XkbRF_GroupRec);
     }
     else if (rules->num_groups >= rules->sz_groups) {
 	rules->sz_groups *= 2;
-	rules->groups= _XkbTypedRealloc(rules->groups,rules->sz_groups,
-							XkbRF_GroupRec);
+	rules->groups= uTypedRealloc(rules->groups,rules->sz_groups,
+                                     XkbRF_GroupRec);
     }
     if (!rules->groups) {
 	rules->sz_groups= rules->num_groups= 0;
diff --git a/src/utils.h b/src/utils.h
index 2fbf87a..0b0582b 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -40,17 +40,21 @@
 extern void *
 recalloc(void *ptr, size_t old_size, size_t new_size);
 
-#define	uTypedAlloc(t)		((t *)malloc((unsigned)sizeof(t)))
-#define	uTypedCalloc(n,t)	((t *)calloc((unsigned)n,(unsigned)sizeof(t)))
-#define	uTypedRealloc(pO,n,t)	((t *)realloc(pO,((unsigned)n)*sizeof(t)))
-#define uTypedRecalloc(pO, o, n, t) recalloc(pO, (o) * sizeof(t), (n) * sizeof(t))
+#define uTypedAlloc(t)              malloc(sizeof(t))
+#define uTypedCalloc(n, t)          calloc((n), sizeof(t))
+#define uTypedRealloc(pO, n, t)     realloc((pO), (n) * sizeof(t))
+#define uTypedRecalloc(pO, o, n, t) recalloc((pO), (o) * sizeof(t), (n) * sizeof(t))
+
+#define uDupString(s)          ((s) ? strdup(s) : NULL)
+#define uStringText(s)         ((s) == NULL ? "<NullString>" : (s))
+#define uStrCaseCmp(s1, s2)    strcasecmp(s1, s2)
+#define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
 
 /***====================================================================***/
 
 extern Bool
 uSetErrorFile(char *name);
 
-
 #define INFO 			uInformation
 
 extern _X_ATTRIBUTE_PRINTF(1, 2) void
@@ -82,12 +86,4 @@ uFatalError(const char *s, ...);
 extern _X_ATTRIBUTE_PRINTF(1, 2) void
 uInternalError(const char *s, ...);
 
-/***====================================================================***/
-
-#define	uStringText(s)		((s) == NULL ? "<NullString>" : (s))
-#define	uStringEqual(s1,s2)	(strcmp(s1,s2) == 0)
-#define	uStringPrefix(p,s)	(strncmp(p,s,strlen(p))==0)
-#define	uStrCaseCmp(s1,s2)	(strcasecmp(s1,s2))
-#define	uStrCasePrefix(p,s)	(strncasecmp(p,s,strlen(p))==0)
-
 #endif /* UTILS_H */
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index f21627e..6b30232 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -708,7 +708,7 @@ HandleCompatMapFile(XkbFile * file,
     if (merge == MergeDefault)
         merge = MergeAugment;
     free(info->name);
-    info->name = _XkbDupString(file->name);
+    info->name = uDupString(file->name);
     stmt = file->defs;
     while (stmt)
     {
diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c
index 55328c2..4d03bd6 100644
--- a/src/xkbcomp/indicators.c
+++ b/src/xkbcomp/indicators.c
@@ -32,6 +32,7 @@
 #include "vmod.h"
 #include "indicators.h"
 #include "action.h"
+#include "utils.h"
 
 /***====================================================================***/
 
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index a65bb1a..88dcb50 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -92,7 +92,7 @@ ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
     void *tmp;
     int i;
 
-    tmp = _XkbTypedRealloc(info->names, newMax + 1, unsigned long);
+    tmp = uTypedRealloc(info->names, newMax + 1, unsigned long);
     if (!tmp) {
         ERROR
             ("Couldn't reallocate for larger maximum keycode (%d)\n",
@@ -104,7 +104,7 @@ ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
     for (i = info->arraySize + 1; i <= newMax; i++)
         info->names[i] = 0;
 
-    tmp = _XkbTypedRealloc(info->files, newMax + 1, unsigned);
+    tmp = uTypedRealloc(info->files, newMax + 1, unsigned);
     if (!tmp) {
         ERROR
             ("Couldn't reallocate for larger maximum keycode (%d)\n",
@@ -116,7 +116,7 @@ ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
     for (i = info->arraySize + 1; i <= newMax; i++)
         info->files[i] = 0;
 
-    tmp = _XkbTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
+    tmp = uTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
     if (!tmp) {
         ERROR
             ("Couldn't reallocate for larger maximum keycode (%d)\n",
@@ -805,7 +805,7 @@ HandleKeycodesFile(XkbFile * file,
     ParseCommon *stmt;
 
     free(info->name);
-    info->name = _XkbDupString(file->name);
+    info->name = uDupString(file->name);
     stmt = file->defs;
     while (stmt)
     {
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 0e00666..ab31706 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -1012,7 +1012,7 @@ HandleKeyTypesFile(XkbFile * file,
     ParseCommon *stmt;
 
     free(info->name);
-    info->name = _XkbDupString(file->name);
+    info->name = uDupString(file->name);
     stmt = file->defs;
     while (stmt)
     {
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index 107be23..32f7484 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -473,7 +473,7 @@ IncludeCreate(char *str, unsigned merge)
     incl = first = NULL;
     file = map = NULL;
     tmp = str;
-    stmt = _XkbDupString(str);
+    stmt = uDupString(str);
     while ((tmp) && (*tmp))
     {
         if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
@@ -592,7 +592,7 @@ CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
         XkbcEnsureSafeMapName(name);
         memset(file, 0, sizeof(XkbFile));
         file->type = type;
-        file->topName = _XkbDupString(name);
+        file->topName = uDupString(name);
         file->name = name;
         file->defs = defs;
         file->id = fileID++;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 726e9d0..6defce2 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1454,7 +1454,7 @@ HandleSymbolsFile(XkbFile * file,
     ParseCommon *stmt;
 
     free(info->name);
-    info->name = _XkbDupString(file->name);
+    info->name = uDupString(file->name);
     stmt = file->defs;
     while (stmt)
     {
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index b229688..991ec60 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -77,7 +77,7 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
         return NULL;
     }
 
-    if (!(loaded = _XkbTypedCalloc(1, XkbRF_RulesRec))) {
+    if (!(loaded = uTypedCalloc(1, XkbRF_RulesRec))) {
         ERROR("failed to allocate XKB rules\n");
         goto unwind_file;
     }
@@ -87,7 +87,7 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
         goto unwind_file;
     }
 
-    if (!(names = _XkbTypedCalloc(1, struct xkb_component_names))) {
+    if (!(names = uTypedCalloc(1, struct xkb_component_names))) {
         ERROR("failed to allocate XKB components\n");
         goto unwind_file;
     }
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index 505d8ba..06dd71a 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -115,7 +115,7 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
         if (tmp != NULL)
         {
             *tmp++ = '\0';
-            *extra_data = _XkbDupString(tmp);
+            *extra_data = uDupString(tmp);
         }
         else
         {
@@ -124,7 +124,7 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
         tmp = strchr(str, '(');
         if (tmp == NULL)
         {
-            *file_rtrn = _XkbDupString(str);
+            *file_rtrn = uDupString(str);
             *map_rtrn = NULL;
         }
         else if (str[0] == '(')
@@ -135,7 +135,7 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
         else
         {
             *tmp++ = '\0';
-            *file_rtrn = _XkbDupString(str);
+            *file_rtrn = uDupString(str);
             str = tmp;
             tmp = strchr(str, ')');
             if ((tmp == NULL) || (tmp[1] != '\0'))
@@ -145,7 +145,7 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
                 return False;
             }
             *tmp++ = '\0';
-            *map_rtrn = _XkbDupString(str);
+            *map_rtrn = uDupString(str);
         }
     }
     if (*nextop_rtrn == '\0')