keytypes: use darray for key types in the client 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 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
diff --git a/src/alloc.c b/src/alloc.c
index 2e61646..a1d34bf 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -28,62 +28,35 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
int
XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
- unsigned nTotalTypes)
+ size_t nTotalTypes)
{
- struct xkb_client_map * map;
-
if (!keymap || ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes)))
return BadValue;
if (!keymap->map) {
- map = uTypedCalloc(1, struct xkb_client_map);
- if (!map)
+ keymap->map = calloc(1, sizeof(*keymap->map));
+ if (!keymap->map)
return BadAlloc;
- keymap->map = map;
+ darray_init(keymap->map->types);
}
- else
- map = keymap->map;
-
- if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) {
- if (!map->types) {
- map->types = uTypedCalloc(nTotalTypes, struct xkb_key_type);
- if (!map->types)
- return BadAlloc;
-
- map->num_types = 0;
- map->size_types = nTotalTypes;
- }
- else if (map->size_types < nTotalTypes) {
- struct xkb_key_type *prev_types = map->types;
-
- map->types = uTypedRealloc(map->types, nTotalTypes,
- struct xkb_key_type);
- if (!map->types) {
- free(prev_types);
- map->num_types = map->size_types = 0;
- return BadAlloc;
- }
- map->size_types = nTotalTypes;
- memset(&map->types[map->num_types], 0,
- (map->size_types - map->num_types) * sizeof(struct xkb_key_type));
- }
- }
+ if (which & XkbKeyTypesMask)
+ darray_growalloc(keymap->map->types, nTotalTypes);
if (which & XkbKeySymsMask) {
- if (!map->key_sym_map) {
- map->key_sym_map = uTypedCalloc(keymap->max_key_code + 1,
- struct xkb_sym_map);
- if (!map->key_sym_map)
+ 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 & XkbModifierMapMask) {
- if (!map->modmap) {
- map->modmap = uTypedCalloc(keymap->max_key_code + 1,
- unsigned char);
- if (!map->modmap)
+ if (!keymap->map->modmap) {
+ keymap->map->modmap = uTypedCalloc(keymap->max_key_code + 1,
+ unsigned char);
+ if (!keymap->map->modmap)
return BadAlloc;
}
}
@@ -309,14 +282,13 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
struct xkb_client_map * map;
struct xkb_key_type * type;
xkb_keycode_t key;
- int i;
if (!keymap || !keymap->map)
return;
map = keymap->map;
- for (i = 0, type = map->types; i < map->num_types && type; i++, type++) {
+ darray_foreach(type, map->types) {
int j;
free(type->map);
free(type->preserve);
@@ -325,7 +297,7 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
free(type->level_names);
free(UNCONSTIFY(type->name));
}
- free(map->types);
+ darray_free(map->types);
if (map->key_sym_map) {
for (key = keymap->min_key_code; key < keymap->max_key_code; key++) {
@@ -410,12 +382,10 @@ XkbcAllocNames(struct xkb_keymap *keymap, unsigned which,
}
names = keymap->names;
- if ((which & XkbKTLevelNamesMask) && keymap->map && keymap->map->types) {
- int i;
+ if ((which & XkbKTLevelNamesMask) && keymap->map) {
struct xkb_key_type * type;
- type = keymap->map->types;
- for (i = 0; i < keymap->map->num_types; i++, type++) {
+ darray_foreach(type, keymap->map->types) {
if (!type->level_names) {
type->level_names = uTypedCalloc(type->num_levels, const char *);
if (!type->level_names)
@@ -462,6 +432,7 @@ XkbcFreeNames(struct xkb_keymap *keymap)
{
struct xkb_names * names;
struct xkb_client_map * map;
+ struct xkb_key_type *type;
int i;
if (!keymap || !keymap->names)
@@ -470,10 +441,8 @@ XkbcFreeNames(struct xkb_keymap *keymap)
names = keymap->names;
map = keymap->map;
- if (map && map->types) {
- struct xkb_key_type * type = map->types;
-
- for (i = 0; i < map->num_types; i++, type++) {
+ if (map) {
+ darray_foreach(type, map->types) {
int j;
for (j = 0; j < type->num_levels; j++)
free(UNCONSTIFY(type->level_names[j]));
diff --git a/src/alloc.h b/src/alloc.h
index aec0249..c9a3314 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -50,7 +50,7 @@ XkbcFreeKeyboard(struct xkb_keymap *keymap);
extern int
XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
- unsigned nTotalTypes);
+ size_t nTotalTypes);
extern int
XkbcAllocServerMap(struct xkb_keymap *keymap, unsigned which,
diff --git a/src/misc.c b/src/misc.c
index 748d83c..ac54077 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -80,7 +80,7 @@ XkbcInitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
int keypadVMod)
{
struct xkb_client_map * map;
- struct xkb_key_type *from, *to;
+ struct xkb_key_type *from;
int rtrn;
if (!keymap)
@@ -96,23 +96,25 @@ XkbcInitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
rtrn = Success;
from = canonicalTypes;
- to = map->types;
if (which & XkbOneLevelMask)
- rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]);
+ rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex],
+ &darray_item(map->types, XkbOneLevelIndex));
if ((which & XkbTwoLevelMask) && (rtrn == Success))
- rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]);
+ rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex],
+ &darray_item(map->types, XkbTwoLevelIndex));
if ((which & XkbAlphabeticMask) && (rtrn == Success))
rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
- &to[XkbAlphabeticIndex]);
+ &darray_item(map->types, XkbAlphabeticIndex));
if ((which & XkbKeypadMask) && (rtrn == Success)) {
struct xkb_key_type * type;
- rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex], &to[XkbKeypadIndex]);
- type = &to[XkbKeypadIndex];
+ rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex],
+ &darray_item(map->types, XkbKeypadIndex));
+ type = &darray_item(map->types, XkbKeypadIndex);
if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) &&
(rtrn == Success)) {
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index db07442..876dbfd 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -280,9 +280,7 @@ struct xkb_sym_map {
};
struct xkb_client_map {
- unsigned char size_types;
- unsigned char num_types;
- struct xkb_key_type * types;
+ darray(struct xkb_key_type) types;
struct xkb_sym_map * key_sym_map;
unsigned char *modmap;
};
@@ -387,7 +385,7 @@ struct xkb_keymap {
#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) (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
+#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])
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 2cb3905..4b5caca 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1025,6 +1025,7 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
{
xkb_keycode_t key;
int i;
+ struct xkb_key_type *type;
/* Find all the interprets for the key and bind them to actions,
* which will also update the vmodmap. */
@@ -1046,8 +1047,7 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
}
/* Now update the level masks for all the types to reflect the vmods. */
- for (i = 0; i < keymap->map->num_types; i++) {
- struct xkb_key_type *type = &keymap->map->types[i];
+ darray_foreach(type, keymap->map->types) {
uint32_t mask = 0;
int j;
type->mods.mask = type->mods.real_mods;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index b8b019b..5914b32 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -1171,7 +1171,7 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
goto err_info;
}
- keymap->map->num_types = i;
+ darray_resize0(keymap->map->types, i);
if (XkbAllRequiredTypes & (~info.stdPresent)) {
unsigned missing, keypadVMod;
@@ -1185,29 +1185,29 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
}
if (missing & XkbOneLevelMask)
- keymap->map->types[XkbOneLevelIndex].name =
+ darray_item(keymap->map->types, XkbOneLevelIndex).name =
xkb_atom_strdup(keymap->ctx, tok_ONE_LEVEL);
if (missing & XkbTwoLevelMask)
- keymap->map->types[XkbTwoLevelIndex].name =
+ darray_item(keymap->map->types, XkbTwoLevelIndex).name =
xkb_atom_strdup(keymap->ctx, tok_TWO_LEVEL);
if (missing & XkbAlphabeticMask)
- keymap->map->types[XkbAlphabeticIndex].name =
+ darray_item(keymap->map->types, XkbAlphabeticIndex).name =
xkb_atom_strdup(keymap->ctx, tok_ALPHABETIC);
if (missing & XkbKeypadMask)
- keymap->map->types[XkbKeypadIndex].name =
+ darray_item(keymap->map->types, XkbKeypadIndex).name =
xkb_atom_strdup(keymap->ctx, tok_KEYPAD);
}
- next = &keymap->map->types[XkbLastRequiredType + 1];
+ next = &darray_item(keymap->map->types, XkbLastRequiredType + 1);
for (i = 0, def = info.types; i < info.nTypes; i++) {
if (def->name == tok_ONE_LEVEL)
- type = &keymap->map->types[XkbOneLevelIndex];
+ type = &darray_item(keymap->map->types, XkbOneLevelIndex);
else if (def->name == tok_TWO_LEVEL)
- type = &keymap->map->types[XkbTwoLevelIndex];
+ type = &darray_item(keymap->map->types, XkbTwoLevelIndex);
else if (def->name == tok_ALPHABETIC)
- type = &keymap->map->types[XkbAlphabeticIndex];
+ type = &darray_item(keymap->map->types, XkbAlphabeticIndex);
else if (def->name == tok_KEYPAD)
- type = &keymap->map->types[XkbKeypadIndex];
+ type = &darray_item(keymap->map->types, XkbKeypadIndex);
else
type = next++;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index f40bf9c..3ae10cf 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1696,18 +1696,17 @@ FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym,
static bool
FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
{
- unsigned n;
+ unsigned n = 0;
const char *name = xkb_atom_text(keymap->ctx, atom);
+ struct xkb_key_type *type;
- if (keymap && keymap->map && keymap->map->types)
- {
- for (n = 0; n < keymap->map->num_types; n++)
- {
- if (strcmp(keymap->map->types[n].name, name) == 0)
- {
+ if (keymap && keymap->map) {
+ darray_foreach(type, keymap->map->types) {
+ if (strcmp(type->name, name) == 0) {
*type_rtrn = n;
return true;
}
+ n++;
}
}
return false;
@@ -2005,7 +2004,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 = &keymap->map->types[types[i]];
+ type = &darray_item(keymap->map->types, types[i]);
if (type->num_levels < key->numLevels[i])
{
if (warningLevel > 0)