From patchwork Sun Sep 10 21:50:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22806 Received: (qmail 41990 invoked by alias); 10 Sep 2017 21:50:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 41678 invoked by uid 89); 10 Sep 2017 21:50:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2017091 X-HELO: gproxy8-pub.mail.unifiedlayer.com Received: from gproxy8-pub.mail.unifiedlayer.com (HELO gproxy8-pub.mail.unifiedlayer.com) (67.222.33.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 21:50:46 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy8.mail.unifiedlayer.com (Postfix) with ESMTP id D70FC1AB090 for ; Sun, 10 Sep 2017 15:50:44 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 7xqh1w00Q2f2jeq01xqkCt; Sun, 10 Sep 2017 15:50:44 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=509fkm8zpWdOnoX5e2sA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:39396 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1drA7l-0020eg-BO; Sun, 10 Sep 2017 15:50:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/8] Replace clear_hook_in_cleanup with scoped_restore_hook_in Date: Sun, 10 Sep 2017 15:50:32 -0600 Message-Id: <20170910215037.24329-4-tom@tromey.com> In-Reply-To: <20170910215037.24329-1-tom@tromey.com> References: <20170910215037.24329-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1drA7l-0020eg-BO X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:39396 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes 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 * 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 + * 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 + * 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); } }