From b1314e15504ca365f79942dfff08591e5ef553d3 Mon Sep 17 00:00:00 2001 From: Karl Heuer Date: Fri, 30 Jul 1999 14:37:30 +0000 Subject: [PATCH] (get_keymap_1, get_keyelt): Check the type of OBJECT before calling indirect_function. --- src/keymap.c | 104 +++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/src/keymap.c b/src/keymap.c index dbbbafbcf7d..1b673384806 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -224,9 +224,16 @@ get_keymap_1 (object, error, autoload) Lisp_Object tem; autoload_retry: - tem = indirect_function (object); - if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap)) - return tem; + if (NILP (object)) + goto end; + if (CONSP (object) && EQ (XCAR (object), Qkeymap)) + return object; + else + { + tem = indirect_function (object); + if (CONSP (tem) && EQ (XCONS (tem)->car, Qkeymap)) + return tem; + } /* Should we do an autoload? Autoload forms for keymaps have Qkeymap as their fifth element. */ @@ -250,6 +257,7 @@ get_keymap_1 (object, error, autoload) } } + end: if (error) wrong_type_argument (Qkeymapp, object); else @@ -545,68 +553,76 @@ get_keyelt (object, autoload) { while (1) { - register Lisp_Object map, tem; + if (!(CONSP (object))) + /* This is really the value. */ + return object; - /* If the contents are (KEYMAP . ELEMENT), go indirect. */ - map = get_keymap_1 (Fcar_safe (object), 0, autoload); - tem = Fkeymapp (map); - if (!NILP (tem)) + /* If the keymap contents looks like (keymap ...) or (lambda ...) + then use itself. */ + else if (EQ (XCAR (object), Qkeymap) || EQ (XCAR (object), Qlambda)) + return object; + + /* If the keymap contents looks like (menu-item name . DEFN) + or (menu-item name DEFN ...) then use DEFN. + This is a new format menu item. + */ + else if (EQ (XCAR (object), Qmenu_item)) { - Lisp_Object key; - key = Fcdr (object); - if (INTEGERP (key) && (XINT (key) & meta_modifier)) + if (CONSP (XCDR (object))) { - object = access_keymap (map, meta_prefix_char, 0, 0); - map = get_keymap_1 (object, 0, autoload); - object = access_keymap (map, - make_number (XINT (key) & ~meta_modifier), - 0, 0); + object = XCDR (XCDR (object)); + if (CONSP (object)) + object = XCAR (object); } else - object = access_keymap (map, key, 0, 0); + /* Invalid keymap */ + return object; } - else if (!(CONSP (object))) - /* This is really the value. */ - return object; - - /* If the keymap contents looks like (STRING . DEFN), - use DEFN. + /* If the keymap contents looks like (STRING . DEFN), use DEFN. Keymap alist elements like (CHAR MENUSTRING . DEFN) will be used by HierarKey menus. */ - else if (STRINGP (XCONS (object)->car)) + else if (STRINGP (XCAR (object))) { - object = XCONS (object)->cdr; + object = XCDR (object); /* Also remove a menu help string, if any, following the menu item name. */ - if (CONSP (object) && STRINGP (XCONS (object)->car)) - object = XCONS (object)->cdr; + if (CONSP (object) && STRINGP (XCAR (object))) + object = XCDR (object); /* Also remove the sublist that caches key equivalences, if any. */ - if (CONSP (object) - && CONSP (XCONS (object)->car)) + if (CONSP (object) && CONSP (XCAR (object))) { Lisp_Object carcar; - carcar = XCONS (XCONS (object)->car)->car; + carcar = XCAR (XCAR (object)); if (NILP (carcar) || VECTORP (carcar)) - object = XCONS (object)->cdr; + object = XCDR (object); } } - /* If the keymap contents looks like (menu-item name . DEFN) - or (menu-item name DEFN ...) then use DEFN. - This is a new format menu item. - */ - else if (EQ (XCONS (object)->car, Qmenu_item) - && CONSP (XCONS (object)->cdr)) + /* If the contents are (KEYMAP . ELEMENT), go indirect. */ + else { - object = XCONS (XCONS (object)->cdr)->cdr; - if (CONSP (object)) - object = XCONS (object)->car; + register Lisp_Object map; + map = get_keymap_1 (Fcar_safe (object), 0, autoload); + if (NILP (map)) + /* Invalid keymap */ + return object; + else + { + Lisp_Object key; + key = Fcdr (object); + if (INTEGERP (key) && (XINT (key) & meta_modifier)) + { + object = access_keymap (map, meta_prefix_char, 0, 0); + map = get_keymap_1 (object, 0, autoload); + object = access_keymap (map, make_number (XINT (key) + & ~meta_modifier), + 0, 0); + } + else + object = access_keymap (map, key, 0, 0); + } } - - else - /* Anything else is really the value. */ - return object; } } -- 2.39.5