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>
master
Ran Benita 2012-08-03 00:20:07 +03:00
parent 6f08a2cfa0
commit b804aec292
1 changed files with 13 additions and 34 deletions

View File

@ -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)