From unknown Mon Jun 23 18:27:22 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#10190 <10190@debbugs.gnu.org> To: bug#10190 <10190@debbugs.gnu.org> Subject: Status: eventp can give incorrect results (subr.el), Emacs 23 and 24 Reply-To: bug#10190 <10190@debbugs.gnu.org> Date: Tue, 24 Jun 2025 01:27:22 +0000 retitle 10190 eventp can give incorrect results (subr.el), Emacs 23 and 24 reassign 10190 emacs submitter 10190 Christopher Genovese severity 10190 normal tag 10190 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 02 00:55:52 2011 Received: (at submit) by debbugs.gnu.org; 2 Dec 2011 05:55:52 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWM6B-00089N-Oc for submit@debbugs.gnu.org; Fri, 02 Dec 2011 00:55:51 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWM6A-00089H-G2 for submit@debbugs.gnu.org; Fri, 02 Dec 2011 00:55:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWM5w-0002Vg-F8 for submit@debbugs.gnu.org; Fri, 02 Dec 2011 00:55:37 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:59664) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWM5w-0002Vc-CZ for submit@debbugs.gnu.org; Fri, 02 Dec 2011 00:55:36 -0500 Received: from eggs.gnu.org ([140.186.70.92]:57842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWM5v-00009w-6Q for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 00:55:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWM5t-0002VO-To for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 00:55:35 -0500 Received: from mail-qw0-f48.google.com ([209.85.216.48]:40206) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWM5t-0002VJ-PI for bug-gnu-emacs@gnu.org; Fri, 02 Dec 2011 00:55:33 -0500 Received: by qao25 with SMTP id 25so663085qao.0 for ; Thu, 01 Dec 2011 21:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=nrIT0PUywIxZQK3RP9FcnJvc/UFEtApJWd/yOB/8A6I=; b=ME19JTxj97AFK39m008qO2aS3nF2CrKXmTMRsWzPIAQn9Kt+WpjjBOe/agbTspFLKi PY8UE2vJ/GnBvnWgFNkVvWmGXLUprIjVLAdop1USqefl14FQjHWZNrcTc6xrXblXy7aY KFkSNcEW3AaRyFDXVZeHiCUJMJiuvkBV3ogwg= Received: by 10.224.208.134 with SMTP id gc6mr1759249qab.64.1322805332734; Thu, 01 Dec 2011 21:55:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.242.73 with HTTP; Thu, 1 Dec 2011 21:55:11 -0800 (PST) From: Christopher Genovese Date: Fri, 2 Dec 2011 00:55:11 -0500 Message-ID: Subject: eventp can give incorrect results (subr.el), Emacs 23 and 24 To: bug-gnu-emacs@gnu.org Content-Type: multipart/alternative; boundary=20cf300fa9ebf6f12f04b3159da8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --20cf300fa9ebf6f12f04b3159da8 Content-Type: text/plain; charset=ISO-8859-1 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. 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., (cond ((integerp c) ...) .... ((eventp ) (do-something-with (event-modfiers c))) (t (not-what-we-want-with c))) will fail when c is a symbolic event that has not been parsed before. Consider the following sequence, which illustrates the error in a new Emacs 24 session with -Q (on Mac OS X 10.5.8). Although the event M-S-f5 is a rather obscure one, it is the event used to illustrate the event- fucntions in the Elisp Info documentation. ;; #1 (eventp 'M-S-f5) > nil (symbol-plist 'M-S-f5) > nil ;; #2 (event-modifiers 'M-S-f5) > (meta shift) ;; #3 (eventp 'M-S-f5) > (f5 meta shift) (symbol-plist 'M-S-f5) > (event-symbol-element-mask (f5 167772160) event-symbol-elements (f5 meta shift)) A similar example occurs with, say, M-s-z, even if M-s-z has been defined in the global map. This problem holds with event-basic-type too because it also just checks the symbol plist. In #1, for instance, (event-basic-type 'M-S-f5) would be nil, but not in #3. Another side of the problem(?) is that in #1 calling (event-modifier 'foobar) would make subsequent (eventp 'foobar) calls true. Neither of these seems like desirable behaviors. Not a really big deal, but I thought I'd pass it along. Thanks, Chris P.S. I haven't had a chance to look over the C code on this too closely, but the function parse_modifiers, which is doing the work in internal-event-symbol-parse-modifiers, is called at some points when reading key sequences. Caching the events when they are read would seem to be a good idea, although it is not happening in the M-s-z example. --20cf300fa9ebf6f12f04b3159da8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 res= ults
for symbolic events, depending on the timing of the call.=A0 This s= eems to
occurs because event symbol elements (mask, modifiers, basic type) are stor= ed in a plist
associated with symbolic events, but the list is set in th= e function
internal-event-symbol-parse-modifiers, which is only called i= n the function
event-modifiers not in the inline function eventp.=A0 Hence, code that test= s for
an event before checking the modifiers can give the wrong results,= e.g.,

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (cond=A0 ((integerp c) ...)=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ...= .
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ((eventp )= =A0 (do-something-with (event-modfiers c)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (t
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (not-what-we-want-with c)))
will fail when c is a symbolic event that has not been parsed before.=

Consider the following sequence, which illustrates the error in a new E= macs 24
session with -Q (on Mac OS X 10.5.8). Although the event M-S-f5 = is a rather
obscure one, it is the event used to illustrate the event- f= ucntions in the
Elisp Info documentation.

;; #1
(eventp 'M-S-f5)
> nil<= br>(symbol-plist 'M-S-f5)
> nil

;; #2
(event-modifiers = 'M-S-f5)
> (meta shift)

;; #3
(eventp 'M-S-f5)
> (f5 meta shift)
(symbol-plist 'M-S-f5)
> (event-symbol-el= ement-mask (f5 167772160) event-symbol-elements (f5 meta shift))

A s= imilar example occurs with, say, M-s-z, even if M-s-z has been defined in t= he global map.

This problem holds with event-basic-type too because it also just check= s the symbol plist.=A0
In #1, for instance, (event-basic-type 'M-S-= f5) would be nil, but not in #3.=A0
Another side of the problem(?) is t= hat in #1=A0 calling (event-modifier 'foobar) would make
subsequent (eventp 'foobar) calls true.

Neither of these seems = like desirable behaviors.

Not a really big deal, but I thought I= 9;d pass it along.

Thanks,

=A0=A0 Chris

P.S. I haven&= #39;t had a chance to look over the C code on this too closely, but the fun= ction
parse_modifiers, which is doing the work in internal-event-symbol-parse-mod= ifiers,
is called at some points when reading key sequences. Caching the events whe= n
they are read would seem to be a good idea, although it is not happening in= the
M-s-z example.

--20cf300fa9ebf6f12f04b3159da8-- From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 02 09:31:56 2011 Received: (at 10190) by debbugs.gnu.org; 2 Dec 2011 14:31:56 +0000 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 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 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 Received: by pastel.home (Postfix, from userid 20848) id 581C658CC3; Fri, 2 Dec 2011 09:31:35 -0500 (EST) From: Stefan Monnier To: Christopher Genovese Subject: Re: bug#10190: eventp can give incorrect results (subr.el), Emacs 23 and 24 Message-ID: References: Date: Fri, 02 Dec 2011 09:31:35 -0500 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) MIME-Version: 1.0 Content-Type: text/plain 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-Spam-Score: -4.5 (----) X-Debbugs-Envelope-To: 10190 Cc: 10190@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.5 (----) > 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. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 02 10:18:17 2011 Received: (at 10190) by debbugs.gnu.org; 2 Dec 2011 15:18:17 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWUsT-0008Jr-Mo for submit@debbugs.gnu.org; Fri, 02 Dec 2011 10:18:17 -0500 Received: from mail-pz0-f44.google.com ([209.85.210.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWUsQ-0008Jg-VN for 10190@debbugs.gnu.org; Fri, 02 Dec 2011 10:18:15 -0500 Received: by dadv40 with SMTP id v40so1670848dad.3 for <10190@debbugs.gnu.org>; Fri, 02 Dec 2011 07:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=1SDzQEKsttfyET43yHjwGXuRB46S379eeSdys12WUBk=; b=mfh102rANMMLocOgoOodoQYsIfFPlViC3/HC0QpvQdEa4baB61s3FV25gUiK50eWih +GnWSA9+e2+rtrE7Htv0C0HaPKjDKv1LXcqnTPsgrP0dyVHLtsZDflMnStEzCw4Up85P amX9F3rhC0TRQ04aFtvjcnaJx0bI9s5wZmDvA= Received: by 10.68.72.36 with SMTP id a4mr15167655pbv.4.1322839078802; Fri, 02 Dec 2011 07:17:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.155.7 with HTTP; Fri, 2 Dec 2011 07:17:37 -0800 (PST) In-Reply-To: References: From: Christopher Genovese Date: Fri, 2 Dec 2011 10:17:37 -0500 Message-ID: Subject: Re: bug#10190: eventp can give incorrect results (subr.el), Emacs 23 and 24 To: Stefan Monnier Content-Type: multipart/alternative; boundary=f46d04190b406316ba04b31d79ff X-Spam-Score: -4.3 (----) X-Debbugs-Envelope-To: 10190 Cc: 10190@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.2 (----) --f46d04190b406316ba04b31d79ff Content-Type: text/plain; charset=ISO-8859-1 > > > 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. > I'm finishing up a package to give easy and flexible management of imports during initialization, and in using the package, I had a function that made some settings based on a user-specified help character or event. Failures showed up in the test cases that used more obscure events like M-S-f5, and the nil eventp caused unexpected behavior. (I've since changed my approach.) > My own impression is that the patch below would be an improvement, but > I'd rather keep it for after 24.1. > That sounds reasonable to me. It's not a critical issue. Thanks for your help. -- Chris --f46d04190b406316ba04b31d79ff Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
=A0
> Neither of these seems like desirable behaviors.

I tend to agree. =A0But I'm also curious in which circumstance did you<= br> bump into this problem.

I'm finishing up a pac= kage to give easy and flexible management of imports
during initializati= on, and in using the package, I had a function that made some settings
based on a user-specified help character or event.=A0 Failures showed up in=
the test cases that used more obscure events like M-S-f5,
and the nil ev= entp caused unexpected behavior. (I've since changed
my approach.)=A0
My own impression is that the patch below would be an improvement, but
I'd rather keep it for after 24.1.

That sounds= reasonable to me.=A0 It's not a critical issue.

Thanks for your= help.

=A0 -- Chris


--f46d04190b406316ba04b31d79ff-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 19 02:31:37 2012 Received: (at 10190-done) by debbugs.gnu.org; 19 Jul 2012 06:31:37 +0000 Received: from localhost ([127.0.0.1]:49340 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrkGu-0008KF-N0 for submit@debbugs.gnu.org; Thu, 19 Jul 2012 02:31:37 -0400 Received: from pruche.dit.umontreal.ca ([132.204.246.22]:53361) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrkGp-0008K4-P3 for 10190-done@debbugs.gnu.org; Thu, 19 Jul 2012 02:31:33 -0400 Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id q6J6PJYY032242; Thu, 19 Jul 2012 02:25:20 -0400 Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 3AC8EAE20D; Thu, 19 Jul 2012 02:25:19 -0400 (EDT) From: Stefan Monnier To: Christopher Genovese Subject: Re: bug#10190: eventp can give incorrect results (subr.el), Emacs 23 and 24 Message-ID: References: Date: Thu, 19 Jul 2012 02:25:19 -0400 In-Reply-To: (Stefan Monnier's message of "Fri, 02 Dec 2011 09:31:35 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.2 X-NAI-Spam-Rules: 2 Rules triggered GEN_SPAM_FEATRE=0.2, RV4283=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4283> : streams <787036> : uri <1169064> X-Spam-Score: -3.5 (---) X-Debbugs-Envelope-To: 10190-done Cc: 10190-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.5 (---) > My own impression is that the patch below would be an improvement, but > I'd rather keep it for after 24.1. Installed (in a slightly different form). Stefan From unknown Mon Jun 23 18:27:22 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 16 Aug 2012 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator