action: drop global actionInitialized The action.c needs to use two constant Expr values, constTrue and constFalse. To do this is keeps to static globals Expr's of type boolean and the values "true" and "false" which need to be interned (and thus context specific). The interning means they can't be made static const, so there's a global flag and initializer function. Instead of using this unsafe global state, we can simply use an integer boolean expression (1 and 0) instead of a string one ("true" and "false") and make them const. 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
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 6aaf5d7..418ec31 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -26,9 +26,19 @@
#include "action.h"
-static bool actionsInitialized;
-static ExprDef constTrue;
-static ExprDef constFalse;
+static const ExprDef constTrue = {
+ .common = { .type = STMT_EXPR, .next = NULL },
+ .op = EXPR_VALUE,
+ .value_type = EXPR_TYPE_BOOLEAN,
+ .value = { .ival = 1 },
+};
+
+static const ExprDef constFalse = {
+ .common = { .type = STMT_EXPR, .next = NULL },
+ .op = EXPR_VALUE,
+ .value_type = EXPR_TYPE_BOOLEAN,
+ .value = { .ival = 0 },
+};
/***====================================================================***/
@@ -1160,9 +1170,6 @@ ApplyActionFactoryDefaults(union xkb_action * action)
}
}
-static void
-ActionsInit(struct xkb_context *ctx);
-
int
HandleActionDef(ExprDef * def,
struct xkb_keymap *keymap,
@@ -1172,9 +1179,6 @@ HandleActionDef(ExprDef * def,
const char *str;
unsigned tmp, hndlrType;
- if (!actionsInitialized)
- ActionsInit(keymap->ctx);
-
if (def->op != EXPR_ACTION_DECL) {
log_err(keymap->ctx, "Expected an action definition, found %s\n",
exprOpText(def->op));
@@ -1220,12 +1224,10 @@ HandleActionDef(ExprDef * def,
else {
if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
field = arg->value.child;
- constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
value = &constFalse;
}
else {
field = arg;
- constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
value = &constTrue;
}
}
@@ -1259,9 +1261,6 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
{
ActionInfo *new, *old;
- if (!actionsInitialized)
- ActionsInit(keymap->ctx);
-
new = malloc(sizeof(*new));
if (!new) {
log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
@@ -1303,26 +1302,6 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
/***====================================================================***/
-static void
-ActionsInit(struct xkb_context *ctx)
-{
- if (!actionsInitialized) {
- memset(&constTrue, 0, sizeof(constTrue));
- memset(&constFalse, 0, sizeof(constFalse));
- constTrue.common.type = STMT_EXPR;
- constTrue.common.next = NULL;
- constTrue.op = EXPR_IDENT;
- constTrue.value_type = EXPR_TYPE_BOOLEAN;
- constTrue.value.str = xkb_atom_intern(ctx, "true");
- constFalse.common.type = STMT_EXPR;
- constFalse.common.next = NULL;
- constFalse.op = EXPR_IDENT;
- constFalse.value_type = EXPR_TYPE_BOOLEAN;
- constFalse.value.str = xkb_atom_intern(ctx, "false");
- actionsInitialized = 1;
- }
-}
-
union xkb_action *
ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
uint32_t needed)