This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 17/23] Use a scoped_restore for user_call_depth
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Wed, 3 May 2017 16:46:20 -0600
- Subject: [RFA 17/23] Use a scoped_restore for user_call_depth
- Authentication-results: sourceware.org; auth=none
- References: <20170503224626.2818-1-tom@tromey.com>
This changes execute_user_command to use a scoped_restore for
user_call_depth. This avoids a cleanup.
2017-05-02 Tom Tromey <tom@tromey.com>
* cli/cli-script.c (do_restore_user_call_depth): Remove.
(execute_user_command): Use scoped_restore.
---
gdb/ChangeLog | 5 +++++
gdb/cli/cli-script.c | 18 ++++--------------
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 45c5db7..873b404 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-05-02 Tom Tromey <tom@tromey.com>
+ * cli/cli-script.c (do_restore_user_call_depth): Remove.
+ (execute_user_command): Use scoped_restore.
+
+2017-05-02 Tom Tromey <tom@tromey.com>
+
* top.h (in_user_command): Remove.
* top.c (in_user_command): Remove.
* cli/cli-script.c (do_restore_user_call_depth)
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 994f5c4..7f90d27 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -372,16 +372,6 @@ execute_cmd_post_hook (struct cmd_list_element *c)
}
}
-/* Execute the command in CMD. */
-static void
-do_restore_user_call_depth (void * call_depth)
-{
- int *depth = (int *) call_depth;
-
- (*depth)--;
-}
-
-
void
execute_user_command (struct cmd_list_element *c, char *args)
{
@@ -398,15 +388,15 @@ execute_user_command (struct cmd_list_element *c, char *args)
return;
scoped_user_args_level push_user_args (args);
+ scoped_restore restore_call_depth
+ = make_scoped_restore (&user_call_depth, user_call_depth + 1);
- if (++user_call_depth > max_user_call_depth)
+ if (user_call_depth > max_user_call_depth)
error (_("Max user call depth exceeded -- command aborted."));
- old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth);
-
/* Set the instream to 0, indicating execution of a
user-defined function. */
- make_cleanup (do_restore_instream_cleanup, ui->instream);
+ old_chain = make_cleanup (do_restore_instream_cleanup, ui->instream);
ui->instream = NULL;
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
--
2.9.3