[15/15] gdb/tui: make use of a scoped_restore

Message ID 086366914f866559bc26512dfc67cf1f9fae2964.1673000632.git.aburgess@redhat.com
State Committed
Commit 2e10cefd83b6a5b0b3745da1134d35a4924db6c5
Headers
Series Mixed bag of TUI tests and fixes |

Commit Message

Andrew Burgess Jan. 6, 2023, 10:25 a.m. UTC
  Make use of a scoped_restore object in tui_mld_read_key instead of
doing a manual save/restore.

I don't think the existing code can throw an exception, so this is
just a cleanup rather than a bug fix.

There should be no user visible changes after this commit.
---
 gdb/tui/tui-io.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
  

Comments

Andrew Burgess Jan. 25, 2023, 12:01 p.m. UTC | #1
Andrew Burgess <aburgess@redhat.com> writes:

> Make use of a scoped_restore object in tui_mld_read_key instead of
> doing a manual save/restore.
>
> I don't think the existing code can throw an exception, so this is
> just a cleanup rather than a bug fix.
>
> There should be no user visible changes after this commit.

I've gone ahead and pushed this patch.

Thanks,
Andrew

> ---
>  gdb/tui/tui-io.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
> index 2f39e34df2f..a17cf38a1f2 100644
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -773,14 +773,10 @@ tui_mld_getc (FILE *fp)
>  static int
>  tui_mld_read_key (const struct match_list_displayer *displayer)
>  {
> -  rl_getc_func_t *prev = rl_getc_function;
> -  int c;
> -
>    /* We can't use tui_getc as we need NEWLINE to not get emitted.  */
> -  rl_getc_function = tui_mld_getc;
> -  c = rl_read_key ();
> -  rl_getc_function = prev;
> -  return c;
> +  scoped_restore restore_getc_function
> +    = make_scoped_restore (&rl_getc_function, tui_mld_getc);
> +  return rl_read_key ();
>  }
>  
>  /* TUI version of rl_completion_display_matches_hook.
> -- 
> 2.25.4
  

Patch

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 2f39e34df2f..a17cf38a1f2 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -773,14 +773,10 @@  tui_mld_getc (FILE *fp)
 static int
 tui_mld_read_key (const struct match_list_displayer *displayer)
 {
-  rl_getc_func_t *prev = rl_getc_function;
-  int c;
-
   /* We can't use tui_getc as we need NEWLINE to not get emitted.  */
-  rl_getc_function = tui_mld_getc;
-  c = rl_read_key ();
-  rl_getc_function = prev;
-  return c;
+  scoped_restore restore_getc_function
+    = make_scoped_restore (&rl_getc_function, tui_mld_getc);
+  return rl_read_key ();
 }
 
 /* TUI version of rl_completion_display_matches_hook.