Replace do_restore_instream_cleanup with scoped_restore
authorTom Tromey <tom@tromey.com>
Mon, 1 May 2017 03:17:58 +0000 (21:17 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 3 Aug 2017 13:59:06 +0000 (07:59 -0600)
This changes the users of do_restore_instream_cleanup to use a
scoped_restore instead.  This patch is broken out because it warrants
some additional attention: in particular it's unclear to me whether
current_ui can change in the body of these functions -- but if it can,
then the cleanup would have modified a different UI's instream member.

ChangeLog
2017-08-03  Tom Tromey  <tom@tromey.com>

* top.h (do_restore_instream_cleanup): Remove.
* top.c (do_restore_instream_cleanup): Remove.
(read_command_file): Use scoped_restore.
* cli/cli-script.c (execute_user_command): Use scoped_restore.

gdb/ChangeLog
gdb/cli/cli-script.c
gdb/top.c
gdb/top.h

index 9337365973522fab7b9a8649f28d921ae4a745d1..4459acc4bf1357289ced0d6498ec96505b1c2055 100644 (file)
@@ -1,3 +1,10 @@
+2017-08-03  Tom Tromey  <tom@tromey.com>
+
+       * top.h (do_restore_instream_cleanup): Remove.
+       * top.c (do_restore_instream_cleanup): Remove.
+       (read_command_file): Use scoped_restore.
+       * cli/cli-script.c (execute_user_command): Use scoped_restore.
+
 2017-08-03  Tom Tromey  <tom@tromey.com>
 
        * cli/cli-script.c (execute_user_command)
index d8dfbfc097148792ab0733185816bc66720b9c3c..4b8ae0b1dca98b483838e1f6f5dac8c4572b76f3 100644 (file)
@@ -377,7 +377,6 @@ execute_user_command (struct cmd_list_element *c, char *args)
 {
   struct ui *ui = current_ui;
   struct command_line *cmdlines;
-  struct cleanup *old_chain;
   enum command_control_type ret;
   extern unsigned int max_user_call_depth;
 
@@ -393,8 +392,8 @@ execute_user_command (struct cmd_list_element *c, char *args)
 
   /* Set the instream to 0, indicating execution of a
      user-defined function.  */
-  old_chain = make_cleanup (do_restore_instream_cleanup, ui->instream);
-  ui->instream = NULL;
+  scoped_restore restore_instream
+    = make_scoped_restore (&ui->instream, nullptr);
 
   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
@@ -410,7 +409,6 @@ execute_user_command (struct cmd_list_element *c, char *args)
        }
       cmdlines = cmdlines->next;
     }
-  do_cleanups (old_chain);
 }
 
 /* This function is called every time GDB prints a prompt.  It ensures
index 43bf0d42d41c704910d8410eb723f761a84b17fb..6b00c6e7c2cee0e9cd3441af65ac91e5b3bca415 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -444,27 +444,14 @@ quit_cover (void)
    event-top.c into this file, top.c.  */
 /* static */ const char *source_file_name;
 
-/* Clean up on error during a "source" command (or execution of a
-   user-defined command).  */
-
-void
-do_restore_instream_cleanup (void *stream)
-{
-  struct ui *ui = current_ui;
-
-  /* Restore the previous input stream.  */
-  ui->instream = (FILE *) stream;
-}
-
 /* Read commands from STREAM.  */
 void
 read_command_file (FILE *stream)
 {
   struct ui *ui = current_ui;
-  struct cleanup *cleanups;
 
-  cleanups = make_cleanup (do_restore_instream_cleanup, ui->instream);
-  ui->instream = stream;
+  scoped_restore save_instream
+    = make_scoped_restore (&ui->instream, stream);
 
   /* Read commands from `instream' and execute them until end of file
      or error reading instream.  */
@@ -479,8 +466,6 @@ read_command_file (FILE *stream)
        break;
       command_handler (command);
     }
-
-  do_cleanups (cleanups);
 }
 \f
 void (*pre_init_ui_hook) (void);
index 5d7cb1f810873598f57e8f0b4d8d4a327d4cb0c4..45798897f694ab8ce33abccbc01221cb8609bbe0 100644 (file)
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -290,8 +290,6 @@ extern void show_history (char *, int);
 
 extern void set_verbose (char *, int, struct cmd_list_element *);
 
-extern void do_restore_instream_cleanup (void *stream);
-
 extern char *handle_line_of_input (struct buffer *cmd_line_buffer,
                                   char *rl, int repeat,
                                   const char *annotation_suffix);
This page took 0.032325 seconds and 4 git commands to generate.