]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Replace clear_hook_in_cleanup with scoped_restore_hook_in
authorTom Tromey <tom@tromey.com>
Sun, 13 Aug 2017 20:44:08 +0000 (14:44 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 11 Sep 2017 22:15:09 +0000 (16:15 -0600)
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-11  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
gdb/cli/cli-script.c

index 00fbd0b0a3ac47bffc60ba0c478ea961de080637..a0dfb7823839547b496b296e1709aa93840144d8 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-11  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-11  Tom Tromey  <tom@tromey.com>
 
        * cli/cli-script.c (restore_interp): Remove.
index dc3e856bcfddda51a0316b9baf114494dd5d5936..37466fd76633f37c0c56ce91251d3de01e7be392 100644 (file)
@@ -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);
     }
 }