parser: use darray for keysym list 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
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index 885ec30..7a6afa7 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -385,59 +385,6 @@ ActionCreate(xkb_atom_t name, ExprDef * args)
return NULL;
}
-static bool
-ResizeKeysymList(ExprDef *list, unsigned int extra)
-{
- int i;
-
- if (list->value.list.nSyms + extra > list->value.list.szSyms)
- {
- list->value.list.szSyms *= 2;
- list->value.list.szSyms += extra;
- if (list->value.list.szSyms == 1)
- list->value.list.szSyms = 4;
- list->value.list.syms = uTypedRecalloc(list->value.list.syms,
- list->value.list.nSyms,
- list->value.list.szSyms,
- char *);
- if (list->value.list.syms == NULL)
- {
- FATAL("Couldn't resize list of symbols for append\n");
- return false;
- }
- }
- if (list->value.list.nLevels >= list->value.list.szLevels)
- {
- list->value.list.szLevels *= 2;
- if (list->value.list.szLevels == 0)
- list->value.list.szLevels = 4;
- list->value.list.symsMapIndex =
- uTypedRecalloc(list->value.list.symsMapIndex,
- list->value.list.nLevels,
- list->value.list.szLevels,
- int);
- if (list->value.list.symsMapIndex == NULL)
- {
- FATAL("Couldn't resize keysym index map for append\n");
- return false;
- }
- list->value.list.symsNumEntries =
- uTypedRecalloc(list->value.list.symsNumEntries,
- list->value.list.nLevels,
- list->value.list.szLevels,
- unsigned int);
- if (list->value.list.symsNumEntries == NULL)
- {
- FATAL("Couldn't resize num keysym entries for append\n");
- return false;
- }
- for (i = list->value.list.nLevels; i < list->value.list.szLevels; i++)
- list->value.list.symsMapIndex[i] = -1;
- }
-
- return true;
-}
-
ExprDef *
CreateKeysymList(char *sym)
{
@@ -450,25 +397,13 @@ CreateKeysymList(char *sym)
return NULL;
}
- def->value.list.nSyms = 0;
- def->value.list.szSyms = 0;
- def->value.list.nLevels = 0;
- def->value.list.szLevels = 0;
- def->value.list.syms = NULL;
- def->value.list.symsMapIndex = NULL;
- def->value.list.symsNumEntries = NULL;
+ darray_init(def->value.list.syms);
+ darray_init(def->value.list.symsMapIndex);
+ darray_init(def->value.list.symsNumEntries);
- if (!ResizeKeysymList(def, 1))
- {
- FreeStmt(&def->common);
- return NULL;
- }
-
- def->value.list.syms[0] = sym;
- def->value.list.symsMapIndex[0] = 0;
- def->value.list.symsNumEntries[0] = 1;
- def->value.list.nLevels = 1;
- def->value.list.nSyms = 1;
+ darray_append(def->value.list.syms, sym);
+ darray_append(def->value.list.symsMapIndex, 0);
+ darray_append(def->value.list.symsNumEntries, 1);
return def;
}
@@ -476,16 +411,12 @@ CreateKeysymList(char *sym)
ExprDef *
CreateMultiKeysymList(ExprDef *list)
{
- int i;
+ size_t nLevels = darray_size(list->value.list.symsMapIndex);
- for (i = 1; i < list->value.list.szLevels; i++)
- {
- list->value.list.symsMapIndex[i] = -1;
- list->value.list.symsNumEntries[i] = 0;
- }
- list->value.list.symsMapIndex[0] = 0;
- list->value.list.symsNumEntries[0] = list->value.list.nLevels;
- list->value.list.nLevels = 1;
+ darray_resize(list->value.list.symsMapIndex, 1);
+ darray_resize(list->value.list.symsNumEntries, 1);
+ darray_item(list->value.list.symsMapIndex, 0) = 0;
+ darray_item(list->value.list.symsNumEntries, 0) = nLevels;
return list;
}
@@ -493,36 +424,28 @@ CreateMultiKeysymList(ExprDef *list)
ExprDef *
AppendKeysymList(ExprDef * list, char *sym)
{
- if (!ResizeKeysymList(list, 1))
- return NULL;
+ size_t nSyms = darray_size(list->value.list.syms);
+
+ darray_append(list->value.list.symsMapIndex, nSyms);
+ darray_append(list->value.list.symsNumEntries, 1);
+ darray_append(list->value.list.syms, sym);
- list->value.list.symsMapIndex[list->value.list.nLevels] =
- list->value.list.nSyms;
- list->value.list.symsNumEntries[list->value.list.nLevels] = 1;
- list->value.list.syms[list->value.list.nSyms++] = sym;
- list->value.list.nLevels++;
return list;
}
ExprDef *
AppendMultiKeysymList(ExprDef * list, ExprDef * append)
{
- int i;
+ size_t nSyms = darray_size(list->value.list.syms);
+ size_t numEntries = darray_size(append->value.list.syms);
- if (!ResizeKeysymList(list, append->value.list.nSyms))
- return NULL;
-
- list->value.list.symsMapIndex[list->value.list.nLevels] =
- list->value.list.nSyms;
- list->value.list.symsNumEntries[list->value.list.nLevels] =
- append->value.list.nSyms;
- for (i = 0; i < append->value.list.nSyms; i++) {
- list->value.list.syms[list->value.list.nSyms++] =
- append->value.list.syms[i];
- append->value.list.syms[i] = NULL;
- }
- list->value.list.nLevels++;
+ darray_append(list->value.list.symsMapIndex, nSyms);
+ darray_append(list->value.list.symsNumEntries, numEntries);
+ darray_append_items(list->value.list.syms,
+ &darray_item(append->value.list.syms, 0),
+ numEntries);
+ darray_resize(append->value.list.syms, 0);
FreeStmt(&append->common);
return list;
@@ -717,7 +640,7 @@ StmtSetMerge(ParseCommon * stmt, unsigned merge, struct YYLTYPE *loc, void *scan
static void
FreeExpr(ExprDef *expr)
{
- int i;
+ char **sym;
if (!expr)
return;
@@ -746,11 +669,11 @@ FreeExpr(ExprDef *expr)
FreeStmt(&expr->value.array.entry->common);
break;
case ExprKeysymList:
- for (i = 0; i < expr->value.list.nSyms; i++)
- free(expr->value.list.syms[i]);
- free(expr->value.list.syms);
- free(expr->value.list.symsMapIndex);
- free(expr->value.list.symsNumEntries);
+ darray_foreach(sym, expr->value.list.syms)
+ free(*sym);
+ darray_free(expr->value.list.syms);
+ darray_free(expr->value.list.symsMapIndex);
+ darray_free(expr->value.list.symsNumEntries);
break;
default:
break;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 8b371b9..58565c1 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1049,8 +1049,8 @@ AddSymbolsToKey(KeyInfo *key, struct xkb_keymap *keymap,
ACTION("Ignoring duplicate definition\n");
return false;
}
- nSyms = value->value.list.nSyms;
- nLevels = value->value.list.nLevels;
+ nSyms = darray_size(value->value.list.syms);
+ nLevels = darray_size(value->value.list.symsMapIndex);
if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
(!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
{
@@ -1061,15 +1061,21 @@ AddSymbolsToKey(KeyInfo *key, struct xkb_keymap *keymap,
}
key->symsDefined |= (1 << ndx);
for (i = 0; i < nLevels; i++) {
- key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
- key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
+ key->symsMapIndex[ndx][i] =
+ darray_item(value->value.list.symsMapIndex, i);
+ key->symsMapNumEntries[ndx][i] =
+ darray_item(value->value.list.symsNumEntries, i);
+
for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
if (key->symsMapIndex[ndx][i] + j >= nSyms)
abort();
- if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
+ if (!LookupKeysym(darray_item(value->value.list.syms,
+ darray_item(value->value.list.symsMapIndex, i) + j),
&key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
- value->value.list.syms[i], longText(key->name), ndx + 1,
+ darray_item(value->value.list.syms, i),
+ longText(key->name),
+ ndx + 1,
xkb_atom_text(keymap->ctx, info->groupNames[ndx]), nSyms);
while (--j >= 0)
key->syms[ndx][key->symsMapIndex[ndx][i] + j] = XKB_KEY_NoSymbol;
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index e16d96b..ec0db0f 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -131,13 +131,9 @@ typedef struct _Expr
} action;
struct
{
- int nSyms;
- int szSyms;
- char **syms;
- int nLevels;
- int szLevels;
- int *symsMapIndex;
- unsigned int *symsNumEntries;
+ darray(char *) syms;
+ darray(int) symsMapIndex;
+ darray(unsigned int) symsNumEntries;
} list;
struct _Expr *child;
xkb_atom_t str;