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 3/8] Replace clear_hook_in_cleanup with scoped_restore_hook_in
Date: Sun, 10 Sep 2017 21:50:00 -0000	[thread overview]
Message-ID: <20170910215037.24329-4-tom@tromey.com> (raw)
In-Reply-To: <20170910215037.24329-1-tom@tromey.com>

This removes clear_hook_in_cleanup in favor of a scoped_restore-like
class.  scoped_restore itself can't be used because hook_in is a
bitfield.

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

	* cli/cli-script.c (class scoped_restore_hook_in): New.
	(clear_hook_in_cleanup): Remove.
	(execute_cmd_pre_hook, execute_cmd_post_hook): Use
	scoped_restore_hook_in.
---
 gdb/ChangeLog        |  7 +++++++
 gdb/cli/cli-script.c | 31 +++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index de88894..62d3d3c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2017-09-10  Tom Tromey  <tom@tromey.com>
 
+	* cli/cli-script.c (class scoped_restore_hook_in): New.
+	(clear_hook_in_cleanup): Remove.
+	(execute_cmd_pre_hook, execute_cmd_post_hook): Use
+	scoped_restore_hook_in.
+
+2017-09-10  Tom Tromey  <tom@tromey.com>
+
 	* cli/cli-script.c (restore_interp): Remove.
 	(read_command_lines): Use scoped_restore_interp.
 	* interps.c (scoped_restore_interp::set_temp): Rename from
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 805064f..9b7ca12 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -340,23 +340,36 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
 
 /* Handle pre-post hooks.  */
 
-static void
-clear_hook_in_cleanup (void *data)
+class scoped_restore_hook_in
 {
-  struct cmd_list_element *c = (struct cmd_list_element *) data;
+public:
 
-  c->hook_in = 0; /* Allow hook to work again once it is complete.  */
-}
+  scoped_restore_hook_in (struct cmd_list_element *c)
+    : m_cmd (c)
+  {
+  }
+
+  ~scoped_restore_hook_in ()
+  {
+    m_cmd->hook_in = 0;
+  }
+
+  scoped_restore_hook_in (const scoped_restore_hook_in &) = delete;
+  scoped_restore_hook_in &operator= (const scoped_restore_hook_in &) = delete;
+
+private:
+
+  struct cmd_list_element *m_cmd;
+};
 
 void
 execute_cmd_pre_hook (struct cmd_list_element *c)
 {
   if ((c->hook_pre) && (!c->hook_in))
     {
-      struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
+      scoped_restore_hook_in restore_hook (c);
       c->hook_in = 1; /* Prevent recursive hooking.  */
       execute_user_command (c->hook_pre, (char *) 0);
-      do_cleanups (cleanups);
     }
 }
 
@@ -365,11 +378,9 @@ execute_cmd_post_hook (struct cmd_list_element *c)
 {
   if ((c->hook_post) && (!c->hook_in))
     {
-      struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
-
+      scoped_restore_hook_in restore_hook (c);
       c->hook_in = 1; /* Prevent recursive hooking.  */
       execute_user_command (c->hook_post, (char *) 0);
-      do_cleanups (cleanups);
     }
 }
 
-- 
2.9.4


  parent reply	other threads:[~2017-09-10 21:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-10 21:50 [RFA 0/8] various cleanup removals Tom Tromey
2017-09-10 21:50 ` [RFA 6/8] Use std::string in ctf_start Tom Tromey
2017-09-10 21:50 ` [RFA 1/8] Change setup_breakpoint_reporting to return a scoped_restore Tom Tromey
2017-09-10 21:50 ` Tom Tromey [this message]
2017-09-10 21:50 ` [RFA 8/8] Remove make_show_memory_breakpoints_cleanup Tom Tromey
2017-09-11 20:34   ` Simon Marchi
2017-09-10 21:50 ` [RFA 7/8] Use std::string in d-namespace.c Tom Tromey
2017-09-10 21:50 ` [RFA 4/8] Remove cleanups from findcmd.c Tom Tromey
2017-09-10 21:50 ` [RFA 2/8] Replace interp_set_temp with scoped_restore_interp Tom Tromey
2017-09-10 21:50 ` [RFA 5/8] Remove cleanups from find_frame_funname Tom Tromey
2017-09-11 20:25   ` Simon Marchi
2017-09-11 20:35 ` [RFA 0/8] various cleanup removals Simon Marchi
2017-09-11 22:04   ` Tom Tromey

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=20170910215037.24329-4-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