Contextualize XkbFile IDs

Currently the IDs are assigned from a static variable inside
CreateXKBFile. This can lead to some unpleasantness with threads, so
maintain the counter in the context instead.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-05-09 11:29:04 +03:00 committed by Daniel Stone
parent 64aa5c95ed
commit 4aef083e46
6 changed files with 35 additions and 14 deletions

View File

@ -35,6 +35,9 @@ struct xkb_context {
char **include_paths;
int num_include_paths;
int size_include_paths;
/* xkbcomp needs to assign sequential IDs to XkbFile's it creates. */
int file_id;
};
/**
@ -149,6 +152,12 @@ xkb_context_include_path_get(struct xkb_context *context, unsigned int idx)
return context->include_paths[idx];
}
int
xkb_context_take_file_id(struct xkb_context *context)
{
return context->file_id++;
}
/**
* Take a new reference on the context.
*/

View File

@ -437,6 +437,10 @@ extern unsigned int
xkb_key_get_syms_by_level(struct xkb_keymap *keymap, xkb_keycode_t key,
unsigned int group, unsigned int level,
const xkb_keysym_t **syms_out);
extern int
xkb_context_take_file_id(struct xkb_context *context);
extern bool
XkbcComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type,
unsigned char *map_rtrn);

View File

@ -175,7 +175,10 @@ XkbCompMapList : XkbCompMapList XkbCompositeMap
XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
XkbMapConfigList
CBRACE SEMI
{ $$= CreateXKBFile($2,$3,&$5->common,$1); }
{
$$ = CreateXKBFile(param->context, $2, $3,
&$5->common, $1);
}
;
XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
@ -206,7 +209,7 @@ XkbMapConfig : OptFlags FileType OptMapName OBRACE
}
else
{
$$= CreateXKBFile($2,$3,$5,$1);
$$ = CreateXKBFile(param->context, $2, $3, $5, $1);
}
}
;
@ -221,7 +224,7 @@ XkbConfig : OptFlags FileType OptMapName DeclList
}
else
{
$$= CreateXKBFile($2,$3,$4,$1);
$$ = CreateXKBFile(param->context, $2, $3, $4, $1);
}
}
;

View File

@ -684,10 +684,10 @@ EnsureSafeMapName(char *name)
}
XkbFile *
CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
CreateXKBFile(struct xkb_context *context, int type, char *name,
ParseCommon *defs, unsigned flags)
{
XkbFile *file;
static int fileID;
file = uTypedAlloc(XkbFile);
if (file)
@ -698,7 +698,7 @@ CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
file->topName = uDupString(name);
file->name = name;
file->defs = defs;
file->id = fileID++;
file->id = xkb_context_take_file_id(context);
file->flags = flags;
}
return file;

View File

@ -120,7 +120,7 @@ extern void
CheckDefaultMap(XkbFile *maps, const char *fileName);
extern XkbFile *
CreateXKBFile(int type, char *name,
CreateXKBFile(struct xkb_context *context, int type, char *name,
ParseCommon *defs, unsigned flags);
extern bool

View File

@ -34,27 +34,32 @@ unsigned int warningLevel = 0;
#define ISEMPTY(str) (!(str) || (strlen(str) == 0))
static XkbFile *
XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
XkbKeymapFileFromComponents(struct xkb_context *context,
const struct xkb_component_names *ktcsg)
{
XkbFile *keycodes, *types, *compat, *symbols;
IncludeStmt *inc;
inc = IncludeCreate(ktcsg->keycodes, MergeDefault);
keycodes = CreateXKBFile(XkmKeyNamesIndex, NULL, (ParseCommon *)inc, 0);
keycodes = CreateXKBFile(context, XkmKeyNamesIndex, NULL,
(ParseCommon *)inc, 0);
inc = IncludeCreate(ktcsg->types, MergeDefault);
types = CreateXKBFile(XkmTypesIndex, NULL, (ParseCommon *)inc, 0);
types = CreateXKBFile(context, XkmTypesIndex, NULL,
(ParseCommon *)inc, 0);
AppendStmt(&keycodes->common, &types->common);
inc = IncludeCreate(ktcsg->compat, MergeDefault);
compat = CreateXKBFile(XkmCompatMapIndex, NULL, (ParseCommon *)inc, 0);
compat = CreateXKBFile(context, XkmCompatMapIndex, NULL,
(ParseCommon *)inc, 0);
AppendStmt(&keycodes->common, &compat->common);
inc = IncludeCreate(ktcsg->symbols, MergeDefault);
symbols = CreateXKBFile(XkmSymbolsIndex, NULL, (ParseCommon *)inc, 0);
symbols = CreateXKBFile(context, XkmSymbolsIndex, NULL,
(ParseCommon *)inc, 0);
AppendStmt(&keycodes->common, &symbols->common);
return CreateXKBFile(XkmKeymapFile,
return CreateXKBFile(context, XkmKeymapFile,
ktcsg->keymap ? ktcsg->keymap : strdup(""),
&keycodes->common, 0);
}
@ -249,7 +254,7 @@ xkb_map_new_from_kccgst(struct xkb_context *context,
return NULL;
}
if (!(file = XkbKeymapFileFromComponents(kccgst))) {
if (!(file = XkbKeymapFileFromComponents(context, kccgst))) {
ERROR("failed to generate parsed XKB file from components\n");
return NULL;
}