compat: use darray for sym_interprets 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
diff --git a/src/alloc.c b/src/alloc.c
index ccdea78..2e61646 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -363,49 +363,21 @@ XkbcFreeServerMap(struct xkb_keymap *keymap)
int
XkbcAllocCompatMap(struct xkb_keymap *keymap, unsigned nSI)
{
- struct xkb_compat_map * compat;
- struct xkb_sym_interpret *prev_interpret;
-
if (!keymap)
return BadMatch;
- if (keymap->compat) {
- if (keymap->compat->size_si >= nSI)
- return Success;
-
- compat = keymap->compat;
- compat->size_si = nSI;
- if (!compat->sym_interpret)
- compat->num_si = 0;
-
- prev_interpret = compat->sym_interpret;
- compat->sym_interpret = uTypedRecalloc(compat->sym_interpret,
- compat->num_si, nSI,
- struct xkb_sym_interpret);
- if (!compat->sym_interpret) {
- free(prev_interpret);
- compat->size_si = compat->num_si = 0;
+ if (!keymap->compat) {
+ keymap->compat = calloc(1, sizeof(*keymap->compat));
+ if (!keymap->compat)
return BadAlloc;
- }
-
- return Success;
+ darray_init(keymap->compat->sym_interpret);
}
- compat = uTypedCalloc(1, struct xkb_compat_map);
- if (!compat)
- return BadAlloc;
+ darray_growalloc(keymap->compat->sym_interpret, nSI);
+ darray_resize(keymap->compat->sym_interpret, 0);
- if (nSI > 0) {
- compat->sym_interpret = uTypedCalloc(nSI, struct xkb_sym_interpret);
- if (!compat->sym_interpret) {
- free(compat);
- return BadAlloc;
- }
- }
- compat->size_si = nSI;
- compat->num_si = 0;
- memset(&compat->groups[0], 0, XkbNumKbdGroups * sizeof(struct xkb_mods));
- keymap->compat = compat;
+ memset(keymap->compat->groups, 0,
+ XkbNumKbdGroups * sizeof(*keymap->compat->groups));
return Success;
}
@@ -414,15 +386,11 @@ XkbcAllocCompatMap(struct xkb_keymap *keymap, unsigned nSI)
static void
XkbcFreeCompatMap(struct xkb_keymap *keymap)
{
- struct xkb_compat_map * compat;
-
if (!keymap || !keymap->compat)
return;
- compat = keymap->compat;
-
- free(compat->sym_interpret);
- free(compat);
+ darray_free(keymap->compat->sym_interpret);
+ free(keymap->compat);
keymap->compat = NULL;
}
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index d89287b..db07442 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -265,10 +265,8 @@ struct xkb_sym_interpret {
};
struct xkb_compat_map {
- struct xkb_sym_interpret * sym_interpret;
+ darray(struct xkb_sym_interpret) sym_interpret;
struct xkb_mods groups[XkbNumKbdGroups];
- unsigned short num_si;
- unsigned short size_si;
};
struct xkb_sym_map {
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index a2a4143..2cb3905 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -776,13 +776,7 @@ CopyInterps(CompatInfo * info,
(needSymbol && (si->interp.sym == XKB_KEY_NoSymbol)) ||
((!needSymbol) && (si->interp.sym != XKB_KEY_NoSymbol)))
continue;
- if (compat->num_si >= compat->size_si)
- {
- WSGO("No room to merge symbol interpretations\n");
- ACTION("Symbol interpretations lost\n");
- return;
- }
- compat->sym_interpret[compat->num_si++] = si->interp;
+ darray_append(compat->sym_interpret, si->interp);
}
}
@@ -893,16 +887,15 @@ FindInterpForKey(struct xkb_keymap *keymap, xkb_keycode_t key,
uint32_t group, uint32_t level)
{
struct xkb_sym_interpret *ret = NULL;
+ struct xkb_sym_interpret *interp;
const xkb_keysym_t *syms;
int num_syms;
- int i;
num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
if (num_syms == 0)
return NULL;
- for (i = 0; i < keymap->compat->num_si; i++) {
- struct xkb_sym_interpret *interp = &keymap->compat->sym_interpret[i];
+ darray_foreach(interp, keymap->compat->sym_interpret) {
uint32_t mods;
bool found;