* [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441]
@ 2022-05-01 18:21 Patrick Palka
2022-05-01 18:21 ` [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911] Patrick Palka
2022-05-01 19:09 ` [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Jonathan Wakely
0 siblings, 2 replies; 5+ messages in thread
From: Patrick Palka @ 2022-05-01 18:21 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c
overlooked that the exponent part can also begin with an uppercase 'P'.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11, and possibly the
12 branch now for 12.1?
PR libstdc++/105441
libstdc++-v3/ChangeLog:
* src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
Also accept 'P' as the start of the exponent.
* testsuite/20_util/from_chars/7.cc: Add corresponding testcase.
---
libstdc++-v3/src/c++17/floating_from_chars.cc | 2 +-
libstdc++-v3/testsuite/20_util/from_chars/7.cc | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
index 13de1e346ab..e7f3a58cf18 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -664,7 +664,7 @@ namespace
// Parse the written exponent.
int written_exponent = 0;
- if (first != last && *first == 'p')
+ if (first != last && (*first == 'p' || *first == 'P'))
{
// Tentatively consume the 'p' and try to parse a decimal number.
const char* const fallback_first = first;
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/7.cc b/libstdc++-v3/testsuite/20_util/from_chars/7.cc
index 2a78c7441e2..1aa9b230531 100644
--- a/libstdc++-v3/testsuite/20_util/from_chars/7.cc
+++ b/libstdc++-v3/testsuite/20_util/from_chars/7.cc
@@ -96,6 +96,7 @@ constexpr testcase testcases[] = {
{ "1p-1", 4, {}, 0x1p-1 },
{ "0", 1, {}, 0.0 },
{ "A", 1, {}, 0xA },
+ { "1.ABCDEFP+10", 12, {}, 0x1.ABCDEFP+10 },
{ "-1", 2, {}, -1.0 },
{ "-0", 2, {}, -0.0 },
{ "42", 2, {}, 0x42p0 },
--
2.36.0.44.g0f828332d5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911]
2022-05-01 18:21 [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Patrick Palka
@ 2022-05-01 18:21 ` Patrick Palka
2022-05-01 19:07 ` Jonathan Wakely
2022-05-01 19:09 ` [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Jonathan Wakely
1 sibling, 1 reply; 5+ messages in thread
From: Patrick Palka @ 2022-05-01 18:21 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Patrick Palka
As in r12-6281-gc83ecfbe74a5cf for std::isdigit, <charconv> shouldn't
use std::tolower either I think.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11 and the
12 branch after it's thawed?
PR libstdc++/103911
libstdc++-v3/ChangeLog:
* src/c++17/floating_from_chars.cc (find_end_of_float): Accept
two possible delimeters for the exponent part in the form of a
(possibly NULL) string of length two. Don't use std::tolower.
(pattern): Adjust calls to find_end_of_float accordingly.
---
libstdc++-v3/src/c++17/floating_from_chars.cc | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
index e7f3a58cf18..5d2a931d5dd 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -40,7 +40,6 @@
#include <cmath>
#include <cstdlib>
#include <cstring>
-#include <cctype>
#include <locale.h>
#include <bits/functexcept.h>
#if _GLIBCXX_HAVE_XLOCALE_H
@@ -142,10 +141,10 @@ namespace
// Find initial portion of [first, last) containing a floating-point number.
// The string `digits` is either `dec_digits` or `hex_digits`
- // and `exp` is 'e' or 'p' or '\0'.
+ // and `exp` is "eE", "pP" or NULL.
const char*
find_end_of_float(const char* first, const char* last, const char* digits,
- char exp)
+ const char *exp)
{
while (first < last && strchr(digits, *first) != nullptr)
++first;
@@ -155,7 +154,7 @@ namespace
while (first < last && strchr(digits, *first))
++first;
}
- if (first < last && exp != 0 && std::tolower((unsigned char)*first) == exp)
+ if (first < last && exp != nullptr && (*first == exp[0] || *first == exp[1]))
{
++first;
if (first < last && (*first == '-' || *first == '+'))
@@ -237,7 +236,7 @@ namespace
if ((last - first + 2) > buffer_resource::guaranteed_capacity())
{
- last = find_end_of_float(first + neg, last, digits, 'p');
+ last = find_end_of_float(first + neg, last, digits, "pP");
#ifndef __cpp_exceptions
if ((last - first + 2) > buffer_resource::guaranteed_capacity())
{
@@ -261,7 +260,7 @@ namespace
if ((last - first) > buffer_resource::guaranteed_capacity())
{
last = find_end_of_float(first + neg, last, digits,
- "e"[fmt == chars_format::fixed]);
+ fmt == chars_format::fixed ? nullptr : "eE");
#ifndef __cpp_exceptions
if ((last - first) > buffer_resource::guaranteed_capacity())
{
--
2.36.0.44.g0f828332d5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911]
2022-05-01 18:21 ` [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911] Patrick Palka
@ 2022-05-01 19:07 ` Jonathan Wakely
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2022-05-01 19:07 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc Patches, libstdc++
On Sun, 1 May 2022 at 19:21, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> As in r12-6281-gc83ecfbe74a5cf for std::isdigit, <charconv> shouldn't
> use std::tolower either I think.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11 and the
> 12 branch after it's thawed?
OK, thanks.
>
> PR libstdc++/103911
>
> libstdc++-v3/ChangeLog:
>
> * src/c++17/floating_from_chars.cc (find_end_of_float): Accept
> two possible delimeters for the exponent part in the form of a
> (possibly NULL) string of length two. Don't use std::tolower.
> (pattern): Adjust calls to find_end_of_float accordingly.
> ---
> libstdc++-v3/src/c++17/floating_from_chars.cc | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
> index e7f3a58cf18..5d2a931d5dd 100644
> --- a/libstdc++-v3/src/c++17/floating_from_chars.cc
> +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
> @@ -40,7 +40,6 @@
> #include <cmath>
> #include <cstdlib>
> #include <cstring>
> -#include <cctype>
> #include <locale.h>
> #include <bits/functexcept.h>
> #if _GLIBCXX_HAVE_XLOCALE_H
> @@ -142,10 +141,10 @@ namespace
>
> // Find initial portion of [first, last) containing a floating-point number.
> // The string `digits` is either `dec_digits` or `hex_digits`
> - // and `exp` is 'e' or 'p' or '\0'.
> + // and `exp` is "eE", "pP" or NULL.
> const char*
> find_end_of_float(const char* first, const char* last, const char* digits,
> - char exp)
> + const char *exp)
> {
> while (first < last && strchr(digits, *first) != nullptr)
> ++first;
> @@ -155,7 +154,7 @@ namespace
> while (first < last && strchr(digits, *first))
> ++first;
> }
> - if (first < last && exp != 0 && std::tolower((unsigned char)*first) == exp)
> + if (first < last && exp != nullptr && (*first == exp[0] || *first == exp[1]))
> {
> ++first;
> if (first < last && (*first == '-' || *first == '+'))
> @@ -237,7 +236,7 @@ namespace
>
> if ((last - first + 2) > buffer_resource::guaranteed_capacity())
> {
> - last = find_end_of_float(first + neg, last, digits, 'p');
> + last = find_end_of_float(first + neg, last, digits, "pP");
> #ifndef __cpp_exceptions
> if ((last - first + 2) > buffer_resource::guaranteed_capacity())
> {
> @@ -261,7 +260,7 @@ namespace
> if ((last - first) > buffer_resource::guaranteed_capacity())
> {
> last = find_end_of_float(first + neg, last, digits,
> - "e"[fmt == chars_format::fixed]);
> + fmt == chars_format::fixed ? nullptr : "eE");
> #ifndef __cpp_exceptions
> if ((last - first) > buffer_resource::guaranteed_capacity())
> {
> --
> 2.36.0.44.g0f828332d5
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441]
2022-05-01 18:21 [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Patrick Palka
2022-05-01 18:21 ` [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911] Patrick Palka
@ 2022-05-01 19:09 ` Jonathan Wakely
2022-05-02 5:05 ` Jakub Jelinek
1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2022-05-01 19:09 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc Patches, libstdc++
On Sun, 1 May 2022 at 19:22, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c
> overlooked that the exponent part can also begin with an uppercase 'P'.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11, and possibly the
> 12 branch now for 12.1?
OK for trunk, and as it's a regression since gcc-11 I'd recommend
release manager approval for 12.1 as well, but it's the RMs call.
>
> PR libstdc++/105441
>
> libstdc++-v3/ChangeLog:
>
> * src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
> Also accept 'P' as the start of the exponent.
> * testsuite/20_util/from_chars/7.cc: Add corresponding testcase.
> ---
> libstdc++-v3/src/c++17/floating_from_chars.cc | 2 +-
> libstdc++-v3/testsuite/20_util/from_chars/7.cc | 1 +
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
> index 13de1e346ab..e7f3a58cf18 100644
> --- a/libstdc++-v3/src/c++17/floating_from_chars.cc
> +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
> @@ -664,7 +664,7 @@ namespace
>
> // Parse the written exponent.
> int written_exponent = 0;
> - if (first != last && *first == 'p')
> + if (first != last && (*first == 'p' || *first == 'P'))
> {
> // Tentatively consume the 'p' and try to parse a decimal number.
> const char* const fallback_first = first;
> diff --git a/libstdc++-v3/testsuite/20_util/from_chars/7.cc b/libstdc++-v3/testsuite/20_util/from_chars/7.cc
> index 2a78c7441e2..1aa9b230531 100644
> --- a/libstdc++-v3/testsuite/20_util/from_chars/7.cc
> +++ b/libstdc++-v3/testsuite/20_util/from_chars/7.cc
> @@ -96,6 +96,7 @@ constexpr testcase testcases[] = {
> { "1p-1", 4, {}, 0x1p-1 },
> { "0", 1, {}, 0.0 },
> { "A", 1, {}, 0xA },
> + { "1.ABCDEFP+10", 12, {}, 0x1.ABCDEFP+10 },
> { "-1", 2, {}, -1.0 },
> { "-0", 2, {}, -0.0 },
> { "42", 2, {}, 0x42p0 },
> --
> 2.36.0.44.g0f828332d5
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441]
2022-05-01 19:09 ` [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Jonathan Wakely
@ 2022-05-02 5:05 ` Jakub Jelinek
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2022-05-02 5:05 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: Patrick Palka, libstdc++, gcc Patches
On Sun, May 01, 2022 at 08:09:05PM +0100, Jonathan Wakely via Gcc-patches wrote:
> On Sun, 1 May 2022 at 19:22, Patrick Palka via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c
> > overlooked that the exponent part can also begin with an uppercase 'P'.
> >
> > Tested on x86_64-pc-linux-gnu, does this look OK for trunk/11, and possibly the
> > 12 branch now for 12.1?
>
> OK for trunk, and as it's a regression since gcc-11 I'd recommend
> release manager approval for 12.1 as well, but it's the RMs call.
Ok for 12.1.
> > PR libstdc++/105441
> >
> > libstdc++-v3/ChangeLog:
> >
> > * src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
> > Also accept 'P' as the start of the exponent.
> > * testsuite/20_util/from_chars/7.cc: Add corresponding testcase.
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-02 5:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-01 18:21 [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Patrick Palka
2022-05-01 18:21 ` [PATCH 2/2] libstdc++: Don't use std::tolower in <charconv> [PR103911] Patrick Palka
2022-05-01 19:07 ` Jonathan Wakely
2022-05-01 19:09 ` [PATCH 1/2] libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441] Jonathan Wakely
2022-05-02 5:05 ` Jakub Jelinek
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).