summaryrefslogtreecommitdiff
path: root/libstdc++-v3/config/locale
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-06 23:36:56 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-06 23:36:56 +0000
commitfc4923fee62551632b917151cd233983215ad12d (patch)
treec771b6beaa1c816e9c29838ff51c42346b3c0734 /libstdc++-v3/config/locale
parent7be30e31639eef4669e4b4cda457e22bdb291a99 (diff)
downloadgcc-fc4923fee62551632b917151cd233983215ad12d.tar.gz
2007-04-06 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/31117 * config/locale/gnu/c_locale.cc (__convert_to_v): Do not use errno, just check that the value is finite. * config/locale/generic/c_locale.cc (__convert_to_v): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123635 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config/locale')
-rw-r--r--libstdc++-v3/config/locale/generic/c_locale.cc26
-rw-r--r--libstdc++-v3/config/locale/gnu/c_locale.cc15
2 files changed, 20 insertions, 21 deletions
diff --git a/libstdc++-v3/config/locale/generic/c_locale.cc b/libstdc++-v3/config/locale/generic/c_locale.cc
index 783b1963c0a..f448fa8c983 100644
--- a/libstdc++-v3/config/locale/generic/c_locale.cc
+++ b/libstdc++-v3/config/locale/generic/c_locale.cc
@@ -1,6 +1,6 @@
// Wrapper for underlying C-language localization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -34,7 +34,6 @@
// Written by Benjamin Kosnik <bkoz@redhat.com>
-#include <cerrno> // For errno
#include <cmath> // For isinf, finite, finitef, fabs
#include <cstdlib> // For strof, strtold
#include <locale>
@@ -52,7 +51,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
@@ -63,19 +61,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
float __f = static_cast<float>(__d);
#ifdef _GLIBCXX_HAVE_FINITEF
if (!finitef (__f))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#elif defined (_GLIBCXX_HAVE_FINITE)
if (!finite (static_cast<double> (__f)))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#elif defined (_GLIBCXX_HAVE_ISINF)
if (isinf (static_cast<double> (__f)))
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#else
if (fabs(__d) > numeric_limits<float>::max())
- errno = ERANGE;
+ __f = __builtin_huge_valf();
#endif
#endif
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __f != __builtin_huge_valf()
+ && __f != -__builtin_huge_valf())
__v = __f;
else
__err |= ios_base::failbit;
@@ -89,12 +88,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
char* __sanity;
double __d = strtod(__s, &__sanity);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __d != __builtin_huge_val()
+ && __d != -__builtin_huge_val())
__v = __d;
else
__err |= ios_base::failbit;
@@ -108,20 +107,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
ios_base::iostate& __err, const __c_locale&)
{
// Assumes __s formatted for "C" locale.
- errno = 0;
char* __old = strdup(setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
#if defined(_GLIBCXX_HAVE_STRTOLD)
char* __sanity;
long double __ld = strtold(__s, &__sanity);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
#else
typedef char_traits<char>::int_type int_type;
long double __ld;
int __p = sscanf(__s, "%Lf", &__ld);
if (__p && static_cast<int_type>(__p) != char_traits<char>::eof()
- && errno != ERANGE)
+ && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
#endif
else
diff --git a/libstdc++-v3/config/locale/gnu/c_locale.cc b/libstdc++-v3/config/locale/gnu/c_locale.cc
index 37db702677a..a811cc750c2 100644
--- a/libstdc++-v3/config/locale/gnu/c_locale.cc
+++ b/libstdc++-v3/config/locale/gnu/c_locale.cc
@@ -1,6 +1,6 @@
// Wrapper for underlying C-language localization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -34,7 +34,6 @@
// Written by Benjamin Kosnik <bkoz@redhat.com>
-#include <cerrno> // For errno
#include <locale>
#include <stdexcept>
#include <langinfo.h>
@@ -48,9 +47,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
float __f = __strtof_l(__s, &__sanity, __cloc);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __f != __builtin_huge_valf()
+ && __f != -__builtin_huge_valf())
__v = __f;
else
__err |= ios_base::failbit;
@@ -62,9 +61,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
double __d = __strtod_l(__s, &__sanity, __cloc);
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __d != __builtin_huge_val()
+ && __d != -__builtin_huge_val())
__v = __d;
else
__err |= ios_base::failbit;
@@ -76,7 +75,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const __c_locale& __cloc)
{
char* __sanity;
- errno = 0;
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
// Prefer strtold_l, as __strtold_l isn't prototyped in more recent
// glibc versions.
@@ -84,7 +82,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
#else
long double __ld = __strtold_l(__s, &__sanity, __cloc);
#endif
- if (__sanity != __s && errno != ERANGE)
+ if (__sanity != __s && __ld != __builtin_huge_vall()
+ && __ld != -__builtin_huge_vall())
__v = __ld;
else
__err |= ios_base::failbit;