symbols: use darray for 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 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
diff --git a/src/alloc.c b/src/alloc.c
index b768da0..3106a08 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -43,14 +43,8 @@ XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
if (which & XkbKeyTypesMask)
darray_growalloc(keymap->map->types, nTotalTypes);
- if (which & XkbKeySymsMask) {
- if (!keymap->map->key_sym_map) {
- keymap->map->key_sym_map = uTypedCalloc(keymap->max_key_code + 1,
- struct xkb_sym_map);
- if (!keymap->map->key_sym_map)
- return BadAlloc;
- }
- }
+ if (which & XkbKeySymsMask)
+ darray_resize0(keymap->map->key_sym_map, keymap->max_key_code + 1);
if (which & XkbModifierMapMask) {
if (!keymap->map->modmap) {
@@ -193,20 +187,20 @@ bool
XkbcResizeKeySyms(struct xkb_keymap *keymap, xkb_keycode_t key,
unsigned int needed)
{
- if (keymap->map->key_sym_map[key].size_syms >= needed)
+ struct xkb_sym_map *sym_map =
+ &darray_item(keymap->map->key_sym_map, key);
+
+ if (sym_map->size_syms >= needed)
return true;
- keymap->map->key_sym_map[key].syms =
- uTypedRecalloc(keymap->map->key_sym_map[key].syms,
- keymap->map->key_sym_map[key].size_syms,
- needed,
- xkb_keysym_t);
- if (!keymap->map->key_sym_map[key].syms) {
- keymap->map->key_sym_map[key].size_syms = 0;
+ 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;
}
- keymap->map->key_sym_map[key].size_syms = needed;
+ sym_map->size_syms = needed;
return true;
}
@@ -276,7 +270,7 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
{
struct xkb_client_map * map;
struct xkb_key_type * type;
- xkb_keycode_t key;
+ struct xkb_sym_map *sym_map;
if (!keymap || !keymap->map)
return;
@@ -294,14 +288,12 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
}
darray_free(map->types);
- if (map->key_sym_map) {
- for (key = keymap->min_key_code; key < keymap->max_key_code; key++) {
- free(map->key_sym_map[key].sym_index);
- free(map->key_sym_map[key].num_syms);
- free(map->key_sym_map[key].syms);
- }
+ darray_foreach(sym_map, map->key_sym_map) {
+ free(sym_map->sym_index);
+ free(sym_map->num_syms);
+ free(sym_map->syms);
}
- free(map->key_sym_map);
+ darray_free(map->key_sym_map);
free(map->modmap);
free(keymap->map);
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 3d60af7..0d6f137 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -280,8 +280,8 @@ struct xkb_sym_map {
struct xkb_client_map {
darray(struct xkb_key_type) types;
- struct xkb_sym_map * key_sym_map;
- unsigned char *modmap;
+ darray(struct xkb_sym_map) key_sym_map;
+ unsigned char *modmap;
};
struct xkb_behavior {
@@ -370,39 +370,52 @@ struct xkb_keymap {
struct xkb_compat_map * compat;
};
-#define XkbNumGroups(g) ((g)&0x0f)
-#define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
-#define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
-#define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
-#define XkbSetGroupInfo(g,w,n) (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
-#define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
-
-#define XkbKeyGroupInfo(d,k) ((d)->map->key_sym_map[k].group_info)
-#define XkbKeyNumGroups(d,k) (XkbNumGroups((d)->map->key_sym_map[k].group_info))
-#define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
-#define XkbKeyGroupsWidth(d,k) ((d)->map->key_sym_map[k].width)
-#define XkbKeyTypeIndex(d,k,g) ((d)->map->key_sym_map[k].kt_index[g&0x3])
-#define XkbKeyType(d,k,g) (&darray_item((d)->map->types, XkbKeyTypeIndex(d,k,g)))
-#define XkbKeyNumSyms(d,k,g,sl) \
- ((d)->map->key_sym_map[k].num_syms[(g*XkbKeyGroupsWidth(d,k))+sl])
-#define XkbKeySym(d,k,n) (&(d)->map->key_sym_map[k].syms[n])
-#define XkbKeySymOffset(d,k,g,sl) \
- ((d)->map->key_sym_map[k].sym_index[(g*XkbKeyGroupsWidth(d,k))+sl])
-#define XkbKeySymEntry(d,k,g,sl) \
- (XkbKeySym(d,k,XkbKeySymOffset(d,k,g,sl)))
-#define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0)
-#define XkbKeyNumActions(d,k) \
- (XkbKeyHasActions(d,k)?(XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k)):1)
-#define XkbKeyActionsPtr(d,k) (&(d)->server->acts[(d)->server->key_acts[k]])
-#define XkbKeyAction(d,k,n) \
- (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
-#define XkbKeyActionEntry(d,k,sl,g) \
- (XkbKeyHasActions(d,k)?\
- XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
-
-#define XkbKeycodeInRange(d,k) (((k)>=(d)->min_key_code)&&\
- ((k)<=(d)->max_key_code))
-#define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
+#define XkbNumGroups(g) ((g) & 0x0f)
+#define XkbOutOfRangeGroupInfo(g) ((g) & 0xf0)
+#define XkbOutOfRangeGroupAction(g) ((g) & 0xc0)
+#define XkbOutOfRangeGroupNumber(g) (((g) & 0x30) >> 4)
+#define XkbSetGroupInfo(g, w, n) (((w) & 0xc0) | (((n) & 3) << 4) | ((g) & 0x0f))
+#define XkbSetNumGroups(g, n) (((g) & 0xf0) | ((n) & 0x0f))
+
+#define XkbKeyGroupInfo(d, k) \
+ (darray_item((d)->map->key_sym_map, k).group_info)
+#define XkbKeyNumGroups(d, k) \
+ (XkbNumGroups(darray_item((d)->map->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)
+#define XkbKeyTypeIndex(d, k, g) \
+ (darray_item((d)->map->key_sym_map, k).kt_index[g & 0x3])
+#define XkbKeyType(d, k, g) \
+ (&darray_item((d)->map->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((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) \
+ (XkbKeySym(d, k, XkbKeySymOffset(d, k, g, sl)))
+#define XkbKeyHasActions(d, k) \
+ ((d)->server->key_acts[k] != 0)
+#define XkbKeyNumActions(d, k) \
+ (XkbKeyHasActions(d, k) ? \
+ (XkbKeyGroupsWidth(d, k) * XkbKeyNumGroups(d, k)) : \
+ 1)
+#define XkbKeyActionsPtr(d, k) \
+ (&(d)->server->acts[(d)->server->key_acts[k]])
+#define XkbKeyAction(d, k, n) \
+ (XkbKeyHasActions(d, k) ? &XkbKeyActionsPtr(d, k)[n] : NULL)
+#define XkbKeyActionEntry(d, k, sl, g) \
+ (XkbKeyHasActions(d, k) ? \
+ XkbKeyAction(d, k, ((XkbKeyGroupsWidth(d, k) * (g)) + (sl))) : \
+ NULL)
+
+#define XkbKeycodeInRange(d, k) \
+ (((k) >= (d)->min_key_code) && ((k) <= (d)->max_key_code))
+#define XkbNumKeys(d) \
+ ((d)->max_key_code - (d)->min_key_code + 1)
struct xkb_state {
xkb_group_index_t base_group; /**< depressed */
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 9ebbf92..aba73f3 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1929,6 +1929,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
unsigned types[XkbNumKbdGroups];
union xkb_action *outActs;
unsigned int symIndex = 0;
+ struct xkb_sym_map *sym_map;
useAlias = (start_from == 0);
@@ -2030,17 +2031,19 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
}
else
outActs = NULL;
+
+ sym_map = &darray_item(keymap->map->key_sym_map, kc);
+
if (key->defs.defined & _Key_GroupInfo)
i = key->groupInfo;
else
- i = keymap->map->key_sym_map[kc].group_info;
-
- keymap->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
- keymap->map->key_sym_map[kc].width = width;
- keymap->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width,
- int);
- keymap->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
- unsigned int);
+ i = sym_map->group_info;
+
+ sym_map->group_info = XkbSetNumGroups(i, nGroups);
+ sym_map->width = width;
+ sym_map->sym_index = uTypedCalloc(nGroups * width, int);
+ sym_map->num_syms = uTypedCalloc(nGroups * width, unsigned int);
+
for (i = 0; i < nGroups; i++)
{
/* assign kt_index[i] to the index of the type in map->types.
@@ -2051,7 +2054,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
* FIXME: There should be a better fix for this.
*/
if (key->numLevels[i])
- keymap->map->key_sym_map[kc].kt_index[i] = types[i];
+ sym_map->kt_index[i] = types[i];
if (key->sizeSyms[i] != 0)
{
/* fill key to "width" symbols*/
@@ -2059,21 +2062,19 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
{
if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
{
- memcpy(&keymap->map->key_sym_map[kc].syms[symIndex],
+ memcpy(&sym_map->syms[symIndex],
&key->syms[i][key->symsMapIndex[i][tmp]],
key->symsMapNumEntries[i][tmp] *
sizeof(xkb_keysym_t));
- keymap->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
- symIndex;
- keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
+ sym_map->sym_index[(i * width) + tmp] = symIndex;
+ sym_map->num_syms[(i * width) + tmp] =
key->symsMapNumEntries[i][tmp];
- symIndex +=
- keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp];
+ symIndex += sym_map->num_syms[(i * width) + tmp];
}
else
{
- keymap->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
- keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
+ sym_map->sym_index[(i * width) + tmp] = -1;
+ sym_map->num_syms[(i * width) + tmp] = 0;
}
if ((outActs != NULL) && (key->acts[i] != NULL))
{