[RFA] Remove cleanups from TUI

Message ID 20171010202558.29742-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Oct. 10, 2017, 8:25 p.m. UTC
  This removes the last cleanups from the TUI, by using std::string
rather than manual memory management.

Regression tested against gdb.tui/*.exp on Fedora 26 x86-64.

gdb/ChangeLog
2017-10-09  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c (tui_set_win_height, parse_scrolling_args): Use
	std::string.
	* tui/tui-layout.c (enum tui_status): Use std::string.
---
 gdb/ChangeLog        |  6 ++++++
 gdb/tui/tui-layout.c | 11 ++++-------
 gdb/tui/tui-win.c    | 15 +++++----------
 3 files changed, 15 insertions(+), 17 deletions(-)
  

Comments

Pedro Alves Oct. 11, 2017, 12:58 p.m. UTC | #1
On 10/10/2017 09:25 PM, Tom Tromey wrote:
> This removes the last cleanups from the TUI, by using std::string

Hurray!

> rather than manual memory management.
> 
> Regression tested against gdb.tui/*.exp on Fedora 26 x86-64.
> 
> gdb/ChangeLog
> 2017-10-09  Tom Tromey  <tom@tromey.com>
> 
> 	* tui/tui-win.c (tui_set_win_height, parse_scrolling_args): Use
> 	std::string.
> 	* tui/tui-layout.c (enum tui_status): Use std::string.

OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index eab1ab6336..fe68331b5b 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -404,15 +404,13 @@  tui_set_layout_by_name (const char *layout_name)
   if (layout_name != (char *) NULL)
     {
       int i;
-      char *buf_ptr;
       enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
       enum tui_layout_type cur_layout = tui_current_layout ();
-      struct cleanup *old_chain;
 
-      buf_ptr = (char *) xstrdup (layout_name);
-      for (i = 0; (i < strlen (layout_name)); i++)
-	buf_ptr[i] = toupper (buf_ptr[i]);
-      old_chain = make_cleanup (xfree, buf_ptr);
+      std::string copy = layout_name;
+      for (i = 0; i < copy.size (); i++)
+	copy[i] = toupper (copy[i]);
+      const char *buf_ptr = copy.c_str ();
 
       /* First check for ambiguous input.  */
       if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
@@ -450,7 +448,6 @@  tui_set_layout_by_name (const char *layout_name)
 	      tui_set_layout (new_layout);
 	    }
 	}
-      do_cleanups (old_chain);
     }
   else
     status = TUI_FAILURE;
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index cb8e475b72..a7ab960f40 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -1165,14 +1165,13 @@  tui_set_win_height (char *arg, int from_tty)
   tui_enable ();
   if (arg != (char *) NULL)
     {
-      char *buf = xstrdup (arg);
+      std::string copy = arg;
+      char *buf = &copy[0];
       char *buf_ptr = buf;
       char *wname = NULL;
       int new_height, i;
       struct tui_win_info *win_info;
-      struct cleanup *old_chain;
 
-      old_chain = make_cleanup (xfree, buf);
       wname = buf_ptr;
       buf_ptr = strchr (buf_ptr, ' ');
       if (buf_ptr != (char *) NULL)
@@ -1234,8 +1233,6 @@  The window name specified must be valid and visible.\n"));
 	}
       else
 	printf_filtered (WIN_HEIGHT_USAGE);
-
-      do_cleanups (old_chain);
     }
   else
     printf_filtered (WIN_HEIGHT_USAGE);
@@ -1661,12 +1658,11 @@  parse_scrolling_args (char *arg,
      window name arg.  */
   if (arg != (char *) NULL)
     {
-      char *buf, *buf_ptr;
-      struct cleanup *old_chain;
+      char *buf_ptr;
 
       /* Process the number of lines to scroll.  */
-      buf = buf_ptr = xstrdup (arg);
-      old_chain = make_cleanup (xfree, buf);
+      std::string copy = arg;
+      buf_ptr = &copy[0];
       if (isdigit (*buf_ptr))
 	{
 	  char *num_str;
@@ -1713,6 +1709,5 @@  The window name specified must be valid and visible.\n"));
 	  else if (*win_to_scroll == TUI_CMD_WIN)
 	    *win_to_scroll = (tui_source_windows ())->list[0];
 	}
-      do_cleanups (old_chain);
     }
 }