[RFA,1/4] Use scoped_restore in a couple of interp-related places

Message ID 20180430051207.19979-2-tom@tromey.com
State New
Headers show
Series
  • minor interp-related cleanups
Related show

Commit Message

Tom Tromey April 30, 2018, 5:12 a.m.
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(-)

-- 
2.13.6

Comments

Pedro Alves May 25, 2018, 5:58 p.m. | #1
On 04/30/2018 06:12 AM, Tom Tromey wrote:
> 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.


Typo: "Ues" -> "Use".

> @@ -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;

> -


I was a little worried about whether exception_print could use current_uiout,
but it seems not.  So OK.

>    /* FIXME: cagney/2005-01-13: This shouldn't be needed.  Instead the

>       caller should print the exception.  */

>    exception_print (gdb_stderr, e);

Thanks,
Pedro Alves

Patch

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.