From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#10190: eventp can give incorrect results (subr.el), Emacs 23 and 24 Date: Fri, 02 Dec 2011 09:31:35 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1322836317 6402 80.91.229.12 (2 Dec 2011 14:31:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 2 Dec 2011 14:31:57 +0000 (UTC) Cc: 10190@debbugs.gnu.org To: Christopher Genovese Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 02 15:31:53 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RWU9Y-00027j-Em for geb-bug-gnu-emacs@m.gmane.org; Fri, 02 Dec 2011 15:31:52 +0100 Original-Received: from localhost ([::1]:41861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWU9Y-0007Xn-0K for geb-bug-gnu-emacs@m.gmane.org; Fri, 02 Dec 2011 09:31:52 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:50271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWU9U-0007W5-RF for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 09:31:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWU9T-00087n-OZ for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 09:31:48 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWU9T-00087U-N2 for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 09:31:47 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RWU9i-00074N-AE for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 09:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Dec 2011 14:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10190 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10190-submit@debbugs.gnu.org id=B10190.132283631627164 (code B ref 10190); Fri, 02 Dec 2011 14:32:02 +0000 Original-Received: (at 10190) by debbugs.gnu.org; 2 Dec 2011 14:31:56 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWU9c-000745-8R for submit@debbugs.gnu.org; Fri, 02 Dec 2011 09:31:56 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWU9Y-00073s-0l for 10190@debbugs.gnu.org; Fri, 02 Dec 2011 09:31:54 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id pB2EVZ1i015031; Fri, 2 Dec 2011 09:31:35 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 581C658CC3; Fri, 2 Dec 2011 09:31:35 -0500 (EST) In-Reply-To: (Christopher Genovese's message of "Fri, 2 Dec 2011 00:55:11 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4058=0 X-NAI-Spam-Version: 2.2.0.9286 : core <4058> : streams <707143> : uri <1020387> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 02 Dec 2011 09:32:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:54613 Archived-At: > 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.