summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-09-14 00:21:54 +0300
committerRan Benita <ran234@gmail.com>2012-09-14 21:09:48 +0300
commit96c21e1577fa6462efc4d98a6f72a16ba521f6a3 (patch)
tree6ea489d16d5e4a712b8831d2a9b349089c5506c2 /src
parent7b5a1dd556f2f4d21f7a3265e614cae3a91e36bb (diff)
downloadlibxkbcommon-96c21e1577fa6462efc4d98a6f72a16ba521f6a3.tar.gz
libxkbcommon-96c21e1577fa6462efc4d98a6f72a16ba521f6a3.tar.bz2
libxkbcommon-96c21e1577fa6462efc4d98a6f72a16ba521f6a3.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/xkbcomp/compat.c21
-rw-r--r--src/xkbcomp/keycodes.c17
-rw-r--r--src/xkbcomp/symbols.c34
-rw-r--r--src/xkbcomp/types.c19
-rw-r--r--src/xkbcomp/vmod.c9
-rw-r--r--src/xkbcomp/vmod.h3
6 files changed, 22 insertions, 81 deletions
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);