Subject: bug#5365: 23.1.91; Wrong type argument: keymapp, ("DEAD" . 35215396)

From: Chong Yidong <[email-masked]>
Date: Wed, 13 Jan 2010 12:27:53 -0500

Chong Yidong <[email-masked]> writes:

> Even if that's the case, I'm not sure why Vlocal_function_key_map is
> getting garbage-collected, tho.

OK, I see one place where this could happen.  In xterm.c:10207:

    terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
    ...
    if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
      {
        char *vendor = ServerVendor (dpy);
        /* Temporarily hide the partially initialized terminal */
        terminal_list = terminal->next_terminal;
        UNBLOCK_INPUT;
        terminal->kboard->Vsystem_key_alist
          = call1 (Qvendor_specific_keysyms,
                   vendor ? build_string (vendor) : empty_unibyte_string);
        BLOCK_INPUT;
        ...
      }

    terminal->kboard->next_kboard = all_kboards;
    all_kboards = terminal->kboard;

It's possible that garbage-collection occurs during the call1, when the
keyboard has not yet been put on the all_kboards linked list.  In that
case, it will not be protected from garbage collection.

Sven, does the following patch fix the bug?

*** src/xterm.c	2010-01-09 04:16:32 +0000
--- src/xterm.c	2010-01-13 17:27:27 +0000
***************
*** 10210,10215 ****
--- 10210,10216 ----
  	if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
  	  {
  	    char *vendor = ServerVendor (dpy);
+ 	    int count = inhibit_garbage_collection ();
  	    /* Temporarily hide the partially initialized terminal */
  	    terminal_list = terminal->next_terminal;
  	    UNBLOCK_INPUT;
***************
*** 10217,10222 ****
--- 10218,10224 ----
  	      = call1 (Qvendor_specific_keysyms,
  		       vendor ? build_string (vendor) : empty_unibyte_string);
  	    BLOCK_INPUT;
+ 	    unbind_to (count, Qnil);
  	    terminal->next_terminal = terminal_list;
   	    terminal_list = terminal;
  	  }