This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Use ui_file_as_string in gdb/ada-valprint.c


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

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

    Use ui_file_as_string in gdb/ada-valprint.c
    
    gdb/ChangeLog:
    2016-11-08  Pedro Alves  <palves@redhat.com>
    
    	* ada-valprint.c (ada_print_floating): Use ui_file_as_string and
    	std::string.

Diff:
---
 gdb/ChangeLog      |  5 +++++
 gdb/ada-valprint.c | 53 +++++++++++++++++++++++++++--------------------------
 2 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1217550..2760580 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2016-11-08  Pedro Alves  <palves@redhat.com>
 
+	* ada-valprint.c (ada_print_floating): Use ui_file_as_string and
+	std::string.
+
+2016-11-08  Pedro Alves  <palves@redhat.com>
+
 	* xtensa-tdep.c (xtensa_verify_config): Use ui_file_as_string and
 	std::string.
 
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 6b4b6d4..bae4e4f 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -298,49 +298,50 @@ static void
 ada_print_floating (const gdb_byte *valaddr, struct type *type,
 		    struct ui_file *stream)
 {
-  char *s, *result;
   struct ui_file *tmp_stream = mem_fileopen ();
   struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream);
 
   print_floating (valaddr, type, tmp_stream);
-  result = ui_file_xstrdup (tmp_stream, NULL);
-  make_cleanup (xfree, result);
+
+  std::string s = ui_file_as_string (tmp_stream);
+  size_t skip_count = 0;
 
   /* Modify for Ada rules.  */
 
-  s = strstr (result, "inf");
-  if (s == NULL)
-    s = strstr (result, "Inf");
-  if (s == NULL)
-    s = strstr (result, "INF");
-  if (s != NULL)
-    strcpy (s, "Inf");
+  size_t pos = s.find ("inf");
+  if (pos == std::string::npos)
+    pos = s.find ("Inf");
+  if (pos == std::string::npos)
+    pos = s.find ("INF");
+  if (pos != std::string::npos)
+    s.replace (pos, 3, "Inf");
 
-  if (s == NULL)
+  if (pos == std::string::npos)
     {
-      s = strstr (result, "nan");
-      if (s == NULL)
-	s = strstr (result, "NaN");
-      if (s == NULL)
-	s = strstr (result, "Nan");
-      if (s != NULL)
+      pos = s.find ("nan");
+      if (pos == std::string::npos)
+	pos = s.find ("NaN");
+      if (pos == std::string::npos)
+	pos = s.find ("Nan");
+      if (pos != std::string::npos)
 	{
-	  s[0] = s[2] = 'N';
-	  if (result[0] == '-')
-	    result += 1;
+	  s[pos] = s[pos + 2] = 'N';
+	  if (s[0] == '-')
+	    skip_count = 1;
 	}
     }
 
-  if (s == NULL && strchr (result, '.') == NULL)
+  if (pos == std::string::npos
+      && s.find ('.') == std::string::npos)
     {
-      s = strchr (result, 'e');
-      if (s == NULL)
-	fprintf_filtered (stream, "%s.0", result);
+      pos = s.find ('e');
+      if (pos == std::string::npos)
+	fprintf_filtered (stream, "%s.0", s.c_str ());
       else
-	fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
+	fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
     }
   else
-    fprintf_filtered (stream, "%s", result);
+    fprintf_filtered (stream, "%s", &s[skip_count]);
 
   do_cleanups (cleanups);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]