From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84920 invoked by alias); 11 Apr 2017 01:48:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 84668 invoked by uid 89); 11 Apr 2017 01:48:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=personal X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 01:48:21 +0000 Received: by simark.ca (Postfix, from userid 33) id 25CF41E938; Mon, 10 Apr 2017 21:48:16 -0400 (EDT) To: Tom Tromey Subject: Re: [RFA 11/14] Use scoped_restore in more places X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 11 Apr 2017 01:48:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: <20170408201208.2672-12-tom@tromey.com> References: <20170408201208.2672-1-tom@tromey.com> <20170408201208.2672-12-tom@tromey.com> Message-ID: <356668010d7833e53ed76b67dc574524@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.4 X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00257.txt.bz2 On 2017-04-08 16:12, Tom Tromey wrote: > diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c > index fc14465..29a2e04 100644 > --- a/gdb/cli/cli-decode.c > +++ b/gdb/cli/cli-decode.c > @@ -1878,17 +1878,14 @@ cmd_func (struct cmd_list_element *cmd, char > *args, int from_tty) > { > if (cmd_func_p (cmd)) > { > - struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); > - > - if (cmd->suppress_notification != NULL) > - { > - make_cleanup_restore_integer (cmd->suppress_notification); > - *cmd->suppress_notification = 1; > - } > + int dummy = 0; > + scoped_restore restore_suppress > + = make_scoped_restore (cmd->suppress_notification cmd->suppress_notification != NULL > + ? cmd->suppress_notification > + : &dummy, > + 1); My personal preference though would be a scoped_restore wrapped in an optional, I find it more readable: gdb::optional> restore_suppress; if (cmd->suppress_notification != NULL) restore_suppress.emplace (cmd->suppress_notification, 1); > @@ -2140,15 +2132,16 @@ mi_execute_command (const char *cmd, int > from_tty) > if (command != NULL) > { > ptid_t previous_ptid = inferior_ptid; > - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); > > - command->token = token; > + int dummy = 0; > + scoped_restore restore_suppress > + = make_scoped_restore ((command->cmd != NULL > + && command->cmd->suppress_notification != NULL) > + ? command->cmd->suppress_notification > + : &dummy, > + 1); Same here: gdb::optional> restore_suppress; if (command->cmd != NULL && command->cmd->suppress_notification != NULL) restore_suppress.emplace (command->cmd->suppress_notification, 1); Simon