Clean up Init/Clear functions - The Clear* functions should just free the memory associated with the object. If the object is used again, it is Init'd again. - s/Free/Clear if the actual pointer is not free'd. - Zeroise object in Init and only initialize non-zero fields. 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
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 9abc11a..963c938 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -251,23 +251,15 @@ static void
InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
ActionsInfo *actions)
{
+ memset(info, 0, sizeof(*info));
info->keymap = keymap;
- info->name = NULL;
info->file_id = file_id;
- info->errorCount = 0;
- darray_init(info->interps);
info->actions = actions;
info->dflt.file_id = file_id;
- info->dflt.defined = 0;
info->dflt.merge = MERGE_OVERRIDE;
- info->dflt.interp.repeat = false;
info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
- memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
- info->dflt.interp.act.type = ACTION_TYPE_NONE;
- memset(&info->ledDflt, 0, sizeof(info->ledDflt));
info->ledDflt.file_id = file_id;
info->ledDflt.merge = MERGE_OVERRIDE;
- darray_init(info->leds);
InitVModInfo(&info->vmods, keymap);
}
@@ -275,19 +267,8 @@ static void
ClearCompatInfo(CompatInfo *info)
{
free(info->name);
- info->name = NULL;
- info->dflt.defined = 0;
- info->dflt.merge = MERGE_AUGMENT;
- info->dflt.interp.repeat = false;
- info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
- memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
- info->dflt.interp.act.type = ACTION_TYPE_NONE;
- memset(&info->ledDflt, 0, sizeof(info->ledDflt));
darray_free(info->interps);
darray_free(info->leds);
- info->actions = NULL;
- info->keymap = NULL;
- ClearVModInfo(&info->vmods);
}
static SymInterpInfo *
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 274959b..f870f00 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -262,16 +262,11 @@ AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
}
static void
-ClearKeyNamesInfo(KeyNamesInfo * info)
+ClearKeyNamesInfo(KeyNamesInfo *info)
{
free(info->name);
- info->name = NULL;
- info->merge = MERGE_DEFAULT;
- info->computedMax = info->explicitMax = info->explicitMin = 0;
- info->computedMin = XKB_KEYCODE_MAX;
darray_free(info->names);
darray_free(info->files);
- memset(info->indicator_names, 0, sizeof(info->indicator_names));
darray_free(info->aliases);
}
@@ -279,15 +274,11 @@ static void
InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
unsigned file_id)
{
- info->name = NULL;
+ memset(info, 0, sizeof(*info));
+ info->ctx = ctx;
info->merge = MERGE_DEFAULT;
- darray_init(info->aliases);
info->file_id = file_id;
- darray_init(info->names);
- darray_init(info->files);
- ClearKeyNamesInfo(info);
- info->errorCount = 0;
- info->ctx = ctx;
+ info->computedMin = XKB_KEYCODE_MAX;
}
static int
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index ae1b9aa..6ef5733 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -60,9 +60,9 @@
#include "include.h"
enum key_repeat {
+ KEY_REPEAT_UNDEFINED = 0,
KEY_REPEAT_YES = 1,
- KEY_REPEAT_NO = 0,
- KEY_REPEAT_UNDEFINED = -1
+ KEY_REPEAT_NO = 2,
};
enum group_field {
@@ -121,33 +121,24 @@ ClearGroupInfo(GroupInfo *groupi)
{
darray_free(groupi->syms);
darray_free(groupi->levels);
- InitGroupInfo(groupi);
}
static void
InitKeyInfo(KeyInfo *keyi, unsigned file_id)
{
- xkb_group_index_t i;
- static const char dflt[4] = "*";
+ static const char dflt_key_name[XKB_KEY_NAME_LENGTH] = "*";
- keyi->defined = 0;
+ memset(keyi, 0, sizeof(*keyi));
keyi->file_id = file_id;
keyi->merge = MERGE_OVERRIDE;
- keyi->name = KeyNameToLong(dflt);
- for (i = 0; i < XKB_NUM_GROUPS; i++)
- InitGroupInfo(&keyi->groups[i]);
- keyi->dfltType = XKB_ATOM_NONE;
- keyi->vmodmap = 0;
- keyi->repeat = KEY_REPEAT_UNDEFINED;
+ keyi->name = KeyNameToLong(dflt_key_name);
keyi->out_of_range_group_action = RANGE_WRAP;
- keyi->out_of_range_group_number = 0;
}
static void
ClearKeyInfo(KeyInfo *keyi)
{
xkb_group_index_t i;
-
for (i = 0; i < XKB_NUM_GROUPS; i++)
ClearGroupInfo(&keyi->groups[i]);
}
@@ -184,35 +175,25 @@ static void
InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
unsigned file_id, ActionsInfo *actions)
{
- xkb_group_index_t i;
-
- info->name = NULL;
- info->explicit_group = 0;
- info->errorCount = 0;
+ memset(info, 0, sizeof(*info));
+ info->keymap = keymap;
info->file_id = file_id;
info->merge = MERGE_OVERRIDE;
- darray_init(info->keys);
darray_growalloc(info->keys, 110);
- darray_init(info->modMaps);
- for (i = 0; i < XKB_NUM_GROUPS; i++)
- info->groupNames[i] = XKB_ATOM_NONE;
InitKeyInfo(&info->dflt, file_id);
InitVModInfo(&info->vmods, keymap);
info->actions = actions;
- info->keymap = keymap;
}
static void
ClearSymbolsInfo(SymbolsInfo * info)
{
KeyInfo *keyi;
-
free(info->name);
darray_foreach(keyi, info->keys)
ClearKeyInfo(keyi);
darray_free(info->keys);
darray_free(info->modMaps);
- memset(info, 0, sizeof(SymbolsInfo));
}
static bool
@@ -462,6 +443,7 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
(clobber ? "first" : "last"));
ClearKeyInfo(from);
+ InitKeyInfo(from, info->file_id);
return true;
}
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index 4fb0c2f..12f477f 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -216,12 +216,10 @@ static void
InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
unsigned file_id)
{
- info->name = NULL;
- info->errorCount = 0;
- darray_init(info->types);
+ memset(info, 0, sizeof(*info));
+ info->keymap = keymap;
info->file_id = file_id;
InitVModInfo(&info->vmods, keymap);
- info->keymap = keymap;
}
static void
@@ -232,10 +230,9 @@ ClearKeyTypeInfo(KeyTypeInfo *type)
}
static void
-FreeKeyTypesInfo(KeyTypesInfo * info)
+ClearKeyTypesInfo(KeyTypesInfo *info)
{
free(info->name);
- info->name = NULL;
darray_free(info->types);
}
@@ -336,7 +333,7 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *stmt)
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_TYPES,
&rtrn, &merge)) {
info->errorCount += 10;
- FreeKeyTypesInfo(&included);
+ ClearKeyTypesInfo(&included);
return false;
}
@@ -346,12 +343,12 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *stmt)
MergeIncludedKeyTypes(&included, &next_incl, merge);
- FreeKeyTypesInfo(&next_incl);
+ ClearKeyTypesInfo(&next_incl);
FreeXkbFile(rtrn);
}
MergeIncludedKeyTypes(info, &included, merge);
- FreeKeyTypesInfo(&included);
+ ClearKeyTypesInfo(&included);
return (info->errorCount == 0);
}
@@ -851,10 +848,10 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
if (!CopyKeyTypesToKeymap(keymap, &info))
goto err_info;
- FreeKeyTypesInfo(&info);
+ ClearKeyTypesInfo(&info);
return true;
err_info:
- FreeKeyTypesInfo(&info);
+ ClearKeyTypesInfo(&info);
return false;
}
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 64db7ed..b09e3ef 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -34,19 +34,12 @@ InitVModInfo(VModInfo *info, struct xkb_keymap *keymap)
{
xkb_group_index_t i;
- info->defined = info->available = 0;
-
+ memset(info, 0, sizeof(*info));
for (i = 0; i < XKB_NUM_VIRTUAL_MODS; i++)
if (keymap->vmod_names[i])
info->defined |= (1 << i);
}
-void
-ClearVModInfo(VModInfo *info)
-{
- info->defined = info->available = 0;
-}
-
bool
HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
enum merge_mode mergeMode, VModInfo *info)
diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h
index a711b9b..96b330d 100644
--- a/src/xkbcomp/vmod.h
+++ b/src/xkbcomp/vmod.h
@@ -35,9 +35,6 @@ typedef struct _VModInfo {
void
InitVModInfo(VModInfo *info, struct xkb_keymap *keymap);
-void
-ClearVModInfo(VModInfo *info);
-
bool
HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
enum merge_mode mergeMode, VModInfo *info);