This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 11/14] Use scoped_restore in more places


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]