[binutils-gdb] Use ui_file_as_string in gdb/ui-out.c

Pedro Alves palves@sourceware.org
Tue Nov 8 15:30:00 GMT 2016


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=56dbf31760f721893a44d3da26adfccf548995c7

commit 56dbf31760f721893a44d3da26adfccf548995c7
Author: Pedro Alves <palves@redhat.com>
Date:   Tue Nov 8 15:26:44 2016 +0000

    Use ui_file_as_string in gdb/ui-out.c
    
    gdb/ChangeLog:
    2016-11-08  Pedro Alves  <palves@redhat.com>
    
    	* ui-out.c (ui_out_field_stream): Use ui_file_as_string.

Diff:
---
 gdb/ChangeLog | 4 ++++
 gdb/ui-out.c  | 9 +++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2760580..7855776 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2016-11-08  Pedro Alves  <palves@redhat.com>
 
+	* ui-out.c (ui_out_field_stream): Use ui_file_as_string.
+
+2016-11-08  Pedro Alves  <palves@redhat.com>
+
 	* ada-valprint.c (ada_print_floating): Use ui_file_as_string and
 	std::string.
 
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 0eaa48f..60d18ee 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -425,16 +425,13 @@ ui_out_field_stream (struct ui_out *uiout,
 		     const char *fldname,
 		     struct ui_file *stream)
 {
-  long length;
-  char *buffer = ui_file_xstrdup (stream, &length);
-  struct cleanup *old_cleanup = make_cleanup (xfree, buffer);
+  std::string buffer = ui_file_as_string (stream);
 
-  if (length > 0)
-    ui_out_field_string (uiout, fldname, buffer);
+  if (!buffer.empty ())
+    ui_out_field_string (uiout, fldname, buffer.c_str ());
   else
     ui_out_field_skip (uiout, fldname);
   ui_file_rewind (stream);
-  do_cleanups (old_cleanup);
 }
 
 /* Used to omit a field.  */



More information about the Gdb-cvs mailing list