unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master 5b5f441: read_key_sequence: correct the handling of raw_keybuf in recursive calls
Date: Thu, 23 Nov 2017 09:35:03 -0500	[thread overview]
Message-ID: <jwvd149m6fq.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20171122210426.GB4288@ACM> (Alan Mackenzie's message of "Wed, 22 Nov 2017 21:04:26 +0000")

> I'm still not sure there's a problem.  But I think the effort involved
> in showing there's no problem would exceed that needed to solve it, so
> we might as well just assume there's a problem.

Exactly: I can't convince myself that it's safe, even after spending
some effort on it, so I think we need to makes its safety more obvious.

> Which I think is what you're doing anyway.  :-)

Exactly.

>> > That's quite close to what I've done.  The difficulty is in getting a
>> > pointer to that local buffer for use by the menu handling code.
>> Hmm... could you show me that menu handling code you're referring to?
>> The only user I can see of raw_keybuf (outside of local uses within
>> read_key_sequence) is this-single-command-raw-keys, so maybe I'm
>> missing something.
> read_menu_command calls read_key_sequence.  It is called by this stack
> of functions:
> - read_key_sequence is called by
> - read_menu_command .. ...... ..
> - read_menu_input
> - tty_menu_activate
> - tty_menu_show, which is one value of terminal->menu_show_hook.  This
>   is called in its turn by:
> - Fx_popup_menu, which besides being called from many places in lisp is
>   also called from
> - read_char_x_menu_prompt
> - read_char
> - read_key_sequence
> This is the recursion which makes it difficult just to use a global
> buffer for the raw key events.

Ah, I see.  I thought that by "getting a pointer to that local buffer"
you meant that the menu handling code actually needs to get its hands at
the raw_keybuf variable.  Yes, I don't doubt that read-key-sequence can
be called recursively, although I indeed hadn't thought about the above
case.

Here's another case where read-key-sequence can be invoked recursively:
read_key_sequence calls keyremap_step which calls
access_keymap_keyremap, which uses `call1` to run the Elisp code
specified in the remapping keymap (e.g. input-decode-map for
xterm-mouse-mode), which internally may decide to call read-key-sequence
(currently at least xterm-mouse-mode and things like
event-apply-control-modifier use read-event rather than
read-key(-sequence), but there could be very valid reasons to use
read-key(-sequence) in there).

> How about this idea?  Split Fx_popup_menu into two pieces, Fx_popup_menu
> which just initialises the global raw key buffer then calls
> sub_x_popup_menu.  read_char_x_menu_prompt (see above list) would then
> call sub_x_popup_menu to avoid emptying the global buffer.
>
> Other than that, the global raw key buffer would be initialised in
> command_loop_1 and (possibly) read_key_sequence_vs.
>
> This way, everything which appends to the raw key buffer could just use
> the global variables, without any dangerous shenanigans on the stack.

Hmm... that might work, but I still can't imagine what comment I could
write next to the code to explain/prove that it's safe.

I think a record_unwind_protect is the easiest way to make it safer.

Yet, with the new concurrency feature, the unwind might reset the
global var to a pointer into a stack area on another thread, which may
have gotten stale in the mean time.


        Stefan



  reply	other threads:[~2017-11-23 14:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20171120181209.23553.97060@vcs0.savannah.gnu.org>
     [not found] ` <20171120181210.7946F20416@vcs0.savannah.gnu.org>
2017-11-20 18:41   ` [Emacs-diffs] master 5b5f441: read_key_sequence: correct the handling of raw_keybuf in recursive calls Stefan Monnier
2017-11-20 19:59     ` Alan Mackenzie
2017-11-20 20:09       ` Stefan Monnier
2017-11-20 20:30         ` Alan Mackenzie
2017-11-20 21:43           ` Stefan Monnier
2017-11-22 19:25             ` Alan Mackenzie
2017-11-22 20:29               ` Stefan Monnier
2017-11-22 21:04                 ` Alan Mackenzie
2017-11-23 14:35                   ` Stefan Monnier [this message]
2017-11-23 18:10                     ` Alan Mackenzie
2017-11-23 18:46                       ` Stefan Monnier
2017-11-28 18:03                         ` Alan Mackenzie
2017-11-28 20:30                           ` Eli Zaretskii
2017-12-01 16:48                             ` Alan Mackenzie
2017-12-01 18:17                               ` Eli Zaretskii

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=jwvd149m6fq.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acm@muc.de \
    --cc=emacs-devel@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).