[RFA,v2,17/24] Remove user_call_depth

Message ID 20170725172107.9799-18-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey July 25, 2017, 5:21 p.m. UTC
  This changes execute_user_command to remove user_call_depth, using the
size of user_args_stack instead.  This avoids a cleanup.

ChangeLog
2017-07-25  Tom Tromey  <tom@tromey.com>

	* cli/cli-script.c (do_restore_user_call_depth): Remove.
	(execute_user_command): Remove user_call_depth; use
	user_args_stack's size instead.
---
 gdb/ChangeLog        |  6 ++++++
 gdb/cli/cli-script.c | 18 ++++--------------
 2 files changed, 10 insertions(+), 14 deletions(-)
  

Comments

Simon Marchi July 31, 2017, 7:45 p.m. UTC | #1
On 2017-07-25 19:21, Tom Tromey wrote:
> This changes execute_user_command to remove user_call_depth, using the
> size of user_args_stack instead.  This avoids a cleanup.
> 
> ChangeLog
> 2017-07-25  Tom Tromey  <tom@tromey.com>
> 
> 	* cli/cli-script.c (do_restore_user_call_depth): Remove.
> 	(execute_user_command): Remove user_call_depth; use
> 	user_args_stack's size instead.
> ---
>  gdb/ChangeLog        |  6 ++++++
>  gdb/cli/cli-script.c | 18 ++++--------------
>  2 files changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 8564f9f..f81185a 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,5 +1,11 @@
>  2017-07-25  Tom Tromey  <tom@tromey.com>
> 
> +	* cli/cli-script.c (do_restore_user_call_depth): Remove.
> +	(execute_user_command): Remove user_call_depth; use
> +	user_args_stack's size instead.
> +
> +2017-07-25  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 527540a..edaebef 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 (&current_ui->async, 
> 0);

Hi Tom,

This patch seems to still contain the changes of v1.

Simon
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8564f9f..f81185a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@ 
 2017-07-25  Tom Tromey  <tom@tromey.com>
 
+	* cli/cli-script.c (do_restore_user_call_depth): Remove.
+	(execute_user_command): Remove user_call_depth; use
+	user_args_stack's size instead.
+
+2017-07-25  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 527540a..edaebef 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 (&current_ui->async, 0);