Commit 35657c660a121175062d285e714d7ce088b01f31

Ran Benita 2013-02-25T16:38:56

ast-build: remove malloc_or_die This should be fixed properly. Signed-off-by: Ran Benita <ran234@gmail.com>

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
diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c
index 420f8e2..79b579c 100644
--- a/src/xkbcomp/ast-build.c
+++ b/src/xkbcomp/ast-build.c
@@ -56,17 +56,6 @@
 #include "parser-priv.h"
 #include "include.h"
 
-ATTR_MALLOC static void *
-malloc_or_die(size_t size)
-{
-    void *p = malloc(size);
-    if (!p) {
-        fprintf(stderr, "Out of memory\n");
-        exit(1);
-    }
-    return p;
-}
-
 ParseCommon *
 AppendStmt(ParseCommon *to, ParseCommon *append)
 {
@@ -84,14 +73,15 @@ AppendStmt(ParseCommon *to, ParseCommon *append)
 ExprDef *
 ExprCreate(enum expr_op_type op, enum expr_value_type type)
 {
-    ExprDef *expr;
-
-    expr = malloc_or_die(sizeof(*expr));
+    ExprDef *expr = malloc(sizeof(*expr));
+    if (!expr)
+        return NULL;
 
     expr->common.type = STMT_EXPR;
     expr->common.next = NULL;
     expr->op = op;
     expr->value_type = type;
+
     return expr;
 }
 
@@ -99,23 +89,25 @@ ExprDef *
 ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
                 ExprDef *child)
 {
-    ExprDef *expr;
-    expr = malloc_or_die(sizeof(*expr));
+    ExprDef *expr = malloc(sizeof(*expr));
+    if (!expr)
+        return NULL;
 
     expr->common.type = STMT_EXPR;
     expr->common.next = NULL;
     expr->op = op;
     expr->value_type = type;
     expr->value.child = child;
+
     return expr;
 }
 
 ExprDef *
 ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
 {
-    ExprDef *expr;
-
-    expr = malloc_or_die(sizeof(*expr));
+    ExprDef *expr = malloc(sizeof(*expr));
+    if (!expr)
+        return NULL;
 
     expr->common.type = STMT_EXPR;
     expr->common.next = NULL;
@@ -129,61 +121,67 @@ ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
         expr->value_type = EXPR_TYPE_UNKNOWN;
     expr->value.binary.left = left;
     expr->value.binary.right = right;
+
     return expr;
 }
 
 KeycodeDef *
 KeycodeCreate(xkb_atom_t name, int64_t value)
 {
-    KeycodeDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    KeycodeDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_KEYCODE;
     def->common.next = NULL;
     def->name = name;
     def->value = value;
+
     return def;
 }
 
 KeyAliasDef *
 KeyAliasCreate(xkb_atom_t alias, xkb_atom_t real)
 {
-    KeyAliasDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    KeyAliasDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_ALIAS;
     def->common.next = NULL;
     def->alias = alias;
     def->real = real;
+
     return def;
 }
 
 VModDef *
-VModCreate(xkb_atom_t name, ExprDef * value)
+VModCreate(xkb_atom_t name, ExprDef *value)
 {
-    VModDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    VModDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_VMOD;
     def->common.next = NULL;
     def->name = name;
     def->value = value;
+
     return def;
 }
 
 VarDef *
-VarCreate(ExprDef * name, ExprDef * value)
+VarCreate(ExprDef *name, ExprDef *value)
 {
-    VarDef *def;
-    def = malloc_or_die(sizeof(*def));
+    VarDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_VAR;
     def->common.next = NULL;
     def->name = name;
     def->value = value;
+
     return def;
 }
 
@@ -191,109 +189,118 @@ VarDef *
 BoolVarCreate(xkb_atom_t nameToken, unsigned set)
 {
     ExprDef *name, *value;
+    VarDef *def;
 
     name = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
     name->value.str = nameToken;
     value = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN);
     value->value.uval = set;
-    return VarCreate(name, value);
+    def = VarCreate(name, value);
+
+    return def;
 }
 
 InterpDef *
-InterpCreate(char *sym, ExprDef * match)
+InterpCreate(char *sym, ExprDef *match)
 {
-    InterpDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    InterpDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_INTERP;
     def->common.next = NULL;
     def->sym = sym;
     def->match = match;
+
     return def;
 }
 
 KeyTypeDef *
-KeyTypeCreate(xkb_atom_t name, VarDef * body)
+KeyTypeCreate(xkb_atom_t name, VarDef *body)
 {
-    KeyTypeDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    KeyTypeDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_TYPE;
     def->common.next = NULL;
     def->merge = MERGE_DEFAULT;
     def->name = name;
     def->body = body;
+
     return def;
 }
 
 SymbolsDef *
 SymbolsCreate(xkb_atom_t keyName, ExprDef *symbols)
 {
-    SymbolsDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    SymbolsDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_SYMBOLS;
     def->common.next = NULL;
     def->merge = MERGE_DEFAULT;
     def->keyName = keyName;
     def->symbols = symbols;
+
     return def;
 }
 
 GroupCompatDef *
-GroupCompatCreate(int group, ExprDef * val)
+GroupCompatCreate(int group, ExprDef *val)
 {
-    GroupCompatDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    GroupCompatDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_GROUP_COMPAT;
     def->common.next = NULL;
     def->merge = MERGE_DEFAULT;
     def->group = group;
     def->def = val;
+
     return def;
 }
 
 ModMapDef *
-ModMapCreate(uint32_t modifier, ExprDef * keys)
+ModMapCreate(uint32_t modifier, ExprDef *keys)
 {
-    ModMapDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    ModMapDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_MODMAP;
     def->common.next = NULL;
     def->merge = MERGE_DEFAULT;
     def->modifier = modifier;
     def->keys = keys;
+
     return def;
 }
 
 LedMapDef *
-LedMapCreate(xkb_atom_t name, VarDef * body)
+LedMapCreate(xkb_atom_t name, VarDef *body)
 {
-    LedMapDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    LedMapDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_LED_MAP;
     def->common.next = NULL;
     def->merge = MERGE_DEFAULT;
     def->name = name;
     def->body = body;
+
     return def;
 }
 
 LedNameDef *
-LedNameCreate(int ndx, ExprDef * name, bool virtual)
+LedNameCreate(int ndx, ExprDef *name, bool virtual)
 {
-    LedNameDef *def;
-
-    def = malloc_or_die(sizeof(*def));
+    LedNameDef *def = malloc(sizeof(*def));
+    if (!def)
+        return NULL;
 
     def->common.type = STMT_LED_NAME;
     def->common.next = NULL;
@@ -301,21 +308,23 @@ LedNameCreate(int ndx, ExprDef * name, bool virtual)
     def->ndx = ndx;
     def->name = name;
     def->virtual = virtual;
+
     return def;
 }
 
 ExprDef *
-ActionCreate(xkb_atom_t name, ExprDef * args)
+ActionCreate(xkb_atom_t name, ExprDef *args)
 {
-    ExprDef *act;
-
-    act = malloc_or_die(sizeof(*act));
+    ExprDef *act = malloc(sizeof(*act));
+    if (!act)
+        return NULL;
 
     act->common.type = STMT_EXPR;
     act->common.next = NULL;
     act->op = EXPR_ACTION_DECL;
     act->value.action.name = name;
     act->value.action.args = args;
+
     return act;
 }
 
@@ -351,7 +360,7 @@ CreateMultiKeysymList(ExprDef *list)
 }
 
 ExprDef *
-AppendKeysymList(ExprDef * list, char *sym)
+AppendKeysymList(ExprDef *list, char *sym)
 {
     size_t nSyms = darray_size(list->value.list.syms);
 
@@ -363,7 +372,7 @@ AppendKeysymList(ExprDef * list, char *sym)
 }
 
 ExprDef *
-AppendMultiKeysymList(ExprDef * list, ExprDef * append)
+AppendMultiKeysymList(ExprDef *list, ExprDef *append)
 {
     size_t nSyms = darray_size(list->value.list.syms);
     size_t numEntries = darray_size(append->value.list.syms);
@@ -455,25 +464,25 @@ err:
     return NULL;
 }
 
-/*
- * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
- * wildcards.
- */
-static const unsigned char componentSpecLegal[] = {
-    0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
-    0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-    0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
-};
-
 static void
-EnsureSafeMapName(char *name)
-{
+EscapeMapName(char *name)
+{
+    /*
+     * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
+     * wildcards.
+     */
+    static const unsigned char legal[] = {
+        0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
+        0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
+    };
+
     if (!name)
         return;
 
-    while (*name != '\0') {
-        if ((componentSpecLegal[(*name) / 8] & (1 << ((*name) % 8))) == 0)
+    while (*name) {
+        if (!(legal[*name / 8] & (1 << (*name % 8))))
             *name = '_';
         name++;
     }
@@ -489,13 +498,14 @@ XkbFileCreate(struct xkb_context *ctx, enum xkb_file_type type, char *name,
     if (!file)
         return NULL;
 
-    EnsureSafeMapName(name);
+    EscapeMapName(name);
     file->file_type = type;
     file->topName = strdup_safe(name);
     file->name = name;
     file->defs = defs;
     file->id = xkb_context_take_file_id(ctx);
     file->flags = flags;
+
     return file;
 }
 
@@ -700,6 +710,7 @@ static const char *xkb_file_type_strings[_FILE_TYPE_NUM_ENTRIES] = {
     [FILE_TYPE_TYPES] = "xkb_types",
     [FILE_TYPE_COMPAT] = "xkb_compatibility",
     [FILE_TYPE_SYMBOLS] = "xkb_symbols",
+    [FILE_TYPE_GEOMETRY] = "xkb_geometry",
     [FILE_TYPE_KEYMAP] = "xkb_keymap",
     [FILE_TYPE_RULES] = "rules",
 };