forked from Imagelibrary/binutils-gdb
Replace interp_set_temp with scoped_restore_interp
This removes interp_set_temp and an associated cleanup, in favor of a new RAII class, scoped_restore_interp. ChangeLog 2017-09-11 Tom Tromey <tom@tromey.com> * cli/cli-script.c (restore_interp): Remove. (read_command_lines): Use scoped_restore_interp. * interps.c (scoped_restore_interp::set_temp): Rename from interp_set_temp. * interps.h (class scoped_restore_interp): New. (interp_set_temp): Remove.
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
2017-09-11 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* cli/cli-script.c (restore_interp): Remove.
|
||||||
|
(read_command_lines): Use scoped_restore_interp.
|
||||||
|
* interps.c (scoped_restore_interp::set_temp): Rename from
|
||||||
|
interp_set_temp.
|
||||||
|
* interps.h (class scoped_restore_interp): New.
|
||||||
|
(interp_set_temp): Remove.
|
||||||
|
|
||||||
2017-09-11 Tom Tromey <tom@tromey.com>
|
2017-09-11 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* mi/mi-cmd-catch.c (mi_cmd_catch_assert)
|
* mi/mi-cmd-catch.c (mi_cmd_catch_assert)
|
||||||
|
|||||||
@@ -1158,12 +1158,6 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
restore_interp (void *arg)
|
|
||||||
{
|
|
||||||
interp_set_temp (interp_name ((struct interp *)arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read lines from the input stream and accumulate them in a chain of
|
/* Read lines from the input stream and accumulate them in a chain of
|
||||||
struct command_line's, which is then returned. For input from a
|
struct command_line's, which is then returned. For input from a
|
||||||
terminal, the special command "end" is used to mark the end of the
|
terminal, the special command "end" is used to mark the end of the
|
||||||
@@ -1203,12 +1197,10 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands,
|
|||||||
validator, closure);
|
validator, closure);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct interp *old_interp = interp_set_temp (INTERP_CONSOLE);
|
scoped_restore_interp interp_restorer (INTERP_CONSOLE);
|
||||||
struct cleanup *old_chain = make_cleanup (restore_interp, old_interp);
|
|
||||||
|
|
||||||
head = read_command_lines_1 (read_next_line, parse_commands,
|
head = read_command_lines_1 (read_next_line, parse_commands,
|
||||||
validator, closure);
|
validator, closure);
|
||||||
do_cleanups (old_chain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from_tty && input_interactive_p (current_ui)
|
if (from_tty && input_interactive_p (current_ui)
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ current_interp_set_logging (ui_file_up logfile,
|
|||||||
|
|
||||||
/* Temporarily overrides the current interpreter. */
|
/* Temporarily overrides the current interpreter. */
|
||||||
struct interp *
|
struct interp *
|
||||||
interp_set_temp (const char *name)
|
scoped_restore_interp::set_interp (const char *name)
|
||||||
{
|
{
|
||||||
struct ui_interp_info *ui_interp = get_current_interp_info ();
|
struct ui_interp_info *ui_interp = get_current_interp_info ();
|
||||||
struct interp *interp = interp_lookup (current_ui, name);
|
struct interp *interp = interp_lookup (current_ui, name);
|
||||||
|
|||||||
@@ -104,6 +104,32 @@ extern struct ui_out *interp_ui_out (struct interp *interp);
|
|||||||
extern const char *interp_name (struct interp *interp);
|
extern const char *interp_name (struct interp *interp);
|
||||||
extern struct interp *interp_set_temp (const char *name);
|
extern struct interp *interp_set_temp (const char *name);
|
||||||
|
|
||||||
|
/* Temporarily set the current interpreter, and reset it on
|
||||||
|
destruction. */
|
||||||
|
class scoped_restore_interp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
scoped_restore_interp (const char *name)
|
||||||
|
: m_interp (set_interp (name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~scoped_restore_interp ()
|
||||||
|
{
|
||||||
|
set_interp (interp_name (m_interp));
|
||||||
|
}
|
||||||
|
|
||||||
|
scoped_restore_interp (const scoped_restore_interp &) = delete;
|
||||||
|
scoped_restore_interp &operator= (const scoped_restore_interp &) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct interp *set_interp (const char *name);
|
||||||
|
|
||||||
|
struct interp *m_interp;
|
||||||
|
};
|
||||||
|
|
||||||
extern int current_interp_named_p (const char *name);
|
extern int current_interp_named_p (const char *name);
|
||||||
|
|
||||||
/* Call this function to give the current interpreter an opportunity
|
/* Call this function to give the current interpreter an opportunity
|
||||||
|
|||||||
Reference in New Issue
Block a user