public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Remove manual lifetime management from cli_interp
Date: Mon, 18 Jul 2022 14:56:29 +0000 (GMT)	[thread overview]
Message-ID: <20220718145629.6C27D3852751@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=083aca0c8333fc24c6a65a03fca765bc13ee37c0

commit 083aca0c8333fc24c6a65a03fca765bc13ee37c0
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Jun 24 09:39:47 2022 -0600

    Remove manual lifetime management from cli_interp
    
    cli_interp manually manages its cli_out object.  This patch changes it
    to use a unique_ptr, and also changes cli_uiout to be a private
    member.

Diff:
---
 gdb/cli/cli-interp.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index c26b6a75227..ca3a1abcaae 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -43,7 +43,7 @@ class cli_interp final : public cli_interp_base
 {
  public:
   explicit cli_interp (const char *name);
-  ~cli_interp ();
+  ~cli_interp () = default;
 
   void init (bool top_level) override;
   void resume () override;
@@ -51,20 +51,16 @@ class cli_interp final : public cli_interp_base
   gdb_exception exec (const char *command_str) override;
   ui_out *interp_ui_out () override;
 
+private:
+
   /* The ui_out for the console interpreter.  */
-  cli_ui_out *cli_uiout;
+  std::unique_ptr<cli_ui_out> m_cli_uiout;
 };
 
 cli_interp::cli_interp (const char *name)
-  : cli_interp_base (name)
+  : cli_interp_base (name),
+    m_cli_uiout (new cli_ui_out (gdb_stdout))
 {
-  /* Create a default uiout builder for the CLI.  */
-  this->cli_uiout = new cli_ui_out (gdb_stdout);
-}
-
-cli_interp::~cli_interp ()
-{
-  delete cli_uiout;
 }
 
 /* Suppress notification struct.  */
@@ -289,7 +285,6 @@ void
 cli_interp::resume ()
 {
   struct ui *ui = current_ui;
-  struct cli_interp *cli = this;
   struct ui_file *stream;
 
   /*sync_execution = 1; */
@@ -298,10 +293,10 @@ cli_interp::resume ()
      previously writing to gdb_stdout, then set it to the new
      gdb_stdout afterwards.  */
 
-  stream = cli->cli_uiout->set_stream (gdb_stdout);
+  stream = m_cli_uiout->set_stream (gdb_stdout);
   if (stream != gdb_stdout)
     {
-      cli->cli_uiout->set_stream (stream);
+      m_cli_uiout->set_stream (stream);
       stream = NULL;
     }
 
@@ -310,7 +305,7 @@ cli_interp::resume ()
   ui->input_handler = command_line_handler;
 
   if (stream != NULL)
-    cli->cli_uiout->set_stream (gdb_stdout);
+    m_cli_uiout->set_stream (gdb_stdout);
 }
 
 void
@@ -322,20 +317,19 @@ cli_interp::suspend ()
 gdb_exception
 cli_interp::exec (const char *command_str)
 {
-  struct cli_interp *cli = this;
   struct ui_file *old_stream;
   struct gdb_exception result;
 
-  /* gdb_stdout could change between the time cli_uiout was
+  /* gdb_stdout could change between the time m_cli_uiout was
      initialized and now.  Since we're probably using a different
      interpreter which has a new ui_file for gdb_stdout, use that one
      instead of the default.
 
      It is important that it gets reset everytime, since the user
      could set gdb to use a different interpreter.  */
-  old_stream = cli->cli_uiout->set_stream (gdb_stdout);
-  result = safe_execute_command (cli->cli_uiout, command_str, 1);
-  cli->cli_uiout->set_stream (old_stream);
+  old_stream = m_cli_uiout->set_stream (gdb_stdout);
+  result = safe_execute_command (m_cli_uiout.get (), command_str, 1);
+  m_cli_uiout->set_stream (old_stream);
   return result;
 }
 
@@ -373,9 +367,7 @@ safe_execute_command (struct ui_out *command_uiout, const char *command,
 ui_out *
 cli_interp::interp_ui_out ()
 {
-  struct cli_interp *cli = (struct cli_interp *) this;
-
-  return cli->cli_uiout;
+  return m_cli_uiout.get ();
 }
 
 /* These hold the pushed copies of the gdb output files.


                 reply	other threads:[~2022-07-18 14:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220718145629.6C27D3852751@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).