This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 11/14] Use scoped_restore in more places
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Tom Tromey <tom at tromey dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 10 Apr 2017 21:48:16 -0400
- Subject: Re: [RFA 11/14] Use scoped_restore in more places
- Authentication-results: sourceware.org; auth=none
- References: <20170408201208.2672-1-tom@tromey.com> <20170408201208.2672-12-tom@tromey.com>
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<scoped_restore_tmpl<int>> 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<scoped_restore_tmpl<int>> restore_suppress;
if (command->cmd != NULL && command->cmd->suppress_notification !=
NULL)
restore_suppress.emplace (command->cmd->suppress_notification, 1);
Simon