Use char16_t when available, and when it is, don't test for -fshort-wchar. (
Bug 502298) r=bsmedberg
--- a/configure.in
+++ b/configure.in
@@ -2880,42 +2880,57 @@ AC_CACHE_VAL(ac_cv_have_uname_us_domainn
if test "$ac_cv_have_uname_us_domainname_field" = "true"; then
AC_DEFINE(HAVE_UNAME_US_DOMAINNAME_FIELD)
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
-AC_LANG_C
+AC_LANG_CPLUSPLUS
+
+dnl Check for usable char16_t (2 bytes, unsigned)
+dnl (we might not need the unsignedness check anymore)
+AC_CACHE_CHECK(for usable char16_t (2 bytes, unsigned),
+ ac_cv_have_usable_char16_t,
+ [AC_TRY_COMPILE([$configure_static_assert_macros],
+ [CONFIGURE_STATIC_ASSERT(sizeof(char16_t) == 2);
+ CONFIGURE_STATIC_ASSERT(char16_t(-1) > char16_t(0));
+ CONFIGURE_STATIC_ASSERT(sizeof((u"hello")[0]) == 2);
+ CONFIGURE_STATIC_ASSERT(sizeof(u'a') == 2);
+ CONFIGURE_STATIC_ASSERT(u'\xFFFF' > u'\x0')],
+ ac_cv_have_usable_char16_t="yes",
+ ac_cv_have_usable_char16_t="no")])
+if test "$ac_cv_have_usable_char16_t" = "yes"; then
+ AC_DEFINE(HAVE_CPP_CHAR16_T)
+ HAVE_CPP_CHAR16_T=1
+fi
dnl Check for usable wchar_t (2 bytes, unsigned)
dnl (we really don't need the unsignedness check anymore)
dnl ========================================================
AC_CACHE_CHECK(for usable wchar_t (2 bytes, unsigned),
ac_cv_have_usable_wchar_v2,
[AC_TRY_COMPILE([#include <stddef.h>
$configure_static_assert_macros],
[CONFIGURE_STATIC_ASSERT(sizeof(wchar_t) == 2);
CONFIGURE_STATIC_ASSERT((wchar_t)-1 > (wchar_t) 0)],
ac_cv_have_usable_wchar_v2="yes",
ac_cv_have_usable_wchar_v2="no")])
if test "$ac_cv_have_usable_wchar_v2" = "yes"; then
AC_DEFINE(HAVE_CPP_2BYTE_WCHAR_T)
HAVE_CPP_2BYTE_WCHAR_T=1
-else
+elif test "$ac_cv_have_usable_char16_t" != "yes"; then
dnl This is really gcc-only
dnl Do this test using CXX only since some versions of gcc
dnl 2.95-2.97 have a signed wchar_t in c++ only and some versions
dnl only have short-wchar support for c++.
dnl Note that we assume that mac & win32 have short wchar (see nscore.h)
- AC_LANG_SAVE
- AC_LANG_CPLUSPLUS
_SAVE_CXXFLAGS=$CXXFLAGS
CXXFLAGS="$CXXFLAGS -fshort-wchar"
AC_CACHE_CHECK(for compiler -fshort-wchar option,
ac_cv_have_usable_wchar_option_v2,
[AC_TRY_LINK([#include <stddef.h>
$configure_static_assert_macros],
[CONFIGURE_STATIC_ASSERT(sizeof(wchar_t) == 2);
@@ -2925,18 +2940,19 @@ dnl Note that we assume that mac & win32
if test "$ac_cv_have_usable_wchar_option_v2" = "yes"; then
AC_DEFINE(HAVE_CPP_2BYTE_WCHAR_T)
HAVE_CPP_2BYTE_WCHAR_T=1
WCHAR_CFLAGS="-fshort-wchar"
else
CXXFLAGS=$_SAVE_CXXFLAGS
fi
- AC_LANG_RESTORE
-fi
+fi
+
+AC_LANG_C
dnl Check for .hidden assembler directive and visibility attribute.
dnl Borrowed from glibc configure.in
dnl ===============================================================
if test "$GNU_CC"; then
AC_CACHE_CHECK(for visibility(hidden) attribute,
ac_cv_visibility_hidden,
[cat > conftest.c <<EOF
@@ -8387,16 +8403,17 @@ dnl ====================================
dnl The following defines are used by xpcom
_NON_GLOBAL_ACDEFINES="$_NON_GLOBAL_ACDEFINES
CPP_THROW_NEW
HAVE_CPP_2BYTE_WCHAR_T
HAVE_CPP_ACCESS_CHANGING_USING
HAVE_CPP_AMBIGUITY_RESOLVING_USING
HAVE_CPP_BOOL
+HAVE_CPP_CHAR16_T
HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
HAVE_CPP_EXPLICIT
HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
HAVE_CPP_NAMESPACE_STD
HAVE_CPP_NEW_CASTS
HAVE_CPP_PARTIAL_SPECIALIZATION
HAVE_CPP_TROUBLE_COMPARING_TO_ZERO
HAVE_CPP_TYPENAME
--- a/js/src/config/autoconf.mk.in
+++ b/js/src/config/autoconf.mk.in
@@ -137,18 +137,16 @@ MOZ_INSURE = @MOZ_INSURE@
MOZ_INSURIFYING = @MOZ_INSURIFYING@
MOZ_INSURE_DIRS = @MOZ_INSURE_DIRS@
MOZ_INSURE_EXCLUDE_DIRS = @MOZ_INSURE_EXCLUDE_DIRS@
MOZ_NATIVE_NSPR = @MOZ_NATIVE_NSPR@
CROSS_COMPILE = @CROSS_COMPILE@
-WCHAR_CFLAGS = @WCHAR_CFLAGS@
-
OS_CPPFLAGS = @CPPFLAGS@
OS_CFLAGS = $(OS_CPPFLAGS) @CFLAGS@
OS_CXXFLAGS = $(OS_CPPFLAGS) @CXXFLAGS@
OS_LDFLAGS = @LDFLAGS@
OS_COMPILE_CFLAGS = $(OS_CPPFLAGS) @COMPILE_CFLAGS@
OS_COMPILE_CXXFLAGS = $(OS_CPPFLAGS) @COMPILE_CXXFLAGS@
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -2722,62 +2722,16 @@ if test "$ac_cv_have_uname_us_domainname
AC_DEFINE(HAVE_UNAME_US_DOMAINNAME_FIELD)
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
AC_LANG_C
-dnl Check for usable wchar_t (2 bytes, unsigned)
-dnl (we really don't need the unsignedness check anymore)
-dnl ========================================================
-
-AC_CACHE_CHECK(for usable wchar_t (2 bytes, unsigned),
- ac_cv_have_usable_wchar_v2,
- [AC_TRY_COMPILE([#include <stddef.h>
- $configure_static_assert_macros],
- [CONFIGURE_STATIC_ASSERT(sizeof(wchar_t) == 2);
- CONFIGURE_STATIC_ASSERT((wchar_t)-1 > (wchar_t) 0)],
- ac_cv_have_usable_wchar_v2="yes",
- ac_cv_have_usable_wchar_v2="no")])
-if test "$ac_cv_have_usable_wchar_v2" = "yes"; then
- AC_DEFINE(HAVE_CPP_2BYTE_WCHAR_T)
- HAVE_CPP_2BYTE_WCHAR_T=1
-else
-dnl This is really gcc-only
-dnl Do this test using CXX only since some versions of gcc
-dnl 2.95-2.97 have a signed wchar_t in c++ only and some versions
-dnl only have short-wchar support for c++.
-dnl Note that we assume that mac & win32 have short wchar (see nscore.h)
-
- AC_LANG_SAVE
- AC_LANG_CPLUSPLUS
- _SAVE_CXXFLAGS=$CXXFLAGS
- CXXFLAGS="$CXXFLAGS -fshort-wchar"
-
- AC_CACHE_CHECK(for compiler -fshort-wchar option,
- ac_cv_have_usable_wchar_option_v2,
- [AC_TRY_LINK([#include <stddef.h>
- $configure_static_assert_macros],
- [CONFIGURE_STATIC_ASSERT(sizeof(wchar_t) == 2);
- CONFIGURE_STATIC_ASSERT((wchar_t)-1 > (wchar_t) 0)],
- ac_cv_have_usable_wchar_option_v2="yes",
- ac_cv_have_usable_wchar_option_v2="no")])
-
- if test "$ac_cv_have_usable_wchar_option_v2" = "yes"; then
- AC_DEFINE(HAVE_CPP_2BYTE_WCHAR_T)
- HAVE_CPP_2BYTE_WCHAR_T=1
- WCHAR_CFLAGS="-fshort-wchar"
- else
- CXXFLAGS=$_SAVE_CXXFLAGS
- fi
- AC_LANG_RESTORE
-fi
-
dnl Check for .hidden assembler directive and visibility attribute.
dnl Borrowed from glibc configure.in
dnl ===============================================================
if test "$GNU_CC"; then
AC_CACHE_CHECK(for visibility(hidden) attribute,
ac_cv_visibility_hidden,
[cat > conftest.c <<EOF
int foo __attribute__ ((visibility ("hidden"))) = 1;
@@ -5068,17 +5022,16 @@ AC_SUBST(MOZ_NATIVE_NSPR)
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(COMPILE_CFLAGS)
AC_SUBST(COMPILE_CXXFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_SUBST(CROSS_COMPILE)
-AC_SUBST(WCHAR_CFLAGS)
AC_SUBST(HOST_CC)
AC_SUBST(HOST_CXX)
AC_SUBST(HOST_CFLAGS)
AC_SUBST(HOST_CXXFLAGS)
AC_SUBST(HOST_OPTIMIZE_FLAGS)
AC_SUBST(HOST_AR)
AC_SUBST(HOST_AR_FLAGS)
--- a/xpcom/glue/nsStringAPI.h
+++ b/xpcom/glue/nsStringAPI.h
@@ -1045,22 +1045,27 @@ private:
/**
* literal strings
*
* NOTE: HAVE_CPP_2BYTE_WCHAR_T may be automatically defined for some platforms
* in nscore.h. On other platforms, it may be defined in xpcom-config.h.
* Under GCC, this define should only be set if compiling with -fshort-wchar.
*/
-#ifdef HAVE_CPP_2BYTE_WCHAR_T
+#if defined(HAVE_CPP_CHAR16_T) || defined(HAVE_CPP_2BYTE_WCHAR_T)
+#if defined(HAVE_CPP_CHAR16_T)
+ PR_STATIC_ASSERT(sizeof(char16_t) == 2);
+ #define NS_LL(s) u##s
+#else
PR_STATIC_ASSERT(sizeof(wchar_t) == 2);
#define NS_LL(s) L##s
- #define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
- #define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
- #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
+#endif
+ #define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
+ #define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
+ #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
typedef nsDependentString nsLiteralString;
#else
#define NS_LL(s) s
#define NS_MULTILINE_LITERAL_STRING(s) NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(s, PRUint32(sizeof(s)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const NS_ConvertASCIItoUTF16 n(s, PRUint32(sizeof(s)-1))
typedef NS_ConvertASCIItoUTF16 nsLiteralString;
#endif
--- a/xpcom/string/public/nsLiteralString.h
+++ b/xpcom/string/public/nsLiteralString.h
@@ -73,21 +73,27 @@ literal_string( const nsACString::char_t
inline
const nsDependentCString
literal_string( const nsACString::char_type* aPtr, PRUint32 aLength )
{
return nsDependentCString(aPtr, aLength);
}
#endif
-#ifdef HAVE_CPP_2BYTE_WCHAR_T
+#if defined(HAVE_CPP_CHAR16_T) || defined(HAVE_CPP_2BYTE_WCHAR_T)
+#if defined(HAVE_CPP_CHAR16_T)
+ //PR_STATIC_ASSERT(sizeof(char16_t) == 2);
+ #define NS_LL(s) u##s
+#else
+ //PR_STATIC_ASSERT(sizeof(wchar_t) == 2);
#define NS_LL(s) L##s
- #define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
- #define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
- #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
+#endif
+ #define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
+ #define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
+ #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), PRUint32((sizeof(s)/2)-1))
typedef nsDependentString nsLiteralString;
#else
#define NS_LL(s) s
#define NS_MULTILINE_LITERAL_STRING(s) NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(s, PRUint32(sizeof(s)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const NS_ConvertASCIItoUTF16 n(s, PRUint32(sizeof(s)-1))
typedef NS_ConvertASCIItoUTF16 nsLiteralString;
#endif
--- a/xpcom/xpcom-config.h.in
+++ b/xpcom/xpcom-config.h.in
@@ -15,16 +15,19 @@
#undef HAVE_CPP_ACCESS_CHANGING_USING
/* Define if the c++ compiler can resolve ambiguity with |using| */
#undef HAVE_CPP_AMBIGUITY_RESOLVING_USING
/* Define if the c++ compiler has builtin Bool type */
#undef HAVE_CPP_BOOL
+/* Define if the c++ compiler supports char16_t */
+#undef HAVE_CPP_CHAR16_T
+
/* Define if a dyanmic_cast to void* gives the most derived object */
#undef HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
/* Define if the c++ compiler supports the |explicit| keyword */
#undef HAVE_CPP_EXPLICIT
/* Define if the c++ compiler supports the modern template
* specialization syntax