Contextualize XkbFile IDs
authorRan Benita <ran234@gmail.com>
Wed, 9 May 2012 08:29:04 +0000 (11:29 +0300)
committerDaniel Stone <daniel@fooishbar.org>
Wed, 9 May 2012 14:30:49 +0000 (15:30 +0100)
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>
src/context.c
src/xkb-priv.h
src/xkbcomp/parser.y
src/xkbcomp/parseutils.c
src/xkbcomp/parseutils.h
src/xkbcomp/xkbcomp.c

index 2aaee35..190a1c5 100644 (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.
  */
index 83af402..518abc1 100644 (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);
index 5ed0608..ce775b4 100644 (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);
                             }
                         }
                ;
index 8bfafa4..b22a3d5 100644 (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;
index 9bcc9fb..4cf21a7 100644 (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
index c1b7bd0..0ec97ec 100644 (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;
     }