Commit 00304082 authored by Christoph Reiter's avatar Christoph Reiter 🐍

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.
parent 16e63243
......@@ -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;
}
......
......@@ -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')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment