Remove cleanups from TUI
authorTom Tromey <tom@tromey.com>
Tue, 10 Oct 2017 01:13:31 +0000 (19:13 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 11 Oct 2017 22:21:43 +0000 (16:21 -0600)
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
gdb/tui/tui-layout.c
gdb/tui/tui-win.c

index 60be796..532c2b9 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2017-10-11  Tom Tromey  <tom@tromey.com>
 
        * gdbthread.h (thread_command): Constify.
index eab1ab6..fe68331 100644 (file)
@@ -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;
index 7dbd76b..26b6b5e 100644 (file)
@@ -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);
     }
 }