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>
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
diff --git a/src/context.c b/src/context.c
index 2aaee35..190a1c5 100644
--- a/src/context.c
+++ b/src/context.c
@@ -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.
*/
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 83af402..518abc1 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -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);
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 5ed0608..ce775b4 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -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);
}
}
;
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index 8bfafa4..b22a3d5 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -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;
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index 9bcc9fb..4cf21a7 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -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
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index c1b7bd0..0ec97ec 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -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;
}