symbols: use darray in struct xkb_sym_map 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
diff --git a/src/alloc.c b/src/alloc.c
index d0b0618..d474a64 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -158,19 +158,7 @@ bool
XkbcResizeKeySyms(struct xkb_keymap *keymap, xkb_keycode_t key,
unsigned int needed)
{
- struct xkb_sym_map *sym_map = &darray_item(keymap->map->key_sym_map, key);
-
- if (sym_map->size_syms >= needed)
- return true;
-
- sym_map->syms = uTypedRecalloc(sym_map->syms, sym_map->size_syms,
- needed, xkb_keysym_t);
- if (!sym_map->syms) {
- sym_map->size_syms = 0;
- return false;
- }
-
- sym_map->size_syms = needed;
+ darray_resize0(darray_item(keymap->map->key_sym_map, key).syms, needed);
return true;
}
@@ -241,7 +229,7 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
darray_foreach(sym_map, map->key_sym_map) {
free(sym_map->sym_index);
free(sym_map->num_syms);
- free(sym_map->syms);
+ darray_free(sym_map->syms);
}
darray_free(map->key_sym_map);
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 6493aea..e421fd9 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -274,8 +274,7 @@ struct xkb_sym_map {
unsigned char width;
int *sym_index; /* per level/group index into 'syms' */
unsigned int *num_syms; /* per level/group */
- xkb_keysym_t *syms;
- unsigned int size_syms; /* size of 'syms' */
+ darray(xkb_keysym_t) syms;
};
struct xkb_client_map {
@@ -389,7 +388,7 @@ struct xkb_keymap {
#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((d)->map->key_sym_map, k).syms[n])
+ (&darray_item(darray_item((d)->map->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])
#define XkbKeySymEntry(d, k, g, sl) \
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index f3b16ec..f464416 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1942,7 +1942,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
if (tmp < key->numLevels[i] &&
darray_item(key->symsMapNumEntries[i], tmp) != 0)
{
- memcpy(&sym_map->syms[symIndex],
+ memcpy(darray_mem(sym_map->syms, symIndex),
darray_mem(key->syms[i],
darray_item(key->symsMapIndex[i], tmp)),
darray_item(key->symsMapNumEntries[i], tmp) * sizeof(xkb_keysym_t));