[glib/freebsd-gunichar-wchart-fixes] gunicollate: work around FreeBSD wchar_t not matching our gunichar type



commit b49e767e2e43fbaacc5323d3f2fc20cd01e416b1
Author: Christoph Reiter <creiter src gnome org>
Date:   Tue Jun 4 18:15:24 2019 +0200

    gunicollate: work around FreeBSD wchar_t not matching our gunichar type
    
    In !863 I assumed that a 4 byte wchar_t would be equal to gunichar on all platforms,
    but this is not the case for FreeBSD. It previously was using the non wchar_t based API
    because it doesn't define __STDC_ISO_10646__.
    
    Add back the __STDC_ISO_10646__ check again and introduce a more meaningful macro for guarding
    the code paths that are mixing gunichar and wchar_t.
    
    Fixes #1798

 glib/gunicollate.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/glib/gunicollate.c b/glib/gunicollate.c
index 947a003af..f6599f1fb 100644
--- a/glib/gunicollate.c
+++ b/glib/gunicollate.c
@@ -37,6 +37,9 @@
 #include "gcharset.h"
 #include "gconvert.h"
 
+#if SIZEOF_WCHAR_T == 4 && defined(__STDC_ISO_10646__)
+#define GUNICHAR_EQUALS_WCHAR_T 1
+#endif
 
 #ifdef _MSC_VER
 /* Workaround for bug in MSVCR80.DLL */
@@ -99,7 +102,7 @@ g_utf8_collate (const gchar *str1,
   g_free (str2_utf16);
   g_free (str1_utf16);
 
-#elif defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
+#elif defined(HAVE_WCHAR_H) && defined(GUNICHAR_EQUALS_WCHAR_T)
 
   gunichar *str1_norm;
   gunichar *str2_norm;
@@ -157,7 +160,7 @@ g_utf8_collate (const gchar *str1,
   return result;
 }
 
-#if defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
+#if defined(HAVE_WCHAR_H) && defined(GUNICHAR_EQUALS_WCHAR_T)
 /* We need UTF-8 encoding of numbers to encode the weights if
  * we are using wcsxfrm. However, we aren't encoding Unicode
  * characters, so we can't simply use g_unichar_to_utf8.
@@ -380,7 +383,7 @@ g_utf8_collate_key (const gchar *str,
   g_return_val_if_fail (str != NULL, NULL);
   result = carbon_collate_key (str, len);
 
-#elif defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
+#elif defined(HAVE_WCHAR_H) && defined(GUNICHAR_EQUALS_WCHAR_T)
 
   gsize xfrm_len;
   gunichar *str_norm;


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