Use ui_file_up in mi_interp
authorTom Tromey <tromey@adacore.com>
Mon, 28 Nov 2022 21:05:05 +0000 (14:05 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 30 Nov 2022 14:12:38 +0000 (07:12 -0700)
This changes mi_interp to use ui_file_up rather than explicit
management.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/mi/mi-interp.c
gdb/mi/mi-interp.h

index 482166ea3a5c361fc6f3af2d27fa93230817def1..3cc2462f67296333f3d5c8d4e1fad4f7c3fd8be6 100644 (file)
@@ -1276,7 +1276,7 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
       mi->saved_raw_stdout = mi->raw_stdout;
 
       ui_file *logfile_p = logfile.get ();
-      mi->saved_raw_file_to_delete = logfile.release ();
+      mi->logfile_holder = std::move (logfile);
 
       /* If something is not being redirected, then a tee containing both the
         logfile and stdout.  */
@@ -1284,19 +1284,17 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
       if (!logging_redirect || !debug_redirect)
        {
          tee = new tee_file (mi->raw_stdout, logfile_p);
-         mi->saved_tee_to_delete = tee;
+         mi->stdout_holder.reset (tee);
        }
 
       mi->raw_stdout = logging_redirect ? logfile_p : tee;
     }
   else
     {
-      delete mi->saved_raw_file_to_delete;
-      delete mi->saved_tee_to_delete;
+      mi->logfile_holder.reset ();
+      mi->stdout_holder.reset ();
       mi->raw_stdout = mi->saved_raw_stdout;
       mi->saved_raw_stdout = nullptr;
-      mi->saved_raw_file_to_delete = nullptr;
-      mi->saved_tee_to_delete = nullptr;
     }
 
   mi->out->set_raw (mi->raw_stdout);
index d118ffb41e50eb20be02e57253aa4bfd6a089f71..6b6e1f7022043e308c1c71696c98378d83fe1324 100644 (file)
@@ -56,8 +56,8 @@ public:
      file which we need to delete, so we can restore correctly when
      done.  */
   struct ui_file *saved_raw_stdout;
-  struct ui_file *saved_raw_file_to_delete;
-  struct ui_file *saved_tee_to_delete;
+  ui_file_up logfile_holder;
+  ui_file_up stdout_holder;
 
   /* MI's builder.  */
   struct ui_out *mi_uiout;