diff src/event-Xt.c @ 5639:1d1f385c9149

Call XKeysymToString() much less, it leaks. src/ChangeLog addition: 2012-01-08 Aidan Kehoe <kehoea@parhasard.net> * device-x.c: * device-x.c (syms_of_device_x): Move #'x-keysym-on-keyboard{,-sans-modifiers}-p to Lisp, the hash table no longer stores the X keysyms, so we need to manipulate any strings we have been handed. * event-Xt.c (x_has_keysym): Don't call XKeysymToString() here, it leaks; trust x_keysym_to_emacs_keysym() instead. * event-Xt.c (x_keysym_to_emacs_keysym): No longer leak when looking up the strings for keysyms of the form UABCD. lisp/ChangeLog addition: 2012-01-08 Aidan Kehoe <kehoea@parhasard.net> * x-init.el: * x-init.el (pseudo-canonicalize-keysym): New. * x-init.el: Move #'x-keysym-on-keyboard-sans-modifiers-p, #'x-keysym-on-keyboard-p here from device-x.c, some string manipulation it now needs to do is far easier in Lisp. * x-win-xfree86.el: * x-win-xfree86.el (x-win-init-xfree86): No longer call #'x-keysym-on-keyboard{,-sans-modifiers}-p, implement it ourselves cheaply.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 08 Jan 2012 20:41:37 +0000
parents 56144c8593a8
children
line wrap: on
line diff
--- a/src/event-Xt.c	Fri Jan 06 16:35:07 2012 +0000
+++ b/src/event-Xt.c	Sun Jan 08 20:41:37 2012 +0000
@@ -181,26 +181,17 @@
 
   for (j = 0; j < (upper_lower[0] == upper_lower[1] ? 1 : 2); j++)
     {
-      Extbyte *name;
-      keysym = upper_lower[j];
-
-      name = XKeysymToString (keysym);
-      if (name)
-	{
-	  /* X guarantees NAME to be in the Host Portable Character Encoding */
-	  Lisp_Object sym = x_keysym_to_emacs_keysym (keysym, 0);
-	  Lisp_Object new_value = with_modifiers ? Qt : Qsans_modifiers;
-	  Lisp_Object old_value = Fgethash (sym, hash_table, Qnil);
-
-	  if (! EQ (old_value, new_value)
-	      && ! (EQ (old_value, Qsans_modifiers) &&
-		    EQ (new_value, Qt)))
-	    {
-	      maybe_define_x_key_as_self_inserting_character (keysym, sym);
-	      Fputhash (build_extstring (name, Qbinary), new_value,
-			hash_table);
-	      Fputhash (sym, new_value, hash_table);
-	    }
+      KeySym ks = upper_lower[j];
+      Lisp_Object sym = x_keysym_to_emacs_keysym (ks, 0);
+      Lisp_Object new_value = with_modifiers ? Qt : Qsans_modifiers;
+      Lisp_Object old_value = Fgethash (sym, hash_table, Qnil);
+
+      if (! EQ (old_value, new_value)
+          && ! (EQ (old_value, Qsans_modifiers) &&
+                EQ (new_value, Qt)))
+        {
+          maybe_define_x_key_as_self_inserting_character (ks, sym);
+          Fputhash (sym, new_value, hash_table);
 	}
     }
 }
@@ -757,6 +748,17 @@
        characters are the same as their ASCII codes.  */
     return make_char (keysym);
 
+  if (keysym >= 0x01000000 && keysym <= 0x0110FFFF)
+    {
+      /* These keysyms malloc with XKeysymToString(), *every time the
+         function is called.* Avoid leaking, construct the keysym string
+         ourselves. */
+      Ascbyte buf [10];
+      qxesprintf ((Ibyte *) buf, keysym & 0xff0000 ? "U%06X" : "U%04X",
+                  (unsigned int) (keysym & 0xffffff));
+      return KEYSYM (buf);
+    }
+
   switch (keysym)
     {
       /* These would be handled correctly by the default case, but by