public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] [libstdc++] use strtold for from_chars even without locale Date: Thu, 4 May 2023 08:01:32 +0000 (GMT) [thread overview] Message-ID: <20230504080132.640C53857005@sourceware.org> (raw) https://gcc.gnu.org/g:6f51ef5c3329c5c00ee80cb1c1bcb4bab323ba49 commit 6f51ef5c3329c5c00ee80cb1c1bcb4bab323ba49 Author: Alexandre Oliva <oliva@adacore.com> Date: Thu May 4 02:29:46 2023 -0300 [libstdc++] use strtold for from_chars even without locale When we're using fast_float for 32- and 64-bit floating point, use strtold for wider long double, even if locales are unavailable. On vxworks, test for strtof's and strtold's declarations, so that it they be used when cross compiling. for libstdc++-v3/ChangeLog * src/c++17/floating_from_chars.cc (USE_STRTOD_FOR_FROM_CHARS): Define when using fast_float if long double is not as wide as double and strtold is not broken. * crossconfig.m4: Test for strtof and strtold declarations on vxworks. (GLIBCXX_CHECK_MATH_DECL): Include stdlib.h too. * configure: Rebuilt. Diff: --- libstdc++-v3/configure | 131 ++++++++++++++++++++++++++ libstdc++-v3/crossconfig.m4 | 3 +- libstdc++-v3/src/c++17/floating_from_chars.cc | 10 ++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 99f4927aa8c..dcf09df7f55 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -66832,6 +66832,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -66883,6 +66884,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -66934,6 +66936,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -66985,6 +66988,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67036,6 +67040,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67087,6 +67092,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67138,6 +67144,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67189,6 +67196,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67240,6 +67248,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67291,6 +67300,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67342,6 +67352,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67393,6 +67404,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67444,6 +67456,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67495,6 +67508,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67546,6 +67560,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67597,6 +67612,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67648,6 +67664,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67699,6 +67716,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67750,6 +67768,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67801,6 +67820,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67852,6 +67872,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67903,6 +67924,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -67954,6 +67976,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -68005,6 +68028,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -68056,6 +68080,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -68107,6 +68132,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -68158,6 +68184,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> @@ -68193,6 +68220,110 @@ _ACEOF + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for strtof declaration" >&5 +$as_echo_n "checking for strtof declaration... " >&6; } +if ${glibcxx_cv_func_strtof_use+:} false; then : + $as_echo_n "(cached) " >&6 +else + + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <stdlib.h> +#include <math.h> +#ifdef HAVE_IEEEFP_H +# include <ieeefp.h> +#endif +#undef strtof + +int +main () +{ + + void (*f)(void) = (void (*)(void))strtof; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + glibcxx_cv_func_strtof_use=yes + +else + glibcxx_cv_func_strtof_use=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_func_strtof_use" >&5 +$as_echo "$glibcxx_cv_func_strtof_use" >&6; } + if test "x$glibcxx_cv_func_strtof_use" = xyes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_STRTOF 1 +_ACEOF + + fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for strtold declaration" >&5 +$as_echo_n "checking for strtold declaration... " >&6; } +if ${glibcxx_cv_func_strtold_use+:} false; then : + $as_echo_n "(cached) " >&6 +else + + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <stdlib.h> +#include <math.h> +#ifdef HAVE_IEEEFP_H +# include <ieeefp.h> +#endif +#undef strtold + +int +main () +{ + + void (*f)(void) = (void (*)(void))strtold; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + glibcxx_cv_func_strtold_use=yes + +else + glibcxx_cv_func_strtold_use=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_func_strtold_use" >&5 +$as_echo "$glibcxx_cv_func_strtold_use" >&6; } + if test "x$glibcxx_cv_func_strtold_use" = xyes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_STRTOLD 1 +_ACEOF + + fi + + + ;; *) as_fn_error $? "No support for this host/target combination." "$LINENO" 5 diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 index b3269cb88e0..9db32f4d422 100644 --- a/libstdc++-v3/crossconfig.m4 +++ b/libstdc++-v3/crossconfig.m4 @@ -293,7 +293,7 @@ dnl # switch to more elaborate tests. GLIBCXX_CHECK_MATH_DECLS([ acosl asinl atan2l atanl ceill cosl coshl expl fabsl floorl fmodl frexpl ldexpl log10l logl modfl powl sinl sinhl sqrtl tanl tanhl hypotl - ldexpf modff hypotf frexpf]) + ldexpf modff hypotf frexpf strtof strtold]) dnl # sincosl is the only one missing here, compared with the *l dnl # functions in the list guarded by dnl # long_double_math_on_this_cpu in configure.ac, right after @@ -323,6 +323,7 @@ AC_DEFUN([GLIBCXX_CHECK_MATH_DECL], [ AC_LANG_SAVE AC_LANG_C AC_TRY_COMPILE([ +#include <stdlib.h> #include <math.h> #ifdef HAVE_IEEEFP_H # include <ieeefp.h> diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index 78b9d92cdc0..15af811d198 100644 --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -80,6 +80,10 @@ extern "C" _Float128 __strtof128(const char*, char**) # if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ // No need to use strtold. # undef USE_STRTOD_FOR_FROM_CHARS +# elif !defined USE_STRTOD_FOR_FROM_CHARS \ + && defined _GLIBCXX_HAVE_STRTOLD && !defined _GLIBCXX_HAVE_BROKEN_STRTOLD +// A working strtold will be more compliant than fast_float's double. +# define USE_STRTOD_FOR_FROM_CHARS 1 # endif #endif @@ -607,9 +611,11 @@ namespace ptrdiff_t from_chars_impl(const char* str, T& value, errc& ec) noexcept { +#if _GLIBCXX_HAVE_USELOCALE if (locale_t loc = ::newlocale(LC_ALL_MASK, "C", (locale_t)0)) [[likely]] { locale_t orig = ::uselocale(loc); +#endif #if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) const int rounding = std::fegetround(); @@ -652,8 +658,10 @@ namespace std::fesetround(rounding); #endif +#if _GLIBCXX_HAVE_USELOCALE ::uselocale(orig); ::freelocale(loc); +#endif const ptrdiff_t n = endptr - str; if (conv_errno == ERANGE) [[unlikely]] @@ -674,9 +682,11 @@ namespace ec = errc(); } return n; +#if _GLIBCXX_HAVE_USELOCALE } else if (errno == ENOMEM) ec = errc::not_enough_memory; +#endif return 0; }
reply other threads:[~2023-05-04 8:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230504080132.640C53857005@sourceware.org \ --to=aoliva@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.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: linkBe 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).