From: Alan Mackenzie <acm@muc.de>
To: 29349@debbugs.gnu.org
Subject: bug#29349: read_key_sequence is only partially recursive. This is a bug.
Date: Sun, 19 Nov 2017 12:34:56 +0000 [thread overview]
Message-ID: <20171119123456.GA4576@ACM> (raw)
In-Reply-To: <20171118093843.GA3819@ACM>
Hello, Emacs.
On Sat, Nov 18, 2017 at 09:38:43 +0000, Alan Mackenzie wrote:
> In branch emacs-26.
> I came across this bug whilst working on bug #29272 ("C-h k C-mouse-3"
> followed by menu selection asks for more keys).
> In a Linux tty using the GPM mouse package, doing read_key_sequence (the
> C function in keyboard.c), when a menu action is activated,
> read_key_sequence calls itself recursively to handle all the mouse
> manipulation.
> Unfortunately, the variable raw_keybuf_count is initialised to 0 in
> r_k_s. This includes in the recursive call. This variable indexes the
> global buffer raw_keybuf, which accumulates the raw events which make up
> the key sequence.
> The result of this is that the events in the recursive call overwrite
> the stored events of the outer r_k_s call, leaving a mess.
> r_k_s is static in keyboard.c and is called from three functions:
> command_loop_1, read_menu_command (the one that gives the trouble), and
> read_key_sequence_vs.
> So I propose as a solution that raw_keybuf_count be initialised to zero
> in two of these three functions, but not in read_menu_command (and no
> longer in read_key_sequence). I've tried this, and it seems to work.
> It has the disadvantage of being ugly, and it makes read_menu_command
> only callable as a subfunction of r_k_s.
> Has anybody any thoughts on this?
Here is how I propose to solve this:
(i) In keyboard.c, the static variables raw_keybuf and raw_keybuf_count
will become pointers. They will initially point to a static buffer and
a static integer. For safety's sake, they will be reinitialised to
those static variables in command_loop_1(), just before the invocation
of read_key_sequence().
(ii) read_key_sequence() will get a Lisp_Object buffer and a count
variable as local variables. Around the call to read_char(),
raw_keybuf{,_count} will be set to point to these locals, so that should
read_char encounter a menu, its events will be stored in the local copy
of the Lisp_Object buffer.
(iii) On return from read_char, if any events are in the local buffer,
they will be appended to the buffer in the enclosing scope. The global
pointers raw_keybuf{,_count} will be restored to their previous values.
In short, raw_keybuf and raw_keybuf_count will be "bound" to local
variables around the call to read_char().
Comments?
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2017-11-19 12:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-18 9:38 bug#29349: read_key_sequence is only partially recursive. This is a bug Alan Mackenzie
2017-11-19 12:34 ` Alan Mackenzie [this message]
2017-11-19 15:59 ` bug#29349: [Patch] Bug 29349: " Alan Mackenzie
2017-11-19 17:01 ` Eli Zaretskii
2017-11-19 17:45 ` Alan Mackenzie
2017-11-19 18:02 ` Eli Zaretskii
2017-11-19 20:41 ` Alan Mackenzie
2017-11-20 3:33 ` Eli Zaretskii
2017-11-20 17:27 ` Alan Mackenzie
2017-11-20 18:24 ` Eli Zaretskii
2017-11-20 18:12 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171119123456.GA4576@ACM \
--to=acm@muc.de \
--cc=29349@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).