This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 1/2] Remove cleanups from gdb_readline_wrapper


This removes some cleanups from gdb_readline_wrapper by changing the
existing gdb_readline_wrapper_cleanup struct to have a constructor and
destructor, and then changing gdb_readline_wrapper to simply
instantiate it on the stack.

gdb/ChangeLog
2018-03-22  Tom Tromey  <tom@tromey.com>

	* top.c (struct gdb_readline_wrapper_cleanup): Add constructor,
	destructor.
	(gdb_readline_wrapper_cleanup): Remove function.
	(gdb_readline_wrapper): Remove cleanups.
---
 gdb/ChangeLog |  7 +++++
 gdb/top.c     | 91 ++++++++++++++++++++++++++---------------------------------
 2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/gdb/top.c b/gdb/top.c
index 14387b9f1a..02d23cca66 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -919,73 +919,64 @@ gdb_readline_wrapper_line (char *line)
 
 struct gdb_readline_wrapper_cleanup
   {
-    void (*handler_orig) (char *);
-    int already_prompted_orig;
+    explicit gdb_readline_wrapper_cleanup (struct ui *ui)
+      : handler_orig (ui->input_handler),
+	already_prompted_orig (ui->command_editing ? rl_already_prompted : 0),
+	target_is_async_orig (target_is_async_p ())
+    {
+      ui->input_handler = gdb_readline_wrapper_line;
+      ui->secondary_prompt_depth++;
+    }
 
-    /* Whether the target was async.  */
-    int target_is_async_orig;
-  };
+    ~gdb_readline_wrapper_cleanup ()
+    {
+      struct ui *ui = current_ui;
 
-static void
-gdb_readline_wrapper_cleanup (void *arg)
-{
-  struct ui *ui = current_ui;
-  struct gdb_readline_wrapper_cleanup *cleanup
-    = (struct gdb_readline_wrapper_cleanup *) arg;
+      if (ui->command_editing)
+	rl_already_prompted = already_prompted_orig;
 
-  if (ui->command_editing)
-    rl_already_prompted = cleanup->already_prompted_orig;
+      gdb_assert (ui->input_handler == gdb_readline_wrapper_line);
+      ui->input_handler = handler_orig;
 
-  gdb_assert (ui->input_handler == gdb_readline_wrapper_line);
-  ui->input_handler = cleanup->handler_orig;
+      /* Don't restore our input handler in readline yet.  That would make
+	 readline prep the terminal (putting it in raw mode), while the
+	 line we just read may trigger execution of a command that expects
+	 the terminal in the default cooked/canonical mode, such as e.g.,
+	 running Python's interactive online help utility.  See
+	 gdb_readline_wrapper_line for when we'll reinstall it.  */
 
-  /* Don't restore our input handler in readline yet.  That would make
-     readline prep the terminal (putting it in raw mode), while the
-     line we just read may trigger execution of a command that expects
-     the terminal in the default cooked/canonical mode, such as e.g.,
-     running Python's interactive online help utility.  See
-     gdb_readline_wrapper_line for when we'll reinstall it.  */
+      gdb_readline_wrapper_result = NULL;
+      gdb_readline_wrapper_done = 0;
+      ui->secondary_prompt_depth--;
+      gdb_assert (ui->secondary_prompt_depth >= 0);
 
-  gdb_readline_wrapper_result = NULL;
-  gdb_readline_wrapper_done = 0;
-  ui->secondary_prompt_depth--;
-  gdb_assert (ui->secondary_prompt_depth >= 0);
+      after_char_processing_hook = saved_after_char_processing_hook;
+      saved_after_char_processing_hook = NULL;
 
-  after_char_processing_hook = saved_after_char_processing_hook;
-  saved_after_char_processing_hook = NULL;
+      if (target_is_async_orig)
+	target_async (1);
+    }
 
-  if (cleanup->target_is_async_orig)
-    target_async (1);
+    DISABLE_COPY_AND_ASSIGN (gdb_readline_wrapper_cleanup);
 
-  xfree (cleanup);
-}
+    void (*handler_orig) (char *);
+    int already_prompted_orig;
+
+    /* Whether the target was async.  */
+    int target_is_async_orig;
+  };
 
 char *
 gdb_readline_wrapper (const char *prompt)
 {
   struct ui *ui = current_ui;
-  struct cleanup *back_to;
-  struct gdb_readline_wrapper_cleanup *cleanup;
-  char *retval;
-
-  cleanup = XNEW (struct gdb_readline_wrapper_cleanup);
-  cleanup->handler_orig = ui->input_handler;
-  ui->input_handler = gdb_readline_wrapper_line;
-
-  if (ui->command_editing)
-    cleanup->already_prompted_orig = rl_already_prompted;
-  else
-    cleanup->already_prompted_orig = 0;
-
-  cleanup->target_is_async_orig = target_is_async_p ();
 
-  ui->secondary_prompt_depth++;
-  back_to = make_cleanup (gdb_readline_wrapper_cleanup, cleanup);
+  gdb_readline_wrapper_cleanup cleanup (ui);
 
   /* Processing events may change the current UI.  */
   scoped_restore save_ui = make_scoped_restore (&current_ui);
 
-  if (cleanup->target_is_async_orig)
+  if (cleanup.target_is_async_orig)
     target_async (0);
 
   /* Display our prompt and prevent double prompt display.  Don't pass
@@ -1004,9 +995,7 @@ gdb_readline_wrapper (const char *prompt)
     if (gdb_readline_wrapper_done)
       break;
 
-  retval = gdb_readline_wrapper_result;
-  do_cleanups (back_to);
-  return retval;
+  return gdb_readline_wrapper_result;
 }
 
 
-- 
2.13.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]