Remove alloc.{c,h} These functions are more appropriate elsewhere now. 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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
diff --git a/Makefile.am b/Makefile.am
index b9975e6..44859fa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -61,8 +61,6 @@ libxkbcommon_la_SOURCES = \
src/xkbcomp/xkbcomp.c \
src/xkbcomp/xkbcomp.h \
src/xkbcomp/xkbcomp-priv.h \
- src/alloc.c \
- src/alloc.h \
src/atom.c \
src/atom.h \
src/context.c \
diff --git a/src/alloc.c b/src/alloc.c
deleted file mode 100644
index b60b8ac..0000000
--- a/src/alloc.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
- *
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting
- * documentation, and that the name of Silicon Graphics not be
- * used in advertising or publicity pertaining to distribution
- * of the software without specific prior written permission.
- * Silicon Graphics makes no representation about the suitability
- * of this software for any purpose. It is provided "as is"
- * without any express or implied warranty.
- *
- * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- * THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "xkb-priv.h"
-#include "alloc.h"
-
-int
-XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into)
-{
- int i;
-
- if (!from || !into)
- return BadMatch;
-
- darray_free(into->map);
- free(into->preserve);
- free(into->level_names);
-
- *into = *from;
- darray_init(into->map);
-
- darray_copy(into->map, from->map);
-
- if (from->preserve && !darray_empty(into->map)) {
- into->preserve = calloc(darray_size(into->map),
- sizeof(*into->preserve));
- if (!into->preserve)
- return BadAlloc;
- memcpy(into->preserve, from->preserve,
- darray_size(into->map) * sizeof(*into->preserve));
- }
-
- if (from->level_names && into->num_levels > 0) {
- into->level_names = calloc(into->num_levels,
- sizeof(*into->level_names));
- if (!into->level_names)
- return BadAlloc;
-
- for (i = 0; i < into->num_levels; i++)
- into->level_names[i] = strdup(from->level_names[i]);
- }
-
- return Success;
-}
-
-union xkb_action *
-XkbcResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
- uint32_t needed)
-{
- size_t old_ndx, old_num_acts, new_ndx;
-
- if (needed == 0) {
- key->acts_index = 0;
- return NULL;
- }
-
- if (XkbKeyHasActions(key) && key->width >= needed)
- return XkbKeyActionsPtr(keymap, key);
-
- /*
- * The key may already be in the array, but without enough space.
- * This should not happen often, so in order to avoid moving and
- * copying stuff from acts and key_acts, we just allocate new
- * space for the key at the end, and leave the old space alone.
- */
-
- old_ndx = key->acts_index;
- old_num_acts = XkbKeyNumActions(key);
- new_ndx = darray_size(keymap->acts);
-
- darray_resize0(keymap->acts, new_ndx + needed);
- key->acts_index = new_ndx;
-
- /*
- * The key was already in the array, copy the old actions to the
- * new space.
- */
- if (old_ndx != 0)
- memcpy(darray_mem(keymap->acts, new_ndx),
- darray_mem(keymap->acts, old_ndx),
- old_num_acts * sizeof(union xkb_action));
-
- return XkbKeyActionsPtr(keymap, key);
-}
-
-static void
-free_types(struct xkb_keymap *keymap)
-{
- struct xkb_key_type *type;
-
- darray_foreach(type, keymap->types) {
- darray_free(type->map);
- free(type->preserve);
- free(type->level_names);
- }
- darray_free(keymap->types);
-}
-
-static void
-free_keys(struct xkb_keymap *keymap)
-{
- struct xkb_key *key;
-
- darray_foreach(key, keymap->keys) {
- free(key->sym_index);
- free(key->num_syms);
- darray_free(key->syms);
- }
-
- darray_free(keymap->keys);
-}
-
-struct xkb_keymap *
-XkbcAllocKeyboard(struct xkb_context *ctx)
-{
- struct xkb_keymap *keymap;
-
- keymap = calloc(1, sizeof(*keymap));
- if (!keymap)
- return NULL;
-
- keymap->refcnt = 1;
- keymap->ctx = xkb_context_ref(ctx);
-
- return keymap;
-}
-
-void
-XkbcFreeKeyboard(struct xkb_keymap *keymap)
-{
- if (!keymap)
- return;
-
- free_types(keymap);
- darray_free(keymap->acts);
- darray_free(keymap->sym_interpret);
- darray_free(keymap->key_aliases);
- free(keymap->keycodes_section_name);
- free(keymap->symbols_section_name);
- free(keymap->types_section_name);
- free(keymap->compat_section_name);
- free_keys(keymap);
- xkb_context_unref(keymap->ctx);
- free(keymap);
-}
diff --git a/src/alloc.h b/src/alloc.h
deleted file mode 100644
index e6df2c5..0000000
--- a/src/alloc.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2009 Dan Nicholson
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the names of the authors or their
- * institutions shall not be used in advertising or otherwise to promote the
- * sale, use or other dealings in this Software without prior written
- * authorization from the authors.
- */
-
-#ifndef ALLOC_H
-#define ALLOC_H
-
-#include "xkb-priv.h"
-
-extern struct xkb_keymap *
-XkbcAllocKeyboard(struct xkb_context *ctx);
-
-extern void
-XkbcFreeKeyboard(struct xkb_keymap *keymap);
-
-extern int
-XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into);
-
-extern union xkb_action *
-XkbcResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
- uint32_t needed);
-
-#endif /* ALLOC_H */
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 2e54268..8c4c7f4 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -1216,3 +1216,43 @@ ActionsInit(struct xkb_context *ctx)
actionsInitialized = 1;
}
}
+
+union xkb_action *
+ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
+ uint32_t needed)
+{
+ size_t old_ndx, old_num_acts, new_ndx;
+
+ if (needed == 0) {
+ key->acts_index = 0;
+ return NULL;
+ }
+
+ if (XkbKeyHasActions(key) && key->width >= needed)
+ return XkbKeyActionsPtr(keymap, key);
+
+ /*
+ * The key may already be in the array, but without enough space.
+ * This should not happen often, so in order to avoid moving and
+ * copying stuff from acts and key_acts, we just allocate new
+ * space for the key at the end, and leave the old space alone.
+ */
+
+ old_ndx = key->acts_index;
+ old_num_acts = XkbKeyNumActions(key);
+ new_ndx = darray_size(keymap->acts);
+
+ darray_resize0(keymap->acts, new_ndx + needed);
+ key->acts_index = new_ndx;
+
+ /*
+ * The key was already in the array, copy the old actions to the
+ * new space.
+ */
+ if (old_ndx != 0)
+ memcpy(darray_mem(keymap->acts, new_ndx),
+ darray_mem(keymap->acts, old_ndx),
+ old_num_acts * sizeof(union xkb_action));
+
+ return XkbKeyActionsPtr(keymap, key);
+}
diff --git a/src/xkbcomp/action.h b/src/xkbcomp/action.h
index 3d63468..6ca0685 100644
--- a/src/xkbcomp/action.h
+++ b/src/xkbcomp/action.h
@@ -76,6 +76,10 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
ExprDef *index, ExprDef *value,
ActionInfo **info_rtrn);
+union xkb_action *
+ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
+ uint32_t needed);
+
extern const LookupEntry ctrlNames[];
#endif /* ACTION_H */
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 707de43..787ede2 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1410,7 +1410,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
if (num_acts)
num_acts = key->num_groups * key->width;
- acts = XkbcResizeKeyActions(keymap, key, num_acts);
+ acts = ResizeKeyActions(keymap, key, num_acts);
if (num_acts && !acts)
return false;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 0ee9579..fa9eaeb 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -1091,6 +1091,42 @@ static const struct xkb_key_type canonicalTypes[XkbNumRequiredTypes] = {
};
static int
+CopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into)
+{
+ int i;
+
+ darray_free(into->map);
+ free(into->preserve);
+ free(into->level_names);
+
+ *into = *from;
+ darray_init(into->map);
+
+ darray_copy(into->map, from->map);
+
+ if (from->preserve && !darray_empty(into->map)) {
+ into->preserve = calloc(darray_size(into->map),
+ sizeof(*into->preserve));
+ if (!into->preserve)
+ return BadAlloc;
+ memcpy(into->preserve, from->preserve,
+ darray_size(into->map) * sizeof(*into->preserve));
+ }
+
+ if (from->level_names && into->num_levels > 0) {
+ into->level_names = calloc(into->num_levels,
+ sizeof(*into->level_names));
+ if (!into->level_names)
+ return BadAlloc;
+
+ for (i = 0; i < into->num_levels; i++)
+ into->level_names[i] = strdup(from->level_names[i]);
+ }
+
+ return Success;
+}
+
+static int
InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
int keypadVMod)
{
@@ -1106,22 +1142,22 @@ InitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
from = canonicalTypes;
if (which & XkbOneLevelMask)
- rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex],
- &darray_item(keymap->types, XkbOneLevelIndex));
+ rtrn = CopyKeyType(&from[XkbOneLevelIndex],
+ &darray_item(keymap->types, XkbOneLevelIndex));
if ((which & XkbTwoLevelMask) && rtrn == Success)
- rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex],
- &darray_item(keymap->types, XkbTwoLevelIndex));
+ rtrn = CopyKeyType(&from[XkbTwoLevelIndex],
+ &darray_item(keymap->types, XkbTwoLevelIndex));
if ((which & XkbAlphabeticMask) && rtrn == Success)
- rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
- &darray_item(keymap->types, XkbAlphabeticIndex));
+ rtrn = CopyKeyType(&from[XkbAlphabeticIndex],
+ &darray_item(keymap->types, XkbAlphabeticIndex));
if ((which & XkbKeypadMask) && rtrn == Success) {
struct xkb_key_type *type;
- rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex],
- &darray_item(keymap->types, XkbKeypadIndex));
+ rtrn = CopyKeyType(&from[XkbKeypadIndex],
+ &darray_item(keymap->types, XkbKeypadIndex));
type = &darray_item(keymap->types, XkbKeypadIndex);
if (keypadVMod >= 0 && keypadVMod < XkbNumVirtualMods &&
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 1f274d5..4021414 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1792,7 +1792,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
darray_resize0(key->syms, sizeSyms);
if (haveActions) {
- outActs = XkbcResizeKeyActions(keymap, key, width * nGroups);
+ outActs = ResizeKeyActions(keymap, key, width * nGroups);
if (outActs == NULL) {
log_wsgo(info->keymap->ctx,
"Could not enlarge actions for %s (key %d)\n",
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 2d94419..01033f8 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -28,7 +28,6 @@
#define XKBCOMP_PRIV_H
#include "xkbcomp.h"
-#include "alloc.h"
#include "text.h"
#include "utils.h"
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 7b1b198..1b4eb2e 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -60,6 +60,21 @@ keymap_file_from_components(struct xkb_context *ctx,
&keycodes->common, 0);
}
+static struct xkb_keymap *
+new_keymap(struct xkb_context *ctx)
+{
+ struct xkb_keymap *keymap;
+
+ keymap = calloc(1, sizeof(*keymap));
+ if (!keymap)
+ return NULL;
+
+ keymap->refcnt = 1;
+ keymap->ctx = xkb_context_ref(ctx);
+
+ return keymap;
+}
+
/**
* Compile the given file and store the output in keymap.
* @param file A list of XkbFiles, each denoting one type (e.g.
@@ -77,7 +92,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
XkbFile *compat = NULL;
XkbFile *symbols = NULL;
- keymap = XkbcAllocKeyboard(ctx);
+ keymap = new_keymap(ctx);
if (!keymap)
goto err;
@@ -332,8 +347,38 @@ xkb_map_ref(struct xkb_keymap *keymap)
XKB_EXPORT void
xkb_map_unref(struct xkb_keymap *keymap)
{
+ struct xkb_key_type *type;
+ struct xkb_key *key;
+
if (!keymap || --keymap->refcnt > 0)
return;
- XkbcFreeKeyboard(keymap);
+ darray_foreach(type, keymap->types) {
+ darray_free(type->map);
+ free(type->preserve);
+ free(type->level_names);
+ }
+ darray_free(keymap->types);
+
+ darray_foreach(key, keymap->keys) {
+ free(key->sym_index);
+ free(key->num_syms);
+ darray_free(key->syms);
+ }
+ darray_free(keymap->keys);
+
+ darray_free(keymap->acts);
+
+ darray_free(keymap->sym_interpret);
+
+ darray_free(keymap->key_aliases);
+
+ free(keymap->keycodes_section_name);
+ free(keymap->symbols_section_name);
+ free(keymap->types_section_name);
+ free(keymap->compat_section_name);
+
+ xkb_context_unref(keymap->ctx);
+
+ free(keymap);
}