Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 2/8] Remove set_batch_flag_and_make_cleanup_restore_page_info
Date: Sun, 01 Oct 2017 04:07:00 -0000	[thread overview]
Message-ID: <20171001040643.25162-3-tom@tromey.com> (raw)
In-Reply-To: <20171001040643.25162-1-tom@tromey.com>

This removes set_batch_flag_and_make_cleanup_restore_page_info and
make_cleanup_restore_page_info in favor of a new RAII class.  This
then allows for the removal of make_cleanup_restore_uinteger and
make_cleanup_restore_integer

ChangeLog
2017-09-30  Tom Tromey  <tom@tromey.com>

	* guile/scm-ports.c (ioscm_with_output_to_port_worker): Update.
	* top.c (execute_command_to_string): Update.
	* utils.c (make_cleanup_restore_page_info): Remove.
	(do_restore_page_info_cleanup): Remove.
	(set_batch_flag_and_restore_page_info):
	New.
	(make_cleanup_restore_page_info): Remove.
	(set_batch_flag_and_make_cleanup_restore_page_info): Remove.
	(~set_batch_flag_and_restore_page_info): New
	(make_cleanup_restore_uinteger): Remove.
	(make_cleanup_restore_integer): Remove.
	(struct restore_integer_closure): Remove.
	(restore_integer): Remove.
	* utils.h (struct set_batch_flag_and_restore_page_info): New
	class.
	(set_batch_flag_and_make_cleanup_restore_page_info): Remove.
	(make_cleanup_restore_page_info): Remove.
	(make_cleanup_restore_uinteger) Remove.
	(make_cleanup_restore_integer) Remove.
---
 gdb/ChangeLog         | 22 ++++++++++++++
 gdb/guile/scm-ports.c |  5 +---
 gdb/top.c             |  6 +---
 gdb/utils.c           | 81 ++++++++-------------------------------------------
 gdb/utils.h           | 27 +++++++++++++----
 5 files changed, 57 insertions(+), 84 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a415c18..a17a83c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,27 @@
 2017-09-30  Tom Tromey  <tom@tromey.com>
 
+	* guile/scm-ports.c (ioscm_with_output_to_port_worker): Update.
+	* top.c (execute_command_to_string): Update.
+	* utils.c (make_cleanup_restore_page_info): Remove.
+	(do_restore_page_info_cleanup): Remove.
+	(set_batch_flag_and_restore_page_info):
+	New.
+	(make_cleanup_restore_page_info): Remove.
+	(set_batch_flag_and_make_cleanup_restore_page_info): Remove.
+	(~set_batch_flag_and_restore_page_info): New
+	(make_cleanup_restore_uinteger): Remove.
+	(make_cleanup_restore_integer): Remove.
+	(struct restore_integer_closure): Remove.
+	(restore_integer): Remove.
+	* utils.h (struct set_batch_flag_and_restore_page_info): New
+	class.
+	(set_batch_flag_and_make_cleanup_restore_page_info): Remove.
+	(make_cleanup_restore_page_info): Remove.
+	(make_cleanup_restore_uinteger) Remove.
+	(make_cleanup_restore_integer) Remove.
+
+2017-09-30  Tom Tromey  <tom@tromey.com>
+
 	* record-full.h (record_full_gdb_operation_disable_set): Return
 	scoped_restore_tmpl<int>.
 	* infrun.c (adjust_pc_after_break): Update.
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 78187c4..a7c0bd4 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -461,7 +461,6 @@ static SCM
 ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
 				  const char *func_name)
 {
-  struct cleanup *cleanups;
   SCM result;
 
   SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port,
@@ -469,7 +468,7 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
   SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk,
 		   SCM_ARG2, func_name, _("thunk"));
 
-  cleanups = set_batch_flag_and_make_cleanup_restore_page_info ();
+  set_batch_flag_and_restore_page_info save_page_info;
 
   scoped_restore restore_async = make_scoped_restore (&current_ui->async, 0);
 
@@ -493,8 +492,6 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
     result = gdbscm_safe_call_0 (thunk, NULL);
   }
 
-  do_cleanups (cleanups);
-
   if (gdbscm_is_exception (result))
     gdbscm_throw (result);
 
diff --git a/gdb/top.c b/gdb/top.c
index 4fc987c..56117a3 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -666,11 +666,9 @@ execute_command (char *p, int from_tty)
 std::string
 execute_command_to_string (char *p, int from_tty)
 {
-  struct cleanup *cleanup;
-
   /* GDB_STDOUT should be better already restored during these
      restoration callbacks.  */
-  cleanup = set_batch_flag_and_make_cleanup_restore_page_info ();
+  set_batch_flag_and_restore_page_info save_page_info;
 
   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
@@ -694,8 +692,6 @@ execute_command_to_string (char *p, int from_tty)
     execute_command (p, from_tty);
   }
 
-  do_cleanups (cleanup);
-
   return std::move (str_file.string ());
 }
 
diff --git a/gdb/utils.c b/gdb/utils.c
index b2e0813..0c59b4e 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -150,44 +150,6 @@ make_cleanup_free_section_addr_info (struct section_addr_info *addrs)
   return make_cleanup (do_free_section_addr_info, addrs);
 }
 
-struct restore_integer_closure
-{
-  int *variable;
-  int value;
-};
-
-static void
-restore_integer (void *p)
-{
-  struct restore_integer_closure *closure
-    = (struct restore_integer_closure *) p;
-
-  *(closure->variable) = closure->value;
-}
-
-/* Remember the current value of *VARIABLE and make it restored when
-   the cleanup is run.  */
-
-struct cleanup *
-make_cleanup_restore_integer (int *variable)
-{
-  struct restore_integer_closure *c = XNEW (struct restore_integer_closure);
-
-  c->variable = variable;
-  c->value = *variable;
-
-  return make_cleanup_dtor (restore_integer, (void *) c, xfree);
-}
-
-/* Remember the current value of *VARIABLE and make it restored when
-   the cleanup is run.  */
-
-struct cleanup *
-make_cleanup_restore_uinteger (unsigned int *variable)
-{
-  return make_cleanup_restore_integer ((int *) variable);
-}
-
 /* Helper for make_cleanup_unpush_target.  */
 
 static void
@@ -1464,42 +1426,23 @@ filtered_printing_initialized (void)
   return wrap_buffer != NULL;
 }
 
-/* Helper for make_cleanup_restore_page_info.  */
-
-static void
-do_restore_page_info_cleanup (void *arg)
-{
-  set_screen_size ();
-  set_width ();
-}
-
-/* Provide cleanup for restoring the terminal size.  */
-
-struct cleanup *
-make_cleanup_restore_page_info (void)
+set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info ()
+  : m_save_lines_per_page (lines_per_page),
+    m_save_chars_per_line (chars_per_line),
+    m_save_batch_flag (batch_flag)
 {
-  struct cleanup *back_to;
-
-  back_to = make_cleanup (do_restore_page_info_cleanup, NULL);
-  make_cleanup_restore_uinteger (&lines_per_page);
-  make_cleanup_restore_uinteger (&chars_per_line);
-
-  return back_to;
+  batch_flag = 1;
+  init_page_info ();
 }
 
-/* Temporarily set BATCH_FLAG and the associated unlimited terminal size.
-   Provide cleanup for restoring the original state.  */
-
-struct cleanup *
-set_batch_flag_and_make_cleanup_restore_page_info (void)
+set_batch_flag_and_restore_page_info::~set_batch_flag_and_restore_page_info ()
 {
-  struct cleanup *back_to = make_cleanup_restore_page_info ();
-  
-  make_cleanup_restore_integer (&batch_flag);
-  batch_flag = 1;
-  init_page_info ();
+  batch_flag = m_save_batch_flag;
+  chars_per_line = m_save_chars_per_line;
+  lines_per_page = m_save_lines_per_page;
 
-  return back_to;
+  set_screen_size ();
+  set_width ();
 }
 
 /* Set the screen size based on LINES_PER_PAGE and CHARS_PER_LINE.  */
diff --git a/gdb/utils.h b/gdb/utils.h
index 7b45cc8..022af51 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -211,9 +211,6 @@ extern struct cleanup *(make_cleanup_free_section_addr_info
 
 /* For make_cleanup_close see common/filestuff.h.  */
 
-extern struct cleanup *make_cleanup_restore_integer (int *variable);
-extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable);
-
 struct target_ops;
 extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops);
 
@@ -236,9 +233,27 @@ extern void free_current_contents (void *);
 
 extern void init_page_info (void);
 
-extern struct cleanup *make_cleanup_restore_page_info (void);
-extern struct cleanup *
-  set_batch_flag_and_make_cleanup_restore_page_info (void);
+/* Temporarily set BATCH_FLAG and the associated unlimited terminal size.
+   Restore when destroyed.  */
+
+struct set_batch_flag_and_restore_page_info
+{
+public:
+
+  set_batch_flag_and_restore_page_info ();
+  ~set_batch_flag_and_restore_page_info ();
+
+  DISABLE_COPY_AND_ASSIGN (set_batch_flag_and_restore_page_info);
+
+private:
+
+  /* Note that this doesn't use scoped_restore, because it's important
+     to control the ordering of operations in the destruction, and it
+     was simpler to avoid introducing a new ad hoc class.  */
+  unsigned m_save_lines_per_page;
+  unsigned m_save_chars_per_line;
+  int m_save_batch_flag;
+};
 
 extern struct cleanup *make_bpstat_clear_actions_cleanup (void);
 \f
-- 
2.9.5


  parent reply	other threads:[~2017-10-01  4:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-01  4:06 [RFA 0/8] more cleanup removal Tom Tromey
2017-10-01  4:06 ` [RFA 6/8] Remove make_delete_ui_cleanup Tom Tromey
2017-10-01  4:06 ` [RFA 8/8] Use std::string in info_symbol_command Tom Tromey
2017-10-01  4:06 ` [RFA 4/8] Remove unused declarations Tom Tromey
2017-10-01  4:07 ` Tom Tromey [this message]
2017-10-01  4:07 ` [RFA 5/8] Use gdb::byte_vector in load_progress Tom Tromey
2017-10-01  4:07 ` [RFA 3/8] Use std::string in utils.c Tom Tromey
2017-10-03 10:50   ` Pedro Alves
2017-10-03 11:26     ` Tom Tromey
2017-10-01  4:07 ` [RFA 7/8] Use std::string in gdb_safe_append_history Tom Tromey
2017-10-01  4:07 ` [RFA 1/8] Change record_full_gdb_operation_disable_set not to return a cleanup Tom Tromey
2017-10-03 10:55 ` [RFA 0/8] more cleanup removal Pedro Alves

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=20171001040643.25162-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@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