Mercurial > octave
changeset 28707:f0a3f4527ba6 stable
respond to signals when readline is waiting for input (bug #54444)
* input.cc (internal_input_event_hook_fcn): Also call octave_quit.
Since we will always call octave_quit, don't remove self from
command_editor event hook list if input_sys no longer has hook
functions registered.
(Fadd_input_event_hook, Fremove_input_event_hook): Don't remove
internal_input_event_hook_fcn from command_editor event hook list if
input_sys no longer has hook functions registered.
(input_system::m_initialized): New data member.
(input_system::initialize): Don't allow initialization more than once.
Call command_editor::add_event_hook to install
internal_input_event_hook_fcn.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 09 Sep 2020 23:57:20 -0400 |
parents | c435048c2796 |
children | 91f0ee715701 29b627624aaa |
files | libinterp/corefcn/input.cc libinterp/corefcn/input.h |
diffstat | 2 files changed, 22 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc Thu Sep 10 13:49:46 2020 +0900 +++ b/libinterp/corefcn/input.cc Wed Sep 09 23:57:20 2020 -0400 @@ -391,6 +391,18 @@ return retval; } + static int internal_input_event_hook_fcn (void) + { + octave_quit (); + + input_system& input_sys + = __get_input_system__ ("internal_input_event_hook_fcn"); + + input_sys.run_input_event_hooks (); + + return 0; + } + // Use literal "octave" in default setting for PS1 instead of // "\\s" to avoid setting the prompt to "octave.exe" or // "octave-gui", etc. @@ -399,12 +411,15 @@ : m_interpreter (interp), m_PS1 (R"(octave:\#> )"), m_PS2 ("> "), m_completion_append_char (' '), m_gud_mode (false), m_mfile_encoding ("system"), m_last_debugging_command ("\n"), - m_input_event_hook_functions () + m_input_event_hook_functions (), m_initialized (false) { } void input_system::initialize (bool line_editing) { + if (m_initialized) + return; + // Force default line editor if we don't want readline editing. if (! line_editing) { @@ -435,6 +450,10 @@ command_editor::set_completion_function (generate_completion); command_editor::set_quoting_function (quoting_filename); + + command_editor::add_event_hook (internal_input_event_hook_fcn); + + m_initialized = true; } octave_value @@ -1188,22 +1207,6 @@ return ovl (); } -namespace octave -{ - static int internal_input_event_hook_fcn (void) - { - input_system& input_sys - = __get_input_system__ ("internal_input_event_hook_fcn"); - - input_sys.run_input_event_hooks (); - - if (! input_sys.have_input_event_hooks ()) - command_editor::remove_event_hook (internal_input_event_hook_fcn); - - return 0; - } -} - DEFMETHOD (add_input_event_hook, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {@var{id} =} add_input_event_hook (@var{fcn}) @@ -1238,9 +1241,6 @@ hook_function hook_fcn (args(0), user_data); - if (! input_sys.have_input_event_hooks ()) - octave::command_editor::add_event_hook (octave::internal_input_event_hook_fcn); - input_sys.add_input_event_hook (hook_fcn); return ovl (hook_fcn.id ()); @@ -1271,9 +1271,6 @@ warning ("remove_input_event_hook: %s not found in list", hook_fcn_id.c_str ()); - if (! input_sys.have_input_event_hooks ()) - octave::command_editor::remove_event_hook (octave::internal_input_event_hook_fcn); - return ovl (); }