This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add D demangling support to libiberty
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Iain Buclaw <ibuclaw at gdcproject dot org>
- Cc: Ian Lance Taylor <iant at google dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Oct 2014 10:07:51 -0700
- Subject: Re: [PATCH] Add D demangling support to libiberty
- Authentication-results: sourceware.org; auth=none
- References: <CABOHX+dCTiefjwOTFfTC4Oa90dp7MaYm0M2T0GcByhB6Q7eO9A at mail dot gmail dot com> <CAKOQZ8xDYdUyi2O2a8HEEJki23DkP6ZT5V_s1dPo=qxeGwZVDA at mail dot gmail dot com> <CABOHX+dM9kwjzXoGGowXeKrUsM249ZYEc=TG5+XS1=TdZi32xQ at mail dot gmail dot com> <CABOHX+fo=Ac1tdoOup6VXqrDKK-jhWMisXZmmMqzh=qmCH+1Jg at mail dot gmail dot com> <20141014141244 dot GA17173 at adacore dot com> <CAKOQZ8y6DCBJpjt9WNGfH8_4RjfE7MFZ=kgRO-0OCYRJj+MOCw at mail dot gmail dot com> <CABOHX+fkVx2GEsv7M60SvQszvtx2tJpekwOG0g0Yn7nE_5nw9w at mail dot gmail dot com>
> I've just seen this, so I'll repeat what I've said in gdb patches too.
>
> The call to strtold is only needed to decode templates which have a
> floating point value encoded inside. This value may or may not have a
> greater than double precision.
>
> Replacing long double with double will be fine with me. I'll accept
> that I didn't consider legacy in hindsight, and in reality it would be
> rather rare to stumble upon the need for strtold.
Attached is a patch that switches it to strtod. Do you have any
test that could quickly verify it? That seems to be the best
approach, at least short-term. Later on, if we do want to use
higher precision, we can indeed add strtold in libiberty.
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.
I verified that the patch allows GDB to build on both sparc-solaris
and x86_64-linux.
Thanks,
--
Joel
>From 99f9794c6d2f4dabed0bbcf2cf362b1eb25ee2a7 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Tue, 14 Oct 2014 12:47:43 -0400
Subject: [PATCH] Use strtod instead of strtold in libiberty/d-demangle.c
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.
---
libiberty/d-demangle.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
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.7.9.5