registry: don't call xmlCleanupParser()
[platform/upstream/libxkbcommon.git] / src / x11 / util.c
index 6618dfe..cc4c71c 100644 (file)
@@ -124,48 +124,6 @@ xkb_x11_get_core_keyboard_device_id(xcb_connection_t *conn)
     return device_id;
 }
 
-void
-get_atom_name(xcb_connection_t *conn, xcb_atom_t atom,
-              xcb_get_atom_name_cookie_t *cookie)
-{
-    if (atom == 0) {
-        cookie->sequence = 0;
-    } else {
-        *cookie = xcb_get_atom_name(conn, atom);
-    }
-}
-
-bool
-get_atom_name_reply(xcb_connection_t *conn, xcb_atom_t atom,
-                    xcb_get_atom_name_cookie_t cookie, char **out)
-{
-    xcb_get_atom_name_reply_t *reply;
-    int length;
-    char *name;
-
-    if (atom == 0) {
-        *out = NULL;
-        assert(cookie.sequence == 0);
-        return true;
-    }
-
-    reply = xcb_get_atom_name_reply(conn, cookie, NULL);
-    if (!reply)
-        return false;
-
-    length = xcb_get_atom_name_name_length(reply);
-    name = xcb_get_atom_name_name(reply);
-
-    *out = strndup(name, length);
-    if (!*out) {
-        free(reply);
-        return false;
-    }
-
-    free(reply);
-    return true;
-}
-
 struct x11_atom_cache {
     /*
      * Invalidate the cache based on the XCB connection.
@@ -204,13 +162,17 @@ x11_atom_interner_init(struct x11_atom_interner *interner,
     interner->conn = conn;
     interner->num_pending = 0;
     interner->num_copies = 0;
+    interner->num_escaped = 0;
 }
 
 void
 x11_atom_interner_adopt_atom(struct x11_atom_interner *interner,
                              const xcb_atom_t atom, xkb_atom_t *out)
 {
-    *out = 0;
+    *out = XKB_ATOM_NONE;
+
+    if (atom == XCB_ATOM_NONE)
+        return;
 
     /* Can be NULL in case the malloc failed. */
     struct x11_atom_cache *cache = get_cache(interner->ctx, interner->conn);
@@ -254,16 +216,7 @@ retry:
 }
 
 void
-x11_atom_interner_adopt_atoms(struct x11_atom_interner *interner,
-                              const xcb_atom_t *from, xkb_atom_t *to,
-                              size_t count)
-{
-    for (size_t i = 0; i < count; i++) {
-        x11_atom_interner_adopt_atom(interner, from[i], &to[i]);
-    }
-}
-
-void x11_atom_interner_round_trip(struct x11_atom_interner *interner) {
+x11_atom_interner_round_trip(struct x11_atom_interner *interner) {
     struct xkb_context *ctx = interner->ctx;
     xcb_connection_t *conn = interner->conn;
 
@@ -298,6 +251,48 @@ void x11_atom_interner_round_trip(struct x11_atom_interner *interner) {
         }
     }
 
+    for (size_t i = 0; i < interner->num_escaped; i++) {
+        xcb_get_atom_name_reply_t *reply;
+        int length;
+        char *name;
+        char **out = interner->escaped[i].out;
+
+        reply = xcb_get_atom_name_reply(conn, interner->escaped[i].cookie, NULL);
+        *interner->escaped[i].out = NULL;
+        if (!reply) {
+            interner->had_error = true;
+        } else {
+            length = xcb_get_atom_name_name_length(reply);
+            name = xcb_get_atom_name_name(reply);
+
+            *out = strndup(name, length);
+            free(reply);
+            if (*out == NULL) {
+                interner->had_error = true;
+            } else {
+                XkbEscapeMapName(*out);
+            }
+        }
+    }
+
     interner->num_pending = 0;
     interner->num_copies = 0;
+    interner->num_escaped = 0;
+}
+
+void
+x11_atom_interner_get_escaped_atom_name(struct x11_atom_interner *interner,
+                                        xcb_atom_t atom, char **out)
+{
+    if (atom == 0) {
+        *out = NULL;
+        return;
+    }
+    size_t idx = interner->num_escaped++;
+    /* There can only be a fixed number of calls to this function "in-flight",
+     * thus we assert this number. Increase the array size if this assert fails.
+     */
+    assert(idx < ARRAY_SIZE(interner->escaped));
+    interner->escaped[idx].out = out;
+    interner->escaped[idx].cookie = xcb_get_atom_name(interner->conn, atom);
 }