Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Iain Buclaw <ibuclaw@gdcproject.org>,	binutils@sourceware.org
Subject: [pushed] Use strtod instead of strtold in libiberty/d-demangle.c
Date: Thu, 16 Oct 2014 21:55:00 -0000	[thread overview]
Message-ID: <1413496497-16369-1-git-send-email-brobecker@adacore.com> (raw)

Hello,

This is a patch was approved in GCC and pushed immediately, but then
I completely forgot to push it to binutils_gdb.git. Now done.

strtold is currently used to decode templates which have a floating-point
value encoded inside; but this routine is not available on some systems,
such as Solaris 2.9 for instance.

This patch fixes the issue by replace the use of strtold by strtod.
It reduces a bit the precision, but it should still remain acceptable
in most cases.

libiberty/ChangeLog:

        * d-demangle.c: Replace strtold with strtod in global comment.
        (strtold): Remove declaration.
        (strtod): New declaration.
        (dlang_parse_real): Declare value as double instead of long
        double.  Replace call to strtold by call to strtod.
        Update format in call to snprintf.

Tested on x86_64-linux.

---
 libiberty/ChangeLog    |  9 +++++++++
 libiberty/d-demangle.c | 10 +++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 829f684..9e91cce 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,12 @@
+2014-10-16  Joel Brobecker  <brobecker@adacore.com>
+
+	* d-demangle.c: Replace strtold with strtod in global comment.
+	(strtold): Remove declaration.
+	(strtod): New declaration.
+	(dlang_parse_real): Declare value as double instead of long
+	double.  Replace call to strtold by call to strtod.
+	Update format in call to snprintf.
+
 2014-09-26  Jason Merrill  <jason@redhat.com>
 
 	* cp-demangle.c (d_substitution): Handle abi tags on abbreviation.
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index d31bf94..bb481c0 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -28,7 +28,7 @@ If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This file exports one function; dlang_demangle.
 
-   This file imports strtol and strtold for decoding mangled literals.  */
+   This file imports strtol and strtod for decoding mangled literals.  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -44,7 +44,7 @@ If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdlib.h>
 #else
 extern long strtol (const char *nptr, char **endptr, int base);
-extern long double strtold (const char *nptr, char **endptr);
+extern double strtod (const char *nptr, char **endptr);
 #endif
 
 #include <demangle.h>
@@ -810,7 +810,7 @@ dlang_parse_real (string *decl, const char *mangled)
 {
   char buffer[64];
   int len = 0;
-  long double value;
+  double value;
   char *endptr;
 
   /* Handle NAN and +-INF.  */
@@ -877,12 +877,12 @@ dlang_parse_real (string *decl, const char *mangled)
 
   /* Convert buffer from hexadecimal to floating-point.  */
   buffer[len] = '\0';
-  value = strtold (buffer, &endptr);
+  value = strtod (buffer, &endptr);
 
   if (endptr == NULL || endptr != (buffer + len))
     return NULL;
 
-  len = snprintf (buffer, sizeof(buffer), "%#Lg", value);
+  len = snprintf (buffer, sizeof(buffer), "%#g", value);
   string_appendn (decl, buffer, len);
   return mangled;
 }
-- 
1.9.1


             reply	other threads:[~2014-10-16 21:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-16 21:55 Joel Brobecker [this message]
2014-12-24 10:06 ` Iain Buclaw
2014-12-24 10:44   ` Alan Modra

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=1413496497-16369-1-git-send-email-brobecker@adacore.com \
    --to=brobecker@adacore.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=ibuclaw@gdcproject.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