Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/4] Use scoped_restore in a couple of interp-related places
Date: Mon, 30 Apr 2018 05:12:00 -0000	[thread overview]
Message-ID: <20180430051207.19979-2-tom@tromey.com> (raw)
In-Reply-To: <20180430051207.19979-1-tom@tromey.com>

While looking through the "interp" code I found a couple of spots that
could use scoped_restore.

ChangeLog
2018-04-29  Tom Tromey  <tom@tromey.com>

	* cli/cli-interp.c (safe_execute_command): Ues scoped_restore.
	* interps.c (interp_exec): Use scoped_restore.
---
 gdb/ChangeLog        |  5 +++++
 gdb/cli/cli-interp.c |  8 ++------
 gdb/interps.c        | 13 +++----------
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index bbee809880..0663301c19 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -356,11 +356,10 @@ safe_execute_command (struct ui_out *command_uiout, const char *command,
 		      int from_tty)
 {
   struct gdb_exception e = exception_none;
-  struct ui_out *saved_uiout;
 
   /* Save and override the global ``struct ui_out'' builder.  */
-  saved_uiout = current_uiout;
-  current_uiout = command_uiout;
+  scoped_restore saved_uiout = make_scoped_restore (&current_uiout,
+						    command_uiout);
 
   TRY
     {
@@ -372,9 +371,6 @@ safe_execute_command (struct ui_out *command_uiout, const char *command,
     }
   END_CATCH
 
-  /* Restore the global builder.  */
-  current_uiout = saved_uiout;
-
   /* FIXME: cagney/2005-01-13: This shouldn't be needed.  Instead the
      caller should print the exception.  */
   exception_print (gdb_stderr, e);
diff --git a/gdb/interps.c b/gdb/interps.c
index 61db7f4bdf..162cd838ec 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -354,18 +354,11 @@ interp_exec (struct interp *interp, const char *command_str)
 {
   struct ui_interp_info *ui_interp = get_current_interp_info ();
 
-  struct gdb_exception ex;
-  struct interp *save_command_interp;
-
   /* See `command_interp' for why we do this.  */
-  save_command_interp = ui_interp->command_interpreter;
-  ui_interp->command_interpreter = interp;
-
-  ex = interp->exec (command_str);
-
-  ui_interp->command_interpreter = save_command_interp;
+  scoped_restore save_command_interp
+    = make_scoped_restore (&ui_interp->command_interpreter, interp);
 
-  return ex;
+  return interp->exec (command_str);
 }
 
 /* A convenience routine that nulls out all the common command hooks.
-- 
2.13.6


  parent reply	other threads:[~2018-04-30  5:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  5:12 [RFA 0/4] minor interp-related cleanups Tom Tromey
2018-04-30  5:12 ` [RFA 4/4] Remove interp_name Tom Tromey
2018-05-25 18:41   ` Pedro Alves
2018-05-25 18:47     ` Tom Tromey
2018-05-25 19:36       ` Pedro Alves
2018-04-30  5:12 ` Tom Tromey [this message]
2018-05-25 18:06   ` [RFA 1/4] Use scoped_restore in a couple of interp-related places Pedro Alves
2018-04-30  5:12 ` [RFA 2/4] Change the as_*_interp functions to use dynamic_cast Tom Tromey
2018-05-25 18:12   ` Pedro Alves
2018-04-30  5:12 ` [RFA 3/4] Remove interp_ui_out Tom Tromey
2018-05-25 18:37   ` Pedro Alves
2018-05-25 17:34 ` [RFA 0/4] minor interp-related cleanups Tom Tromey

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180430051207.19979-2-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox