public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [commit/Ada 10/11] ada_print_floating: Remove use of statically sized buffer.
Date: Tue, 07 Jan 2014 04:23:00 -0000	[thread overview]
Message-ID: <1389068515-10129-11-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <1389068515-10129-1-git-send-email-brobecker@adacore.com>

ada_print_floating declares a char buffer with a size that we're hoping
to always be large enough to hold any string representation of a float
value.  But that's not really necessary, and also forces us to create
a small wrapper (ui_memcpy) to perform the extraction from a temporary
stream into this buffer.  This patches fixes both issues by relying on
ui_file_xstrdup.  This forces us to make a few adjustments that are
minor in nature, as we now need to defer the cleanup to the end of
the function.

gdb/ChangeLog:

        * ada-valprint.c (ui_memcpy): Delete.
        (ada_print_floating): Update documentation.  Add empty line
        between between function documentation and implementation.
        Delete variable "buffer".  Use ui_file_xstrdup in place of
        ui_file_put.  Minor adjustments following this change.
---
 gdb/ChangeLog      |  8 ++++++++
 gdb/ada-valprint.c | 24 ++++++++----------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e668617..9fc947b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2014-01-07  Joel Brobecker  <brobecker@adacore.com>
 
+	* ada-valprint.c (ui_memcpy): Delete.
+	(ada_print_floating): Update documentation.  Add empty line
+	between between function documentation and implementation.
+	Delete variable "buffer".  Use ui_file_xstrdup in place of
+	ui_file_put.  Minor adjustments following this change.
+
+2014-01-07  Joel Brobecker  <brobecker@adacore.com>
+
 	* ada-valprint.c (ada_val_print_string): New function,
 	extracted from ada_val_print_array.
 	(ada_val_print_array): Replace extracted code by call
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index d1c8553..1ae2089 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -289,32 +289,22 @@ char_at (const gdb_byte *string, int i, int type_len,
                                            type_len, byte_order);
 }
 
-/* Wrapper around memcpy to make it legal argument to ui_file_put.  */
-static void
-ui_memcpy (void *dest, const char *buffer, long len)
-{
-  memcpy (dest, buffer, (size_t) len);
-  ((char *) dest)[len] = '\0';
-}
-
 /* Print a floating-point value of type TYPE, pointed to in GDB by
    VALADDR, on STREAM.  Use Ada formatting conventions: there must be
    a decimal point, and at least one digit before and after the
-   point.  We use GNAT format for NaNs and infinities.  */
+   point.  We use the GNAT format for NaNs and infinities.  */
+
 static void
 ada_print_floating (const gdb_byte *valaddr, struct type *type,
 		    struct ui_file *stream)
 {
-  char buffer[64];
   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);
-  ui_file_put (tmp_stream, ui_memcpy, buffer);
-  do_cleanups (cleanups);
-
-  result = buffer;
+  result = ui_file_xstrdup (tmp_stream, NULL);
+  make_cleanup (xfree, result);
 
   /* Modify for Ada rules.  */
 
@@ -348,9 +338,11 @@ ada_print_floating (const gdb_byte *valaddr, struct type *type,
 	fprintf_filtered (stream, "%s.0", result);
       else
 	fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s);
-      return;
     }
-  fprintf_filtered (stream, "%s", result);
+  else
+    fprintf_filtered (stream, "%s", result);
+
+  do_cleanups (cleanups);
 }
 
 void
-- 
1.8.3.2

  parent reply	other threads:[~2014-01-07  4:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07  4:22 [commit/Ada] General ada-valprint improvements Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 06/11] ada-valprint.c: Inline print_record inside ada_val_print_struct_union Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 05/11] Split ada_val_print_1 into smaller functions Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 04/11] Remove call to gdb_flush at end of ada_val_print_1 Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 09/11] Extract string-printing out of ada_val_print_array Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 08/11] move ada_val_print_array down within other ada_val_print* functions Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 02/11] ada_val_print_1: Add language parameter Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 03/11] ada_val_print_1: Go through val_print instead of recursive call to self Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 01/11] ada-valprint.c: Reorder functions to reduce advance declarations Joel Brobecker
2014-01-07  4:22 ` [commit/Ada 07/11] rewrite ada_val_print_ref to reduce if/else block nesting depth Joel Brobecker
2014-01-07  4:23 ` [commit/Ada 11/11] Ada: Fix missing call to pretty-printer for fields of records Joel Brobecker
2014-01-07  4:23 ` Joel Brobecker [this message]
2014-01-07 17:29 ` [commit/Ada] General ada-valprint improvements Tom Tromey
2014-01-08 11:35   ` Joel Brobecker
2014-01-08 15:41     ` Tom Tromey
2014-01-09  3:06       ` Joel Brobecker
2014-01-09 16:14         ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389068515-10129-11-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).