Commit 4c34bda15a4f8c8a16fa03d40bcf989db23023dd

Ran Benita 2012-08-10T22:38:07

action: get rid of xkb_any_action And use union xkb_action instead. We add xkb_private_action, which is the same as xkb_any_action, but only used where the intention is clear. This should take care of whatever sizing changes the action struct might have. 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
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
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index f04f6cc..f406f31 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -397,9 +397,9 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
     if (!suffix)
         suffix = "";
 
-    type = ActionTypeText(action->any.type);
+    type = ActionTypeText(action->type);
 
-    switch (action->any.type) {
+    switch (action->type) {
     case XkbSA_SetMods:
     case XkbSA_LatchMods:
     case XkbSA_LockMods:
@@ -408,10 +408,10 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
         else
             args = VModMaskText(keymap, action->mods.mods.mods);
         write_buf(buf, "%s%s(modifiers=%s%s%s)%s", prefix, type, args,
-                  (action->any.type != XkbSA_LockGroup &&
+                  (action->type != XkbSA_LockGroup &&
                    (action->mods.flags & XkbSA_ClearLocks)) ?
                    ",clearLocks" : "",
-                  (action->any.type != XkbSA_LockGroup &&
+                  (action->type != XkbSA_LockGroup &&
                    (action->mods.flags & XkbSA_LatchToLock)) ?
                    ",latchToLock" : "",
                   suffix);
@@ -425,10 +425,10 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
                    action->group.group > 0) ? "+" : "",
                   (action->group.flags & XkbSA_GroupAbsolute) ?
                   action->group.group + 1 : action->group.group,
-                  (action->any.type != XkbSA_LockGroup &&
+                  (action->type != XkbSA_LockGroup &&
                    (action->group.flags & XkbSA_ClearLocks)) ?
                   ",clearLocks" : "",
-                  (action->any.type != XkbSA_LockGroup &&
+                  (action->type != XkbSA_LockGroup &&
                    (action->group.flags & XkbSA_LatchToLock)) ?
                   ",latchToLock" : "",
                   suffix);
@@ -521,10 +521,10 @@ write_action(struct xkb_keymap *keymap, struct buf *buf,
     default:
         write_buf(buf,
                   "%s%s(type=0x%02x,data[0]=0x%02x,data[1]=0x%02x,data[2]=0x%02x,data[3]=0x%02x,data[4]=0x%02x,data[5]=0x%02x,data[6]=0x%02x)%s",
-                  prefix, type, action->any.type, action->any.data[0],
-                  action->any.data[1], action->any.data[2],
-                  action->any.data[3], action->any.data[4],
-                  action->any.data[5], action->any.data[6],
+                  prefix, type, action->type, action->priv.data[0],
+                  action->priv.data[1], action->priv.data[2],
+                  action->priv.data[3], action->priv.data[4],
+                  action->priv.data[5], action->priv.data[6],
                   suffix);
         break;
     }
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index f53805f..61ba590 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -148,11 +148,6 @@ struct xkb_mods {
     xkb_mod_mask_t mask;       /* computed effective mask */
 };
 
-struct xkb_any_action {
-    uint8_t type;
-    uint8_t data[7];
-};
-
 struct xkb_mod_action {
     uint8_t type;
     uint8_t flags;
@@ -240,8 +235,12 @@ struct xkb_pointer_button_action {
     int8_t button;
 };
 
+struct xkb_private_action {
+    uint8_t type;
+    uint8_t data[7];
+};
+
 union xkb_action {
-    struct xkb_any_action any;
     struct xkb_mod_action mods;
     struct xkb_group_action group;
     struct xkb_iso_action iso;
@@ -254,6 +253,7 @@ union xkb_action {
     struct xkb_pointer_action ptr;         /* XXX delete for DeviceValuator */
     struct xkb_pointer_button_action btn;  /* XXX delete for DeviceBtn */
     struct xkb_message_action msg;         /* XXX just delete */
+    struct xkb_private_action priv;
     unsigned char type;
 };
 
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index a2dd9ed..0d37688 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -219,7 +219,7 @@ ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
 }
 
 static bool
-HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
                unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 
 {
@@ -277,16 +277,15 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action,
 }
 
 static bool
-HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
                    unsigned field, const ExprDef *array_ndx,
                    const ExprDef *value)
 {
-    struct xkb_mod_action *act;
+    struct xkb_mod_action *act = &action->mods;
     unsigned rtrn;
     unsigned t1;
     xkb_mod_mask_t t2;
 
-    act = (struct xkb_mod_action *) action;
     if (array_ndx != NULL) {
         switch (field) {
         case F_ClearLocks:
@@ -318,14 +317,13 @@ HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
                unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 {
-    struct xkb_mod_action *act;
+    struct xkb_mod_action *act = &action->mods;
     unsigned t1;
     xkb_mod_mask_t t2;
 
-    act = (struct xkb_mod_action *) action;
     if ((array_ndx != NULL) && (field == F_Modifiers))
         return ReportActionNotArray(keymap, action->type, field);
     switch (field) {
@@ -370,16 +368,15 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
 }
 
 static bool
-HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
                     unsigned field, const ExprDef *array_ndx,
                     const ExprDef *value)
 {
-    struct xkb_group_action *act;
+    struct xkb_group_action *act = &action->group;
     unsigned rtrn;
     unsigned t1;
     xkb_group_index_t t2;
 
-    act = (struct xkb_group_action *) action;
     if (array_ndx != NULL) {
         switch (field) {
         case F_ClearLocks:
@@ -411,15 +408,14 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
                 unsigned field, const ExprDef *array_ndx,
                 const ExprDef *value)
 {
-    struct xkb_group_action *act;
+    struct xkb_group_action *act = &action->group;
     unsigned t1;
     xkb_group_index_t t2;
 
-    act = (struct xkb_group_action *) action;
     if ((array_ndx != NULL) && (field == F_Group))
         return ReportActionNotArray(keymap, action->type, field);
     if (field == F_Group) {
@@ -435,13 +431,12 @@ HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
               unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 {
-    struct xkb_pointer_action *act;
+    struct xkb_pointer_action *act = &action->ptr;
     bool absolute;
 
-    act = (struct xkb_pointer_action *) action;
     if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
         return ReportActionNotArray(keymap, action->type, field);
 
@@ -493,12 +488,11 @@ static const LookupEntry lockWhich[] = {
 };
 
 static bool
-HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
              unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 {
-    struct xkb_pointer_button_action *act;
+    struct xkb_pointer_button_action *act = &action->btn;
 
-    act = (struct xkb_pointer_button_action *) action;
     if (field == F_Button) {
         int btn;
 
@@ -564,13 +558,12 @@ static const LookupEntry ptrDflts[] = {
 };
 
 static bool
-HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
                  unsigned field, const ExprDef *array_ndx,
                  const ExprDef *value)
 {
-    struct xkb_pointer_default_action *act;
+    struct xkb_pointer_default_action *act = &action->dflt;
 
-    act = (struct xkb_pointer_default_action *) action;
     if (field == F_Affect) {
         unsigned int val;
 
@@ -638,12 +631,11 @@ static const LookupEntry isoNames[] = {
 };
 
 static bool
-HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
               unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 {
-    struct xkb_iso_action *act;
+    struct xkb_iso_action *act = &action->iso;
 
-    act = (struct xkb_iso_action *) action;
     if (field == F_Modifiers) {
         unsigned flags;
         xkb_mod_mask_t mods;
@@ -691,13 +683,12 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
                    unsigned field, const ExprDef *array_ndx,
                    const ExprDef *value)
 {
-    struct xkb_switch_screen_action *act;
+    struct xkb_switch_screen_action *act = &action->screen;
 
-    act = (struct xkb_switch_screen_action *) action;
     if (field == F_Screen) {
         const ExprDef *scrn;
         int val;
@@ -771,13 +762,12 @@ const LookupEntry ctrlNames[] = {
 
 static bool
 HandleSetLockControls(struct xkb_keymap *keymap,
-                      struct xkb_any_action *action,
+                      union xkb_action *action,
                       unsigned field, const ExprDef *array_ndx,
                       const ExprDef *value)
 {
-    struct xkb_controls_action *act;
+    struct xkb_controls_action *act = &action->ctrls;
 
-    act = (struct xkb_controls_action *) action;
     if (field == F_Controls) {
         unsigned int mask;
 
@@ -806,13 +796,12 @@ static const LookupEntry evNames[] = {
 };
 
 static bool
-HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
                     unsigned field, const ExprDef *array_ndx,
                     const ExprDef *value)
 {
-    struct xkb_message_action *act;
+    struct xkb_message_action *act = &action->msg;
 
-    act = (struct xkb_message_action *) action;
     if (field == F_Report) {
         unsigned int mask;
 
@@ -896,12 +885,12 @@ HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
                   unsigned field, const ExprDef *array_ndx,
                   const ExprDef *value)
 {
     struct xkb_key *key;
-    struct xkb_redirect_key_action *act;
+    struct xkb_redirect_key_action *act = &action->redirect;
     unsigned t1;
     xkb_mod_mask_t t2;
     unsigned long tmp;
@@ -910,7 +899,6 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
     if (array_ndx != NULL)
         return ReportActionNotArray(keymap, action->type, field);
 
-    act = (struct xkb_redirect_key_action *) action;
     switch (field) {
     case F_Keycode:
         if (!ExprResolveKeyName(keymap->ctx, value, key_name))
@@ -948,13 +936,12 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
                 unsigned field, const ExprDef *array_ndx,
                 const ExprDef *value)
 {
-    struct xkb_device_button_action *act;
+    struct xkb_device_button_action *act = &action->devbtn;
 
-    act = (struct xkb_device_button_action *) action;
     if (field == F_Button) {
         int val;
 
@@ -1034,24 +1021,23 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 static bool
-HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
                      unsigned field, const ExprDef *array_ndx,
                      const ExprDef *value)
 {
-#if 0
-    ExprResult rtrn;
-    struct xkb_device_valuator_action *act;
+    struct xkb_device_valuator_action *act = &action->devval;
+    (void) act;
 
-    act = (struct xkb_device_valuator_action *) action;
     /*  XXX - Not yet implemented */
-#endif
     return false;
 }
 
 static bool
-HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
+HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
               unsigned field, const ExprDef *array_ndx, const ExprDef *value)
 {
+    struct xkb_private_action *act = &action->priv;
+
     if (field == F_Type) {
         int type;
 
@@ -1065,7 +1051,7 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
             return false;
         }
 
-        action->type = (uint8_t) type;
+        act->type = (uint8_t) type;
         return true;
     }
     else if (field == F_Data) {
@@ -1084,7 +1070,7 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
                 return false;
             }
 
-            strncpy((char *) action->data, str, sizeof(action->data));
+            strncpy((char *) act->data, str, sizeof(act->data));
             return true;
         }
         else {
@@ -1097,16 +1083,16 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
                 return false;
             }
 
-            if (ndx < 0 || ndx >= sizeof(action->data)) {
+            if (ndx < 0 || ndx >= sizeof(act->data)) {
                 log_err(keymap->ctx,
                         "The data for a private action is %zu bytes long; "
                         "Attempt to use data[%d] ignored\n",
-                        sizeof(action->data), ndx);
+                        sizeof(act->data), ndx);
                 return false;
             }
 
             if (!ExprResolveInteger(keymap->ctx, value, &datum))
-                return ReportMismatch(keymap, action->type, field, "integer");
+                return ReportMismatch(keymap, act->type, field, "integer");
 
             if (datum < 0 || datum > 255) {
                 log_err(keymap->ctx,
@@ -1115,7 +1101,7 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
                 return false;
             }
 
-            action->data[ndx] = (uint8_t) datum;
+            act->data[ndx] = (uint8_t) datum;
             return true;
         }
     }
@@ -1124,7 +1110,7 @@ HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
 }
 
 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
-                              struct xkb_any_action *action, unsigned field,
+                              union xkb_action *action, unsigned field,
                               const ExprDef *array_ndx, const ExprDef *value);
 
 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
@@ -1170,7 +1156,7 @@ ApplyActionFactoryDefaults(union xkb_action * action)
 int
 HandleActionDef(ExprDef * def,
                 struct xkb_keymap *keymap,
-                struct xkb_any_action *action, ActionInfo *info)
+                union xkb_action *action, ActionInfo *info)
 {
     ExprDef *arg;
     const char *str;
diff --git a/src/xkbcomp/action.h b/src/xkbcomp/action.h
index 3d63468..5cf67d9 100644
--- a/src/xkbcomp/action.h
+++ b/src/xkbcomp/action.h
@@ -68,7 +68,7 @@ typedef struct _ActionInfo {
 
 extern int
 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
-                struct xkb_any_action *action,
+                union xkb_action *action,
                 ActionInfo *info);
 
 extern int
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 1fbf2b1..b00f64a 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -158,8 +158,6 @@ ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo * info)
 static void
 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
 {
-    unsigned int i;
-
     info->keymap = keymap;
     info->name = NULL;
     info->file_id = file_id;
@@ -172,9 +170,8 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
     info->dflt.merge = MERGE_OVERRIDE;
     info->dflt.interp.flags = 0;
     info->dflt.interp.virtual_mod = XkbNoModifier;
+    memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
     info->dflt.interp.act.type = XkbSA_NoAction;
-    for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
-        info->dflt.interp.act.any.data[i] = 0;
     ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
     info->ledDflt.file_id = file_id;
     info->ledDflt.defined = 0;
@@ -188,7 +185,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
 static void
 ClearCompatInfo(CompatInfo *info)
 {
-    unsigned int i;
     ActionInfo *next_act;
     SymInterpInfo *si, *next_si;
     LEDInfo *led, *next_led;
@@ -200,9 +196,8 @@ ClearCompatInfo(CompatInfo *info)
     info->dflt.merge = MERGE_AUGMENT;
     info->dflt.interp.flags = 0;
     info->dflt.interp.virtual_mod = XkbNoModifier;
+    memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
     info->dflt.interp.act.type = XkbSA_NoAction;
-    for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
-        info->dflt.interp.act.any.data[i] = 0;
     ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
     info->nInterps = 0;
     list_foreach_safe(si, next_si, &info->interps, entry)
@@ -640,7 +635,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
         if (arrayNdx)
             return ReportSINotArray(info, si, field);
 
-        if (!HandleActionDef(value, keymap, &si->interp.act.any, info->act))
+        if (!HandleActionDef(value, keymap, &si->interp.act, info->act))
             return false;
 
         si->defined |= SI_FIELD_ACTION;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 5993a9a..7574520 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -925,7 +925,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
     xkb_group_index_t ndx;
     size_t nActs;
     ExprDef *act;
-    struct xkb_any_action *toAct;
+    union xkb_action *toAct;
 
     if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
         return false;
@@ -970,7 +970,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
     }
     keyi->actsDefined |= (1 << ndx);
 
-    toAct = (struct xkb_any_action *) darray_mem(keyi->acts[ndx], 0);
+    toAct = darray_mem(keyi->acts[ndx], 0);
     act = value->value.child;
     for (i = 0; i < nActs; i++, toAct++) {
         if (!HandleActionDef(act, info->keymap, toAct, info->action)) {