From b804aec292f8fdc6928a62b441bda469b68e2502 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 3 Aug 2012 00:20:07 +0300 Subject: [PATCH] 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 --- src/xkbcomp/action.c | 47 ++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) 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)