Get rid of xkb_client_map We don't make this distinction anymore, and the separate allocations just make it harder to reason about. Since we require that all of symbols, types, compat etc. be present, we should just put stuff directly in the keymap struct. 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
diff --git a/src/alloc.c b/src/alloc.c
index 1e4b4d3..d29c740 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -27,38 +27,6 @@
#include "alloc.h"
int
-XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
- size_t nTotalTypes)
-{
- if (!keymap || ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes)))
- return BadValue;
-
- if (!keymap->map) {
- keymap->map = calloc(1, sizeof(*keymap->map));
- if (!keymap->map)
- return BadAlloc;
- darray_init(keymap->map->types);
- }
-
- if (which & XkbKeyTypesMask)
- darray_growalloc(keymap->map->types, nTotalTypes);
-
- if (which & XkbKeySymsMask)
- darray_resize0(keymap->map->key_sym_map, keymap->max_key_code + 1);
-
- if (which & XkbModifierMapMask) {
- if (!keymap->map->modmap) {
- keymap->map->modmap = uTypedCalloc(keymap->max_key_code + 1,
- unsigned char);
- if (!keymap->map->modmap)
- return BadAlloc;
- }
- }
-
- return Success;
-}
-
-int
XkbcAllocServerMap(struct xkb_keymap *keymap, unsigned which,
unsigned nNewActions)
{
@@ -158,7 +126,7 @@ bool
XkbcResizeKeySyms(struct xkb_keymap *keymap, xkb_keycode_t key,
unsigned int needed)
{
- darray_resize0(darray_item(keymap->map->key_sym_map, key).syms, needed);
+ darray_resize0(darray_item(keymap->key_sym_map, key).syms, needed);
return true;
}
@@ -203,19 +171,12 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t key,
return XkbKeyActionsPtr(keymap, key);
}
-void
-XkbcFreeClientMap(struct xkb_keymap *keymap)
+static void
+free_types(struct xkb_keymap *keymap)
{
- struct xkb_client_map * map;
- struct xkb_key_type * type;
- struct xkb_sym_map *sym_map;
-
- if (!keymap || !keymap->map)
- return;
-
- map = keymap->map;
+ struct xkb_key_type *type;
- darray_foreach(type, map->types) {
+ darray_foreach(type, keymap->types) {
int j;
darray_free(type->map);
free(type->preserve);
@@ -224,18 +185,20 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
free(type->level_names);
free(type->name);
}
- darray_free(map->types);
+ darray_free(keymap->types);
+}
+
+static void
+free_sym_maps(struct xkb_keymap *keymap)
+{
+ struct xkb_sym_map *sym_map;
- darray_foreach(sym_map, map->key_sym_map) {
+ darray_foreach(sym_map, keymap->key_sym_map) {
free(sym_map->sym_index);
free(sym_map->num_syms);
darray_free(sym_map->syms);
}
- darray_free(map->key_sym_map);
-
- free(map->modmap);
- free(keymap->map);
- keymap->map = NULL;
+ darray_free(keymap->key_sym_map);
}
void
@@ -306,10 +269,10 @@ XkbcAllocNames(struct xkb_keymap *keymap, unsigned which,
darray_init(keymap->names->key_aliases);
}
- if ((which & XkbKTLevelNamesMask) && keymap->map) {
+ if ((which & XkbKTLevelNamesMask) && keymap) {
struct xkb_key_type * type;
- darray_foreach(type, keymap->map->types) {
+ darray_foreach(type, keymap->types) {
if (!type->level_names) {
type->level_names = calloc(type->num_levels,
sizeof(*type->level_names));
@@ -332,7 +295,6 @@ static void
XkbcFreeNames(struct xkb_keymap *keymap)
{
struct xkb_names * names;
- struct xkb_client_map * map;
struct xkb_key_type *type;
int i;
@@ -340,16 +302,13 @@ XkbcFreeNames(struct xkb_keymap *keymap)
return;
names = keymap->names;
- map = keymap->map;
-
- if (map) {
- darray_foreach(type, map->types) {
- int j;
- for (j = 0; j < type->num_levels; j++)
- free(type->level_names[j]);
- free(type->level_names);
- type->level_names = NULL;
- }
+
+ darray_foreach(type, keymap->types) {
+ int j;
+ for (j = 0; j < type->num_levels; j++)
+ free(type->level_names[j]);
+ free(type->level_names);
+ type->level_names = NULL;
}
free(names->keycodes);
@@ -445,7 +404,9 @@ XkbcFreeKeyboard(struct xkb_keymap *keymap)
if (!keymap)
return;
- XkbcFreeClientMap(keymap);
+ free_types(keymap);
+ free_sym_maps(keymap);
+ free(keymap->modmap);
XkbcFreeServerMap(keymap);
XkbcFreeCompatMap(keymap);
XkbcFreeIndicatorMaps(keymap);
diff --git a/src/alloc.h b/src/alloc.h
index ed5983e..bea53cf 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -49,10 +49,6 @@ extern void
XkbcFreeKeyboard(struct xkb_keymap *keymap);
extern int
-XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
- size_t nTotalTypes);
-
-extern int
XkbcAllocServerMap(struct xkb_keymap *keymap, unsigned which,
unsigned nNewActions);
@@ -68,9 +64,6 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t key,
uint32_t needed);
extern void
-XkbcFreeClientMap(struct xkb_keymap *keymap);
-
-extern void
XkbcFreeServerMap(struct xkb_keymap *keymap);
#endif /* ALLOC_H */
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index e04a996..6870ca7 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -364,7 +364,7 @@ write_types(struct xkb_keymap *keymap, char **buf, size_t *size,
write_vmods(keymap, buf, size, offset);
- darray_foreach(type, keymap->map->types) {
+ darray_foreach(type, keymap->types) {
write_buf(keymap, buf, size, offset, "\t\ttype \"%s\" {\n",
type->name);
write_buf(keymap, buf, size, offset, "\t\t\tmodifiers= %s;\n",
@@ -779,7 +779,6 @@ static bool
write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
size_t *offset)
{
- struct xkb_client_map *map = keymap->map;
struct xkb_server_map *srv = keymap->server;
xkb_keycode_t key;
int group, tmp;
@@ -834,13 +833,13 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
write_buf(keymap, buf, size, offset,
"\n\t\t\ttype[group%d]= \"%s\",",
group + 1,
- darray_item(map->types, type).name);
+ darray_item(keymap->types, type).name);
}
}
else {
write_buf(keymap, buf, size, offset,
"\n\t\t\ttype= \"%s\",",
- darray_item(map->types, type).name);
+ darray_item(keymap->types, type).name);
}
}
if (keymap->ctrls &&
@@ -922,16 +921,16 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
write_buf(keymap, buf, size, offset, "\n\t\t};\n");
}
}
- if (map && map->modmap) {
+ if (keymap->modmap) {
for (key = keymap->min_key_code; key <= keymap->max_key_code;
key++) {
int mod;
- if (map->modmap[key] == 0)
+ if (keymap->modmap[key] == 0)
continue;
for (mod = 0; mod < XkbNumModifiers; mod++) {
- if (!(map->modmap[key] & (1 << mod)))
+ if (!(keymap->modmap[key] & (1 << mod)))
continue;
write_buf(keymap, buf, size, offset,
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index e21b449..bb7410c 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -275,12 +275,6 @@ struct xkb_sym_map {
darray(xkb_keysym_t) syms;
};
-struct xkb_client_map {
- darray(struct xkb_key_type) types;
- darray(struct xkb_sym_map) key_sym_map;
- unsigned char *modmap;
-};
-
struct xkb_behavior {
unsigned char type;
unsigned char data;
@@ -361,10 +355,13 @@ struct xkb_keymap {
struct xkb_controls * ctrls;
struct xkb_server_map * server;
- struct xkb_client_map * map;
struct xkb_indicator * indicators;
struct xkb_names * names;
struct xkb_compat_map * compat;
+
+ darray(struct xkb_key_type) types;
+ darray(struct xkb_sym_map) key_sym_map;
+ unsigned char *modmap;
};
#define XkbNumGroups(g) ((g) & 0x0f)
@@ -377,22 +374,22 @@ struct xkb_keymap {
#define XkbSetNumGroups(g, n) (((g) & 0xf0) | ((n) & 0x0f))
#define XkbKeyGroupInfo(d, k) \
- (darray_item((d)->map->key_sym_map, k).group_info)
+ (darray_item((d)->key_sym_map, k).group_info)
#define XkbKeyNumGroups(d, k) \
- (XkbNumGroups(darray_item((d)->map->key_sym_map, k).group_info))
+ (XkbNumGroups(darray_item((d)->key_sym_map, k).group_info))
#define XkbKeyGroupWidth(d, k, g) \
(XkbKeyType(d, k, g)->num_levels)
#define XkbKeyGroupsWidth(d, k) \
- (darray_item((d)->map->key_sym_map, k).width)
+ (darray_item((d)->key_sym_map, k).width)
#define XkbKeyTypeIndex(d, k, g) \
- (darray_item((d)->map->key_sym_map, k).kt_index[g & 0x3])
+ (darray_item((d)->key_sym_map, k).kt_index[g & 0x3])
#define XkbKeyType(d, k, g) \
- (&darray_item((d)->map->types, XkbKeyTypeIndex(d, k, g)))
+ (&darray_item((d)->types, XkbKeyTypeIndex(d, k, g)))
#define XkbKeyNumSyms(d, k, g, sl) \
(darray_item((d)->map->key_sym_map, \
k).num_syms[(g * XkbKeyGroupsWidth(d, k)) + sl])
#define XkbKeySym(d, k, n) \
- (&darray_item(darray_item((d)->map->key_sym_map, k).syms, n))
+ (&darray_item(darray_item((d)->key_sym_map, k).syms, n))
#define XkbKeySymOffset(d, k, g, sl) \
(darray_item((d)->map->key_sym_map, \
k).sym_index[(g * XkbKeyGroupsWidth(d, k)) + sl])
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 88d0ff5..ec743f2 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -853,7 +853,7 @@ FindInterpForKey(struct xkb_keymap *keymap, xkb_keycode_t key,
continue;
if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
- mods = keymap->map->modmap[key];
+ mods = keymap->modmap[key];
else
mods = 0;
@@ -994,12 +994,12 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
for (i = 0; i < XkbNumVirtualMods; i++) {
if (!(keymap->server->vmodmap[key] & (1 << i)))
continue;
- keymap->server->vmods[i] |= keymap->map->modmap[key];
+ keymap->server->vmods[i] |= keymap->modmap[key];
}
}
/* Now update the level masks for all the types to reflect the vmods. */
- darray_foreach(type, keymap->map->types) {
+ darray_foreach(type, keymap->types) {
uint32_t mask = 0;
int j;
type->mods.mask = type->mods.real_mods;
@@ -1021,7 +1021,7 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
for (i = 0; i < XkbKeyNumActions(keymap, key); i++) {
if (acts[i].any.type == XkbSA_NoAction)
continue;
- UpdateActionMods(keymap, &acts[i], keymap->map->modmap[key]);
+ UpdateActionMods(keymap, &acts[i], keymap->modmap[key]);
}
}
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 51ef217..7a0874b 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -1084,15 +1084,11 @@ static int
InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
int keypadVMod)
{
- struct xkb_client_map *map;
const struct xkb_key_type *from;
int rtrn;
- rtrn = XkbcAllocClientMap(keymap, XkbKeyTypesMask, XkbNumRequiredTypes);
- if (rtrn != Success)
- return rtrn;
+ darray_growalloc(keymap->types, XkbNumRequiredTypes);
- map = keymap->map;
if ((which & XkbAllRequiredTypes) == 0)
return Success;
@@ -1101,22 +1097,22 @@ InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
if (which & XkbOneLevelMask)
rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex],
- &darray_item(map->types, XkbOneLevelIndex));
+ &darray_item(keymap->types, XkbOneLevelIndex));
if ((which & XkbTwoLevelMask) && rtrn == Success)
rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex],
- &darray_item(map->types, XkbTwoLevelIndex));
+ &darray_item(keymap->types, XkbTwoLevelIndex));
if ((which & XkbAlphabeticMask) && rtrn == Success)
rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
- &darray_item(map->types, XkbAlphabeticIndex));
+ &darray_item(keymap->types, XkbAlphabeticIndex));
if ((which & XkbKeypadMask) && rtrn == Success) {
struct xkb_key_type *type;
rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex],
- &darray_item(map->types, XkbKeypadIndex));
- type = &darray_item(map->types, XkbKeypadIndex);
+ &darray_item(keymap->types, XkbKeypadIndex));
+ type = &darray_item(keymap->types, XkbKeypadIndex);
if (keypadVMod >= 0 && keypadVMod < XkbNumVirtualMods &&
rtrn == Success) {
@@ -1172,12 +1168,7 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
if ((info.stdPresent & XkbAlphabeticMask) == 0)
i++;
- if (XkbcAllocClientMap(keymap, XkbKeyTypesMask, i) != Success) {
- WSGO("Couldn't allocate client map\n");
- goto err_info;
- }
-
- darray_resize0(keymap->map->types, i);
+ darray_resize0(keymap->types, i);
if (XkbAllRequiredTypes & (~info.stdPresent)) {
unsigned missing, keypadVMod;
@@ -1191,29 +1182,29 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
}
if (missing & XkbOneLevelMask)
- darray_item(keymap->map->types, XkbOneLevelIndex).name =
+ darray_item(keymap->types, XkbOneLevelIndex).name =
xkb_atom_strdup(keymap->ctx, tok_ONE_LEVEL);
if (missing & XkbTwoLevelMask)
- darray_item(keymap->map->types, XkbTwoLevelIndex).name =
+ darray_item(keymap->types, XkbTwoLevelIndex).name =
xkb_atom_strdup(keymap->ctx, tok_TWO_LEVEL);
if (missing & XkbAlphabeticMask)
- darray_item(keymap->map->types, XkbAlphabeticIndex).name =
+ darray_item(keymap->types, XkbAlphabeticIndex).name =
xkb_atom_strdup(keymap->ctx, tok_ALPHABETIC);
if (missing & XkbKeypadMask)
- darray_item(keymap->map->types, XkbKeypadIndex).name =
+ darray_item(keymap->types, XkbKeypadIndex).name =
xkb_atom_strdup(keymap->ctx, tok_KEYPAD);
}
- next = &darray_item(keymap->map->types, XkbLastRequiredType + 1);
+ next = &darray_item(keymap->types, XkbLastRequiredType + 1);
for (i = 0, def = info.types; i < info.nTypes; i++) {
if (def->name == tok_ONE_LEVEL)
- type = &darray_item(keymap->map->types, XkbOneLevelIndex);
+ type = &darray_item(keymap->types, XkbOneLevelIndex);
else if (def->name == tok_TWO_LEVEL)
- type = &darray_item(keymap->map->types, XkbTwoLevelIndex);
+ type = &darray_item(keymap->types, XkbTwoLevelIndex);
else if (def->name == tok_ALPHABETIC)
- type = &darray_item(keymap->map->types, XkbAlphabeticIndex);
+ type = &darray_item(keymap->types, XkbAlphabeticIndex);
else if (def->name == tok_KEYPAD)
- type = &darray_item(keymap->map->types, XkbKeypadIndex);
+ type = &darray_item(keymap->types, XkbKeypadIndex);
else
type = next++;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 543b0e0..d1d6b0b 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1494,8 +1494,8 @@ FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
const char *name = xkb_atom_text(keymap->ctx, atom);
struct xkb_key_type *type;
- if (keymap && keymap->map) {
- darray_foreach(type, keymap->map->types) {
+ if (keymap) {
+ darray_foreach(type, keymap->types) {
if (strcmp(type->name, name) == 0) {
*type_rtrn = n;
return true;
@@ -1751,7 +1751,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
types[i] = XkbTwoLevelIndex;
}
/* if the type specifies fewer levels than the key has, shrink the key */
- type = &darray_item(keymap->map->types, types[i]);
+ type = &darray_item(keymap->types, types[i]);
if (type->num_levels < key->numLevels[i]) {
if (warningLevel > 0) {
WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
@@ -1785,7 +1785,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
else
outActs = NULL;
- sym_map = &darray_item(keymap->map->key_sym_map, kc);
+ sym_map = &darray_item(keymap->key_sym_map, kc);
if (key->defs.defined & _Key_GroupInfo)
i = key->groupInfo;
@@ -1887,7 +1887,7 @@ CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
}
return false;
}
- keymap->map->modmap[kc] |= (1 << entry->modifier);
+ keymap->modmap[kc] |= (1 << entry->modifier);
return true;
}
@@ -1924,12 +1924,11 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
goto err_info;
}
- if (XkbcAllocClientMap(keymap, XkbKeySymsMask | XkbModifierMapMask, 0)
- != Success) {
- WSGO("Could not allocate client map in CompileSymbols\n");
- ACTION("Symbols not added\n");
+ darray_resize0(keymap->key_sym_map, keymap->max_key_code + 1);
+ keymap->modmap = calloc(keymap->max_key_code + 1,
+ sizeof(*keymap->modmap));
+ if (!keymap->modmap)
goto err_info;
- }
if (XkbcAllocServerMap(keymap, XkbAllServerInfoMask, 32) != Success) {
WSGO("Could not allocate server map in CompileSymbols\n");