[glibmm] ustring: Fix wchar conversion on macOS with libc++



commit e798fa7b20847c875435a8a8884987e29e7ddf9b
Author: Clemens Lang <cal macports org>
Date:   Thu Apr 26 15:25:44 2018 +0200

    ustring: Fix wchar conversion on macOS with libc++
    
    libc++ internally represents std::wstrings in UCS-4 just like libstdc++,
    but does not set the __STDC_ISO_10646__ define. This caused the code to
    fall back to calling iconv with the WCHAR_T source character set, which
    does not correctly convert these strings and leads to errors, for
    example in inkscape on startup.
    
    See https://trac.macports.org/ticket/56214 for an instance of such
    a problem.
    
    Re-use the UCS4 to UTF8 conversion code when libc++ is detected, which
    solves this. Bug 795338

 glib/glibmm/ustring.cc |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/glib/glibmm/ustring.cc b/glib/glibmm/ustring.cc
index 976289f..901deac 100644
--- a/glib/glibmm/ustring.cc
+++ b/glib/glibmm/ustring.cc
@@ -1371,7 +1371,7 @@ ustring::FormatStream::to_string() const
 #ifdef GLIBMM_HAVE_WIDE_STREAM
   const std::wstring str = stream_.str();
 
-#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
+#if (defined(__STDC_ISO_10646__) || defined(_LIBCPP_VERSION)) && SIZEOF_WCHAR_T == 4
   // Avoid going through iconv if wchar_t always contains UCS-4.
   glong n_bytes = 0;
   const auto buf = make_unique_ptr_gfree(g_ucs4_to_utf8(
@@ -1459,7 +1459,7 @@ operator>>(std::wistream& is, ustring& utf8_string)
   std::wstring wstr;
   is >> wstr;
 
-#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
+#if (defined(__STDC_ISO_10646__) || defined(_LIBCPP_VERSION)) && SIZEOF_WCHAR_T == 4
   // Avoid going through iconv if wchar_t always contains UCS-4.
   glong n_bytes = 0;
   const auto buf = make_unique_ptr_gfree(g_ucs4_to_utf8(
@@ -1490,7 +1490,7 @@ operator<<(std::wostream& os, const ustring& utf8_string)
 {
   GError* error = nullptr;
 
-#if defined(__STDC_ISO_10646__) && SIZEOF_WCHAR_T == 4
+#if (defined(__STDC_ISO_10646__) || defined(_LIBCPP_VERSION)) && SIZEOF_WCHAR_T == 4
   // Avoid going through iconv if wchar_t always contains UCS-4.
   const auto buf = make_unique_ptr_gfree(
     g_utf8_to_ucs4(utf8_string.raw().data(), utf8_string.raw().size(), nullptr, nullptr, &error));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]