Subject: Re: bug#10190: eventp can give incorrect results (subr.el), Emacs 23 and 24

From: Stefan Monnier <[email-masked]>
Date: Fri, 02 Dec 2011 09:31:35 -0500

> This is not a major problem, but it did come up for me in a real program.
> In Emacs 23 and 24, the function eventp in subr.el can give incorrect
> results for symbolic events, depending on the timing of the call.

I think the assumption of the current code is that eventp is allowed to
return nil if that event has not yet occurred in the current session.
I'm not sure why it's done that way.

> This seems to occurs because event symbol elements (mask, modifiers,
> basic type) are stored in a plist associated with symbolic events, but
> the list is set in the function internal-event-symbol-parse-modifiers,
> which is only called in the function event-modifiers not in the inline
> function eventp.  Hence, code that tests for an event before checking
> the modifiers can give the wrong results, e.g.,

Note that (progn (event-modifiers X) (eventp X)) will return non-nil for
*any* symbol (i.e. any symbol can potentially be an event name).

> Neither of these seems like desirable behaviors.

I tend to agree.  But I'm also curious in which circumstance did you
bump into this problem.

My own impression is that the patch below would be an improvement, but
I'd rather keep it for after 24.1.

        Stefan

=== modified file 'lisp/subr.el'
--- lisp/subr.el	2011-11-23 07:03:56 +0000
+++ lisp/subr.el	2011-12-02 14:30:16 +0000
@@ -870,16 +870,10 @@
 
 (defsubst eventp (obj)
   "True if the argument is an event object."
-  (or (and (integerp obj)
-	   ;; Filter out integers too large to be events.
-	   ;; M is the biggest modifier.
-	   (zerop (logand obj (lognot (1- (lsh ?\M-\^@ 1)))))
-	   (characterp (event-basic-type obj)))
-      (and (symbolp obj)
-	   (get obj 'event-symbol-elements))
+  (or (integerp obj)
+      (symbolp obj)
       (and (consp obj)
-	   (symbolp (car obj))
-	   (get (car obj) 'event-symbol-elements))))
+	   (symbolp (car obj)))))
 
 (defun event-modifiers (event)
   "Return a list of symbols representing the modifier keys in event EVENT.