Remove cleanups from utils.c
authorTom Tromey <tom@tromey.com>
Thu, 28 Sep 2017 02:38:07 +0000 (20:38 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 30 Sep 2017 02:46:43 +0000 (20:46 -0600)
This removes a couple of cleanups from utils.c through the use of
std::string.

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

* utils.c (vfprintf_maybe_filtered): Use std::string.
(vfprintf_unfiltered): Likewise.

gdb/ChangeLog
gdb/utils.c

index 48f1f894fdad06145a2f6f3f8b3cb6246c22ada1..0e76e7f559ded42a3f3f6065d6257c70e9db7073 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-29  Tom Tromey  <tom@tromey.com>
+
+       * utils.c (vfprintf_maybe_filtered): Use std::string.
+       (vfprintf_unfiltered): Likewise.
+
 2017-09-29  Tom Tromey  <tom@tromey.com>
 
        * event-top.c (top_level_prompt): Return std::string.
index 24294be4f4989493350796d2ddfdbddff57f7293..b2e08132ba8a46fb1ca02141b081c286ec9436a4 100644 (file)
@@ -2036,13 +2036,8 @@ static void
 vfprintf_maybe_filtered (struct ui_file *stream, const char *format,
                         va_list args, int filter)
 {
-  char *linebuffer;
-  struct cleanup *old_cleanups;
-
-  linebuffer = xstrvprintf (format, args);
-  old_cleanups = make_cleanup (xfree, linebuffer);
-  fputs_maybe_filtered (linebuffer, stream, filter);
-  do_cleanups (old_cleanups);
+  std::string linebuffer = string_vprintf (format, args);
+  fputs_maybe_filtered (linebuffer.c_str (), stream, filter);
 }
 
 
@@ -2055,11 +2050,7 @@ vfprintf_filtered (struct ui_file *stream, const char *format, va_list args)
 void
 vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
 {
-  char *linebuffer;
-  struct cleanup *old_cleanups;
-
-  linebuffer = xstrvprintf (format, args);
-  old_cleanups = make_cleanup (xfree, linebuffer);
+  std::string linebuffer = string_vprintf (format, args);
   if (debug_timestamp && stream == gdb_stdlog)
     {
       using namespace std::chrono;
@@ -2069,18 +2060,18 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
       seconds s = duration_cast<seconds> (now.time_since_epoch ());
       microseconds us = duration_cast<microseconds> (now.time_since_epoch () - s);
 
-      len = strlen (linebuffer);
+      len = linebuffer.size ();
       need_nl = (len > 0 && linebuffer[len - 1] != '\n');
 
       std::string timestamp = string_printf ("%ld.%06ld %s%s",
                                             (long) s.count (),
                                             (long) us.count (),
-                                            linebuffer, need_nl ? "\n": "");
+                                            linebuffer.c_str (),
+                                            need_nl ? "\n": "");
       fputs_unfiltered (timestamp.c_str (), stream);
     }
   else
-    fputs_unfiltered (linebuffer, stream);
-  do_cleanups (old_cleanups);
+    fputs_unfiltered (linebuffer.c_str (), stream);
 }
 
 void