Use scoped_restore for ui_file
authorTom Tromey <tom@tromey.com>
Fri, 23 Sep 2016 02:33:30 +0000 (20:33 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 21 Oct 2016 20:17:32 +0000 (14:17 -0600)
This replaces all the uses of make_cleanup_restore_ui_file with
scoped_restore.

2016-10-21  Tom Tromey  <tom@tromey.com>

* utils.c (make_cleanup_restore_ui_file, do_restore_ui_file)
(struct restore_ui_file_closure): Remove.
* utils.h (make_cleanup_restore_ui_file): Don't declare.
* guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
scoped_restore.
* top.c (execute_command_to_string): Use scoped_restore.

gdb/ChangeLog
gdb/guile/scm-ports.c
gdb/top.c
gdb/utils.c
gdb/utils.h

index b6290c7b3764fad9efbd690846a90baf74d4a343..9d0d5364ad0937dc6716d60e043bfd7fb0ea6e44 100644 (file)
@@ -1,3 +1,12 @@
+2016-10-21  Tom Tromey  <tom@tromey.com>
+
+       * utils.c (make_cleanup_restore_ui_file, do_restore_ui_file)
+       (struct restore_ui_file_closure): Remove.
+       * utils.h (make_cleanup_restore_ui_file): Don't declare.
+       * guile/scm-ports.c (ioscm_with_output_to_port_worker): Use
+       scoped_restore.
+       * top.c (execute_command_to_string): Use scoped_restore.
+
 2016-10-21  Tom Tromey  <tom@tromey.com>
 
        * common/scoped_restore.h: New file.
index 5559475a1b732c09d77ab858d16594a6c07c291d..dea9077aa3396bf6fed91f3a6e5847a261af9c37 100644 (file)
@@ -524,15 +524,13 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
 
   make_cleanup_ui_file_delete (port_file);
 
+  scoped_restore save_file = make_scoped_restore (oport == GDB_STDERR
+                                                 ? &gdb_stderr : &gdb_stdout);
+
   if (oport == GDB_STDERR)
-    {
-      make_cleanup_restore_ui_file (&gdb_stderr);
-      gdb_stderr = port_file;
-    }
+    gdb_stderr = port_file;
   else
     {
-      make_cleanup_restore_ui_file (&gdb_stdout);
-
       if (ui_out_redirect (current_uiout, port_file) < 0)
        warning (_("Current output protocol does not support redirection"));
       else
index 120d751d0ec2abde8741409f086d1e557708f953..053c510333f63377021275ad1f40f73fef5a8f7f 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -706,22 +706,22 @@ execute_command_to_string (char *p, int from_tty)
   str_file = mem_fileopen ();
 
   make_cleanup_ui_file_delete (str_file);
-  make_cleanup_restore_ui_file (&gdb_stdout);
-  make_cleanup_restore_ui_file (&gdb_stderr);
-  make_cleanup_restore_ui_file (&gdb_stdlog);
-  make_cleanup_restore_ui_file (&gdb_stdtarg);
-  make_cleanup_restore_ui_file (&gdb_stdtargerr);
 
   if (ui_out_redirect (current_uiout, str_file) < 0)
     warning (_("Current output protocol does not support redirection"));
   else
     make_cleanup_ui_out_redirect_pop (current_uiout);
 
-  gdb_stdout = str_file;
-  gdb_stderr = str_file;
-  gdb_stdlog = str_file;
-  gdb_stdtarg = str_file;
-  gdb_stdtargerr = str_file;
+  scoped_restore save_stdout
+    = make_scoped_restore (&gdb_stdout, str_file);
+  scoped_restore save_stderr
+    = make_scoped_restore (&gdb_stderr, str_file);
+  scoped_restore save_stdlog
+    = make_scoped_restore (&gdb_stdlog, str_file);
+  scoped_restore save_stdtarg
+    = make_scoped_restore (&gdb_stdtarg, str_file);
+  scoped_restore save_stdtargerr
+    = make_scoped_restore (&gdb_stdtargerr, str_file);
 
   execute_command (p, from_tty);
 
index 71c0e009cacacee3f6e55e87bc2e54faa4d224b4..e552685efa70eaaead9d593fb9bf65b3d5754ae3 100644 (file)
@@ -319,35 +319,6 @@ make_cleanup_htab_delete (htab_t htab)
   return make_cleanup (do_htab_delete_cleanup, htab);
 }
 
-struct restore_ui_file_closure
-{
-  struct ui_file **variable;
-  struct ui_file *value;
-};
-
-static void
-do_restore_ui_file (void *p)
-{
-  struct restore_ui_file_closure *closure
-    = (struct restore_ui_file_closure *) p;
-
-  *(closure->variable) = closure->value;
-}
-
-/* Remember the current value of *VARIABLE and make it restored when
-   the cleanup is run.  */
-
-struct cleanup *
-make_cleanup_restore_ui_file (struct ui_file **variable)
-{
-  struct restore_ui_file_closure *c = XNEW (struct restore_ui_file_closure);
-
-  c->variable = variable;
-  c->value = *variable;
-
-  return make_cleanup_dtor (do_restore_ui_file, (void *) c, xfree);
-}
-
 /* Helper for make_cleanup_value_free_to_mark.  */
 
 static void
index c4944e1337cc74afb1ff905de99c5caae0be412b..36f5294abd11cf948f1bfb9ef18463f67f4d76d4 100644 (file)
@@ -91,9 +91,6 @@ extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable);
 struct target_ops;
 extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops);
 
-extern struct cleanup *
-  make_cleanup_restore_ui_file (struct ui_file **variable);
-
 extern struct cleanup *make_cleanup_value_free_to_mark (struct value *);
 extern struct cleanup *make_cleanup_value_free (struct value *);
 
This page took 0.032348 seconds and 4 git commands to generate.