Make XkbcInitAtoms() call optional
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
diff --git a/src/atom.c b/src/atom.c
index f50b9e7..baab640 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -105,13 +105,6 @@ XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value)
do_get_atom_value = get_atom_value;
return;
}
-
- if (nodeTable)
- return;
-
- tableLength = InitialTableSize;
- nodeTable = (NodePtr *)malloc(InitialTableSize * sizeof(NodePtr));
- nodeTable[None] = NULL;
}
static const char *
@@ -202,16 +195,22 @@ _XkbcMakeAtom(const char *string, unsigned len, Bool makeit)
if ((lastAtom + 1) >= tableLength) {
NodePtr *table;
+ int newLength;
+
+ if (tableLength == 0)
+ newLength = InitialTableSize;
+ else
+ newLength = tableLength * 2;
- table = (NodePtr *)realloc(nodeTable,
- tableLength * 2 * sizeof(NodePtr));
+ table = realloc(nodeTable, newLength * sizeof(NodePtr));
if (!table) {
if (nd->string != string)
free(nd->string);
free(nd);
return BAD_RESOURCE;
}
- tableLength <<= 1;
+ tableLength = newLength;
+ table[None] = NULL;
nodeTable = table;
}
diff --git a/test/filecomp.c b/test/filecomp.c
index dc20681..cd824c0 100644
--- a/test/filecomp.c
+++ b/test/filecomp.c
@@ -60,7 +60,6 @@ int main(int argc, char *argv[])
}
uSetErrorFile(NULL);
- XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromFile(file, name);
fclose(file);
diff --git a/test/namescomp.c b/test/namescomp.c
index 3c34d0c..f1ea4b5 100644
--- a/test/namescomp.c
+++ b/test/namescomp.c
@@ -54,7 +54,6 @@ int main(int argc, char *argv[])
ktcsg.geometry = argv[5];
uSetErrorFile(NULL);
- XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromComponents(&ktcsg);
diff --git a/test/rulescomp.c b/test/rulescomp.c
index 102c3e9..6368ab6 100644
--- a/test/rulescomp.c
+++ b/test/rulescomp.c
@@ -53,7 +53,6 @@ int main(int argc, char *argv[])
rmlvo.options = argv[5];
uSetErrorFile(NULL);
- XkbcInitAtoms(NULL, NULL);
xkb = XkbcCompileKeymapFromRules(&rmlvo);