[committed, v4] libstdc++: Handle encodings in localized chrono formatting [PR109162]
Jonathan Wakely
jwakely@redhat.com
Wed Jul 31 20:26:43 GMT 2024
On Wed, 31 Jul 2024 at 19:18, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On Wed, 31 Jul 2024 at 19:17, Dimitar Dimitrov <dimitar@dinux.eu> wrote:
> >
> > On Wed, Jul 31, 2024 at 05:09:52PM +0100, Jonathan Wakely wrote:
> > > It took a while, but I was finally happy with this v4 patch, so I pushed
> > > it to trunk. Then I noticed silly mistake in the new test, which I'll
> > > fix shortly.
> > >
> > ...
> > > +#if defined _GLIBCXX_HAVE_ICONV
> > > + ::iconv_t _M_cd = (::iconv_t)-1;
> > > + mutable mutex mx;
> > > +#endif
> >
> > Hi Jonathan,
> >
> > This patch caused pru-unknown-elf build to break:
> > /mnt/nvme/dinux/local-workspace/gcc/libstdc++-v3/src/c++20/format.cc:86:11: error: ‘mutex’ does not name a type
> > 86 | mutable mutex mx;
> > | ^~~~~
> >
> > Should the section also be guarded by _GLIBCXX_HAS_GTHREADS ?
>
> Doh, yes it should. I'll fix that today.
I've pushed this, which should fix it.
-------------- next part --------------
commit e7d88ff8aaa244f3f722fc1dc50e8dc31d5c8fde
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jul 31 20:27:33 2024
libstdc++: Fix src/c++20/format.cc for non-gthreads targets
libstdc++-v3/ChangeLog:
* src/c++20/format.cc [!_GLIBCXX_HAS_GTHREADS] (mutex): Define
dummy mutex type.
* testsuite/std/time/format_localized.cc: Use loop variable
instead of creating the same locale on every iteration.
diff --git a/libstdc++-v3/src/c++20/format.cc b/libstdc++-v3/src/c++20/format.cc
index bcf1dd156a7..1a24fcab7f7 100644
--- a/libstdc++-v3/src/c++20/format.cc
+++ b/libstdc++-v3/src/c++20/format.cc
@@ -49,6 +49,15 @@ namespace __format
#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
namespace
{
+#ifndef _GLIBCXX_HAS_GTHREADS
+// Dummy mutex
+struct mutex
+{
+ void lock() const { }
+ void unlock() const { }
+};
+#endif
+
// A non-standard locale::facet that caches the locale's std::text_encoding
// and an iconv descriptor for converting from that encoding to UTF-8.
struct __encoding : locale::facet
@@ -59,7 +68,7 @@ struct __encoding : locale::facet
__encoding(const text_encoding& enc, size_t refs = 0)
: facet(refs), _M_enc(enc)
{
-#if defined _GLIBCXX_HAVE_ICONV
+#ifdef _GLIBCXX_HAVE_ICONV
using enum text_encoding::id;
switch (_M_enc.mib())
{
@@ -74,14 +83,14 @@ struct __encoding : locale::facet
~__encoding()
{
-#if defined _GLIBCXX_HAVE_ICONV
+#ifdef _GLIBCXX_HAVE_ICONV
if (_M_cd != (::iconv_t)-1)
::iconv_close(_M_cd);
#endif
}
text_encoding _M_enc;
-#if defined _GLIBCXX_HAVE_ICONV
+#ifdef _GLIBCXX_HAVE_ICONV
::iconv_t _M_cd = (::iconv_t)-1;
mutable mutex mx;
#endif
@@ -93,7 +102,7 @@ struct __encoding : locale::facet
if (input.empty()) [[unlikely]]
return codecvt_base::noconv;
-#if defined _GLIBCXX_HAVE_ICONV
+#ifdef _GLIBCXX_HAVE_ICONV
if (_M_cd == (::iconv_t)-1)
return codecvt_base::error;
diff --git a/libstdc++-v3/testsuite/std/time/format_localized.cc b/libstdc++-v3/testsuite/std/time/format_localized.cc
index 64a1582b945..393d0d200e4 100644
--- a/libstdc++-v3/testsuite/std/time/format_localized.cc
+++ b/libstdc++-v3/testsuite/std/time/format_localized.cc
@@ -75,7 +75,7 @@ test_en()
for (auto l : {ISO_8859(1,en_US), ISO_8859(15,en_US), "en_US.UTF-8", "C"})
{
- std::locale loc(ISO_8859(1,en_US));
+ std::locale loc(l);
auto s = std::format(loc, "{:L%b %B %a %A}", sys_days(2024y/July/30));
VERIFY( s == "Jul July Tue Tuesday" );
}
More information about the Libstdc++
mailing list