From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fix gnu-versioned-namespace build
Date: Fri, 30 Oct 2020 13:37:58 +0000 [thread overview]
Message-ID: <20201030133758.GI503596@redhat.com> (raw)
In-Reply-To: <20201030132300.GH503596@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]
On 30/10/20 13:23 +0000, Jonathan Wakely wrote:
>On 30/10/20 13:59 +0100, François Dumont via Libstdc++ wrote:
>>The gnu-versioned-namespace build is broken.
>>
>>The fix in charconv/floating_from_chars.cc is quite trivial. I am
>>not so sure about the fix in sstream-inst.cc.
>
>The change for src/c++20/sstream-inst.cc is OK to commit. It would
>probably be better to not build that file at all if the cxx11 ABI is
>not supported at all, but then the src/c++20 directory would be empty
>and I'm not sure if that would work. So just making the file empty is
>fine.
>
>The change for from_chars is not OK. With your change the <charconv>
>header doesn't declare those functions if included by a file using the
>old ABI. That's wrong, they should be declared unconditionally.
>
>I see two ways to fix it. Either make the declarations in the header
>depend on ! _GLIBCXX_INLINE_VERSION (so they're disabled for
>gnu-versioned namespace) or fix the code in floating_from_chars to not
>use a pmr::memory_resource for allocation in the versioned namespace
>build.
Here's a patch for the second way.
A third way to fix it would be to make basic_string work with C++
allocators, so that pmr::string is usable for the gnu-versioned
namespace.
And the fourth would be to switch the versioned namespace to use the
new ABI unconditionally, instead of using the old ABI unconditionally.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3092 bytes --]
diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc
index d52c0a937b9f..c279809cf35d 100644
--- a/libstdc++-v3/src/c++17/floating_from_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_from_chars.cc
@@ -27,6 +27,9 @@
// 23.2.9 Primitive numeric input conversion [utility.from.chars]
//
+// Prefer to use std::pmr::string if possible, which requires the cxx11 ABI.
+#define _GLIBCXX_USE_CXX11_ABI 1
+
#include <charconv>
#include <string>
#include <memory_resource>
@@ -87,6 +90,12 @@ namespace
void* m_ptr = nullptr;
};
+#if _GLIBCXX_USE_CXX11_ABI
+ using buffered_string = std::pmr::string;
+#else
+ using buffered_string = std::string;
+#endif
+
inline bool valid_fmt(chars_format fmt)
{
return fmt != chars_format{}
@@ -130,7 +139,7 @@ namespace
// Returns a nullptr if a valid pattern is not present.
const char*
pattern(const char* const first, const char* last,
- chars_format& fmt, pmr::string& buf)
+ chars_format& fmt, buffered_string& buf)
{
// fmt has the value of one of the enumerators of chars_format.
__glibcxx_assert(valid_fmt(fmt));
@@ -359,6 +368,22 @@ namespace
return result;
}
+#if ! _GLIBCXX_USE_CXX11_ABI
+ inline bool
+ reserve_string(std::string& s) noexcept
+ {
+ __try
+ {
+ s.reserve(buffer_resource::guaranteed_capacity());
+ }
+ __catch (const std::bad_alloc&)
+ {
+ return false;
+ }
+ return true;
+ }
+#endif
+
} // namespace
// FIXME: This should be reimplemented so it doesn't use strtod and newlocale.
@@ -369,10 +394,16 @@ from_chars_result
from_chars(const char* first, const char* last, float& value,
chars_format fmt) noexcept
{
+ errc ec = errc::invalid_argument;
+#if _GLIBCXX_USE_CXX11_ABI
buffer_resource mr;
pmr::string buf(&mr);
+#else
+ string buf;
+ if (!reserve_string(buf))
+ return make_result(first, 0, {}, ec);
+#endif
size_t len = 0;
- errc ec = errc::invalid_argument;
__try
{
if (const char* pat = pattern(first, last, fmt, buf)) [[likely]]
@@ -389,10 +420,16 @@ from_chars_result
from_chars(const char* first, const char* last, double& value,
chars_format fmt) noexcept
{
+ errc ec = errc::invalid_argument;
+#if _GLIBCXX_USE_CXX11_ABI
buffer_resource mr;
pmr::string buf(&mr);
+#else
+ string buf;
+ if (!reserve_string(buf))
+ return make_result(first, 0, {}, ec);
+#endif
size_t len = 0;
- errc ec = errc::invalid_argument;
__try
{
if (const char* pat = pattern(first, last, fmt, buf)) [[likely]]
@@ -409,10 +446,16 @@ from_chars_result
from_chars(const char* first, const char* last, long double& value,
chars_format fmt) noexcept
{
+ errc ec = errc::invalid_argument;
+#if _GLIBCXX_USE_CXX11_ABI
buffer_resource mr;
pmr::string buf(&mr);
+#else
+ string buf;
+ if (!reserve_string(buf))
+ return make_result(first, 0, {}, ec);
+#endif
size_t len = 0;
- errc ec = errc::invalid_argument;
__try
{
if (const char* pat = pattern(first, last, fmt, buf)) [[likely]]
next prev parent reply other threads:[~2020-10-30 13:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-30 12:59 François Dumont
2020-10-30 13:23 ` Jonathan Wakely
2020-10-30 13:37 ` Jonathan Wakely [this message]
2020-10-30 14:11 ` Jonathan Wakely
2020-10-30 17:51 ` François Dumont
2020-10-30 18:48 ` Jonathan Wakely
2020-10-31 17:16 ` François Dumont
-- strict thread matches above, loose matches on Subject: below --
2019-12-11 7:29 François Dumont
2019-12-11 11:16 ` Jonathan Wakely
2019-12-11 11:22 ` Jonathan Wakely
2019-12-11 20:23 ` François Dumont
2019-12-11 20:44 ` Jonathan Wakely
2019-12-11 21:28 ` François Dumont
2019-12-11 21:33 ` Jonathan Wakely
2019-12-11 16:48 ` Jonathan Wakely
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=20201030133758.GI503596@redhat.com \
--to=jwakely@redhat.com \
--cc=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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: link
Be 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).