keymap: don't use darray for keymap->keys

It's never resized.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-10-10 17:51:06 +02:00
parent bdea377c93
commit f3732d8349
3 changed files with 22 additions and 17 deletions

View File

@ -89,16 +89,18 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
if (!keymap || --keymap->refcnt > 0)
return;
darray_foreach(key, keymap->keys) {
for (i = 0; i < key->num_groups; i++) {
for (j = 0; j < XkbKeyGroupWidth(key, i); j++)
if (key->groups[i].levels[j].num_syms > 1)
free(key->groups[i].levels[j].u.syms);
free(key->groups[i].levels);
if (keymap->keys) {
xkb_foreach_key(key, keymap) {
for (i = 0; i < key->num_groups; i++) {
for (j = 0; j < XkbKeyGroupWidth(key, i); j++)
if (key->groups[i].levels[j].num_syms > 1)
free(key->groups[i].levels[j].u.syms);
free(key->groups[i].levels);
}
free(key->groups);
}
free(key->groups);
free(keymap->keys);
}
darray_free(keymap->keys);
for (i = 0; i < keymap->num_types; i++) {
free(keymap->types[i].map);
free(keymap->types[i].level_names);

View File

@ -382,8 +382,7 @@ struct xkb_keymap {
xkb_keycode_t min_key_code;
xkb_keycode_t max_key_code;
darray(struct xkb_key) keys;
struct xkb_key *keys;
/* aliases in no particular order */
darray(struct xkb_key_alias) key_aliases;
@ -412,11 +411,13 @@ XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
if (kc < keymap->min_key_code || kc > keymap->max_key_code)
return NULL;
return &darray_item(keymap->keys, kc);
return &keymap->keys[kc];
}
#define xkb_foreach_key(iter, keymap) \
darray_foreach(iter, keymap->keys)
for (iter = keymap->keys + keymap->min_key_code; \
iter <= keymap->keys + keymap->max_key_code; \
iter++)
static inline xkb_level_index_t
XkbKeyGroupWidth(const struct xkb_key *key, xkb_layout_index_t layout)

View File

@ -97,7 +97,7 @@
* The 'name' field of indicators declared in xkb_keycodes:
* struct xkb_indicator_map indicators[XKB_NUM_INDICATORS];
* Further, the array of keys:
* darray(struct xkb_key) keys;
* struct xkb_key *keys;
* had been resized to its final size (i.e. all of the xkb_key objects are
* referable by their keycode). However the objects themselves do not
* contain any useful information besides the key name at this point.
@ -690,14 +690,16 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
xkb_keycode_t kc;
xkb_led_index_t idx;
keymap->keys = calloc(info->max_key_code + 1, sizeof(*keymap->keys));
if (!keymap->keys)
return false;
keymap->min_key_code = info->min_key_code;
keymap->max_key_code = info->max_key_code;
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info->min_key_code; kc <= info->max_key_code; kc++) {
struct xkb_key *key = &darray_item(keymap->keys, kc);
key->keycode = kc;
key->name = darray_item(info->key_names, kc).name;
keymap->keys[kc].keycode = kc;
keymap->keys[kc].name = darray_item(info->key_names, kc).name;
}
keymap->keycodes_section_name = strdup_safe(info->name);