[RFA,v2,12/17] Remove make_cleanup_restore_current_uiout

Message ID 1476393012-29987-13-git-send-email-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Oct. 13, 2016, 9:10 p.m. UTC
  This removes make_cleanup_restore_current_uiout in favor of an
RAII-based class.

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

	* stack.c (print_stack_frame_to_uiout): Use scoped_restore.
	* ui-out.c (make_cleanup_restore_current_uiout)
	(restore_current_uiout_cleanup): Remove.
	* infrun.c (print_stop_event): Use scoped_restore.
	* ui-out.h (make_cleanup_restore_current_uiout): Don't declare.
---
 gdb/ChangeLog       |  8 ++++++++
 gdb/infrun.c        | 15 +++++++--------
 gdb/python/python.c |  2 +-
 gdb/stack.c         |  7 +------
 gdb/ui-out.c        | 18 ------------------
 gdb/ui-out.h        |  4 ----
 6 files changed, 17 insertions(+), 37 deletions(-)
  

Comments

Pedro Alves Oct. 13, 2016, 10:49 p.m. UTC | #1
On 10/13/2016 10:10 PM, Tom Tromey wrote:

> -  print_stop_location (&last);
> +  {
> +    scoped_restore save_uiout = make_scoped_restore (&current_uiout);
> +    current_uiout = uiout;

I wonder if you had a reasoning that led to deciding when
to use two-argument form?  A couple places looked like obvious
candidates.  My reasoning would be: if the assignment is right
after the scoped_restore creation.

Anyway, this is OK.

Thanks,
Pedro Alves
  
Tom Tromey Oct. 14, 2016, 9:29 p.m. UTC | #2
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> I wonder if you had a reasoning that led to deciding when
Pedro> to use two-argument form?  A couple places looked like obvious
Pedro> candidates.  My reasoning would be: if the assignment is right
Pedro> after the scoped_restore creation.

I tried to use them everywhere, but I just forgot to restore it in this
patch when I added the two-arg form back.  I'll fix this up.

Tom
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ea777f6..d2e51f4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@ 
+2016-10-10  Tom Tromey  <tom@tromey.com>
+
+	* stack.c (print_stack_frame_to_uiout): Use scoped_restore.
+	* ui-out.c (make_cleanup_restore_current_uiout)
+	(restore_current_uiout_cleanup): Remove.
+	* infrun.c (print_stop_event): Use scoped_restore.
+	* ui-out.h (make_cleanup_restore_current_uiout): Don't declare.
+
 2016-09-26  Tom Tromey  <tom@tromey.com>
 
 	* elfread.c (elf_read_minimal_symbols): Use gdb::unique_ptr.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 1864019..493a25e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8082,22 +8082,21 @@  print_stop_location (struct target_waitstatus *ws)
 void
 print_stop_event (struct ui_out *uiout)
 {
-  struct cleanup *old_chain;
   struct target_waitstatus last;
   ptid_t last_ptid;
   struct thread_info *tp;
 
   get_last_target_status (&last_ptid, &last);
 
-  old_chain = make_cleanup_restore_current_uiout ();
-  current_uiout = uiout;
-
-  print_stop_location (&last);
+  {
+    scoped_restore save_uiout = make_scoped_restore (&current_uiout);
+    current_uiout = uiout;
 
-  /* Display the auto-display expressions.  */
-  do_displays ();
+    print_stop_location (&last);
 
-  do_cleanups (old_chain);
+    /* Display the auto-display expressions.  */
+    do_displays ();
+  }
 
   tp = inferior_thread ();
   if (tp->thread_fsm != NULL
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 53f83b8..d9940c2 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -649,7 +649,7 @@  execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
       scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
-      make_cleanup_restore_current_uiout ();
+      scoped_restore save_uiout = make_scoped_restore (&current_uiout);
 
       /* Use the console interpreter uiout to have the same print format
 	for console or MI.  */
diff --git a/gdb/stack.c b/gdb/stack.c
index 0f8b336..44ee81d 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -149,15 +149,10 @@  print_stack_frame_to_uiout (struct ui_out *uiout, struct frame_info *frame,
 			    int print_level, enum print_what print_what,
 			    int set_current_sal)
 {
-  struct cleanup *old_chain;
-
-  old_chain = make_cleanup_restore_current_uiout ();
-
+  scoped_restore save_uiout = make_scoped_restore (&current_uiout);
   current_uiout = uiout;
 
   print_stack_frame (frame, print_level, print_what, set_current_sal);
-
-  do_cleanups (old_chain);
 }
 
 /* Show or print a stack frame FRAME briefly.  The output is formatted
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 9b1df3c..8c39198 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -949,24 +949,6 @@  ui_out_destroy (struct ui_out *uiout)
   xfree (uiout);
 }
 
-/* Cleanup that restores a previous current uiout.  */
-
-static void
-restore_current_uiout_cleanup (void *arg)
-{
-  struct ui_out *saved_uiout = (struct ui_out *) arg;
-
-  current_uiout = saved_uiout;
-}
-
-/* See ui-out.h.  */
-
-struct cleanup *
-make_cleanup_restore_current_uiout (void)
-{
-  return make_cleanup (restore_current_uiout_cleanup, current_uiout);
-}
-
 /* Standard gdb initialization hook.  */
 
 void
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 6a4d78a..9e1e74d 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -247,8 +247,4 @@  extern void ui_out_destroy (struct ui_out *uiout);
 
 extern int ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream);
 
-/* Make a cleanup that restores the previous current uiout.  */
-
-extern struct cleanup *make_cleanup_restore_current_uiout (void);
-
 #endif /* UI_OUT_H */