From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by sourceware.org (Postfix) with ESMTPS id EB54B3858CDB for ; Thu, 4 May 2023 12:05:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB54B3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-192d5ab4962so44379fac.3 for ; Thu, 04 May 2023 05:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1683201919; x=1685793919; h=mime-version:user-agent:message-id:date:errors-to:organization :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=u2qNLRUHslsiCgkwFXyS/fc+NebWxThk+v9JC6vkdEY=; b=dooDZbFkT9gK28uOOjOEWSnXS0oTFOeHHlmHivJiLF9emIDmTKxR15142s1Vb/ycPz EIL8K7bY+WOKw1u/vY/IoHHPKrGehgPGuJ4L6++KRUEu5HUM09334blIJA+SkjE+DAgO KMEkK88yDi/ARw9ONxvITMB8wXt/WqtePdUEjT7VjGJMUJ5XUVG4Sudof+PsaVV3EEO+ tTF0ESbr0PYjwtaYA6nD50bs1Ee1GDrPy3HhvnqlmOsl5ozqcUc7AXBphOn8nYjKMJDW XS3TOcA58AD4xh5fhST3wf26OSKNS3J3VcI855pIrTJ7UXjhAXrMl+8856HQnnmnFX20 bAQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683201919; x=1685793919; h=mime-version:user-agent:message-id:date:errors-to:organization :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u2qNLRUHslsiCgkwFXyS/fc+NebWxThk+v9JC6vkdEY=; b=Vzjnieh3I1EzriMLuSYdHd3u3OUyciL9dTsjXrmlGCbTsS8zKtrZFRKoz0GSYG0Z6v faW89PS4tgg/NjslcLOiondNfS6PjY5Zl8alXcEsKLcZum9KuvVSmhv63uzem0e47BmZ AH7/+kYbXymAw9ld3g4JxOfOIjrcGiJGR+jGcqGdJtWb4F63su+XLVMHo0D4FIJIEPCx dbGSBqNe+AZGGkU4yJwlZvQOUvDR/uVbCBJvZNc1qKSD+iQ/jScdmi+zeooQztznXe22 A2c+fJT8O5pWqyxIgQqWBcMLlownuqk4Ar55rMBgKCOjJvXWm4jlWKbG7OC6D4np3YKu mAvg== X-Gm-Message-State: AC+VfDzgptbRll4RsInWVBuaqJyyZpKmSRQy1iaI5L6CfIDKijoYPhyY n5+sG+v2r2aSvvn2ThsoR8+tag== X-Google-Smtp-Source: ACHHUZ4iU0ev3cTo8iRqV9rT/Qpmyycyd2nQIJes5KiVxV8yoB53HFAMV/9kKVNCxVvWSRZC1wWGJg== X-Received: by 2002:a05:6870:4c3:b0:18b:1926:43eb with SMTP id u3-20020a05687004c300b0018b192643ebmr693352oam.48.1683201918936; Thu, 04 May 2023 05:05:18 -0700 (PDT) Received: from free.home ([2804:7f1:2080:c4e6:caf1:179:3909:b1dd]) by smtp.gmail.com with ESMTPSA id d13-20020a056871040d00b0019296ee9606sm572686oag.4.2023.05.04.05.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 05:05:18 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 344C55wF2687770 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 May 2023 09:05:06 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [libstdc++] use strtold for from_chars even without locale Organization: Free thinker, does not speak for AdaCore Errors-To: aoliva@lxoliva.fsfla.org Date: Thu, 04 May 2023 09:05:05 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 they can be used even when cross compiling. Include stdlib.h in the decl-checking macro, so that it can find them. Regstrapped on x86_64-linux-gnu. Also tested on aarch64-vx7r2 with gcc-12, where uselocale is not available, and using strtold rather than fast_math's double fallback avoids a couple of from_chars-related testsuite fails (from_chars/4.cc and to_chars/long_double.cc). Ok to install? 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. --- 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 [omitted] diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 index b3269cb88e077..9db32f4d422da 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 #include #ifdef HAVE_IEEEFP_H # include diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index 78b9d92cdc0fa..15af811d198c4 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; } -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Disinformation flourishes because many people care deeply about injustice but very few check the facts. Ask me about