[glib: 1/2] gunicollate/cygwin: Don't use __STDC_ISO_10646__ for wchar_t related checks



commit 0030408299527fe79d0e6d08df6ce0b4da98604b
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed May 22 19:26:41 2019 +0200

    gunicollate/cygwin: Don't use __STDC_ISO_10646__ for wchar_t related checks
    
    The code in gunicollate uses __STDC_ISO_10646__ to check that wchar.h is avilable,
    that it includes the wide character related functions and that sizeof(wchar_t) == 4.
    
    cygwin defines __STDC_ISO_10646__ and has sizeof(wchar_t) == 2 and the C standard text isn't
    that clear on whether wchar_t should always be 4 bytes in this case, so we better not use if for
    assuming the size here.
    
    Instead of relying on __STDC_ISO_10646__ add HAVE_WCHAR_H and SIZEOF_WCHAR_T macros.
    With HAVE_WCHAR_H defined we assume wchar_t exists and wchar.h exists. With SIZEOF_WCHAR_T we
    guard the parts where the size of wchar_t is assumed to be 4 (currently all of them).
    
    Note that this doesn't make the collate tests pass under cygwin, they fail before and after this patch 
for me.
    
    See !755 for related discussions.

 glib/gunicollate.c | 20 +++++++++-----------
 meson.build        |  4 +++-
 2 files changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/glib/gunicollate.c b/glib/gunicollate.c
index 161a2de82..947a003af 100644
--- a/glib/gunicollate.c
+++ b/glib/gunicollate.c
@@ -20,7 +20,7 @@
 
 #include <locale.h>
 #include <string.h>
-#ifdef __STDC_ISO_10646__
+#ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif
 
@@ -35,9 +35,7 @@
 #include "gstrfuncs.h"
 #include "gtestutils.h"
 #include "gcharset.h"
-#ifndef __STDC_ISO_10646__
 #include "gconvert.h"
-#endif
 
 
 #ifdef _MSC_VER
@@ -101,7 +99,7 @@ g_utf8_collate (const gchar *str1,
   g_free (str2_utf16);
   g_free (str1_utf16);
 
-#elif defined(__STDC_ISO_10646__)
+#elif defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
 
   gunichar *str1_norm;
   gunichar *str2_norm;
@@ -117,7 +115,7 @@ g_utf8_collate (const gchar *str1,
   g_free (str1_norm);
   g_free (str2_norm);
 
-#else /* !__STDC_ISO_10646__ */
+#else
 
   const gchar *charset;
   gchar *str1_norm;
@@ -154,12 +152,12 @@ g_utf8_collate (const gchar *str1,
   g_free (str1_norm);
   g_free (str2_norm);
 
-#endif /* __STDC_ISO_10646__ */
+#endif
 
   return result;
 }
 
-#if defined(__STDC_ISO_10646__)
+#if defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
 /* 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.
@@ -206,7 +204,7 @@ utf8_encode (char *buf, wchar_t val)
 
   return retval;
 }
-#endif /* __STDC_ISO_10646__ */
+#endif
 
 #ifdef HAVE_CARBON
 
@@ -382,7 +380,7 @@ g_utf8_collate_key (const gchar *str,
   g_return_val_if_fail (str != NULL, NULL);
   result = carbon_collate_key (str, len);
 
-#elif defined(__STDC_ISO_10646__)
+#elif defined(HAVE_WCHAR_H) && SIZEOF_WCHAR_T == 4
 
   gsize xfrm_len;
   gunichar *str_norm;
@@ -412,7 +410,7 @@ g_utf8_collate_key (const gchar *str,
   g_free (str_norm);
 
   return result;
-#else /* !__STDC_ISO_10646__ */
+#else
 
   gsize xfrm_len;
   const gchar *charset;
@@ -466,7 +464,7 @@ g_utf8_collate_key (const gchar *str,
     }
 
   g_free (str_norm);
-#endif /* __STDC_ISO_10646__ */
+#endif
 
   return result;
 }
diff --git a/meson.build b/meson.build
index 6db3e8fe6..da6822521 100644
--- a/meson.build
+++ b/meson.build
@@ -268,6 +268,7 @@ headers = [
   'termios.h',
   'unistd.h',
   'values.h',
+  'wchar.h',
   'xlocale.h',
 ]
 
@@ -1181,6 +1182,7 @@ glib_conf.set('SIZEOF_LONG_LONG', long_long_size)
 glib_conf.set('SIZEOF_SIZE_T', sizet_size)
 glib_conf.set('SIZEOF_SSIZE_T', ssizet_size)
 glib_conf.set('SIZEOF_VOID_P', voidp_size)
+glib_conf.set('SIZEOF_WCHAR_T', cc.sizeof('wchar_t', prefix: '#include <stddef.h>'))
 
 if short_size == 2
   gint16 = 'short'
@@ -2107,4 +2109,4 @@ if get_option('man')
 endif
 
 gnome = import('gnome')
-subdir('docs/reference')
\ No newline at end of file
+subdir('docs/reference')


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