Bug 904985, part 2: Use char16_t for NS_LITERAL_STRING, r=glandium, dbaron.
authorJoshua Cranmer <Pidgeot18@gmail.com>
Tue, 17 Sep 2013 22:43:12 -0500
changeset 147680 0a62484ff46bb8ed6d3bb173ab04bc46c62b659b
parent 147679 11af1e7c053fca4335554f74bae45ed0343fb6f1
child 147681 b0479039a28615cf897b618882b411f9f65e66a8
push id25309
push usercbook@mozilla.com
push dateWed, 18 Sep 2013 10:10:22 +0000
treeherdermozilla-central@e4c63d61ecba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, dbaron
bugs904985
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 904985, part 2: Use char16_t for NS_LITERAL_STRING, r=glandium, dbaron.
configure.in
parser/htmlparser/src/nsHTMLTags.cpp
xpcom/base/nscore.h
xpcom/ds/nsAtomTable.cpp
xpcom/ds/nsStaticAtom.h
xpcom/glue/nsStringAPI.h
xpcom/string/public/nsLiteralString.h
xpcom/string/public/nsString.h
xpcom/xpcom-config.h.in
--- a/configure.in
+++ b/configure.in
@@ -2587,87 +2587,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
 
 MOZ_CXX11
 
-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
-elif test "$GNU_CXX"; then
-    CXXFLAGS="$_SAVE_CXXFLAGS"
-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
-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)
-
-    _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
-        if test "$OS_TARGET" = Android; then
-            WCHAR_CFLAGS="-fshort-wchar -Wl,--no-wchar-size-warning"
-            CXXFLAGS="$CXXFLAGS -Wl,--no-wchar-size-warning"
-            CFLAGS="$CFLAGS -Wl,--no-wchar-size-warning"
-            DSO_LDOPTS="$DSO_LDOPTS -Wl,--no-wchar-size-warning"
-        else
-            WCHAR_CFLAGS="-fshort-wchar"
-        fi
-    else
-        CXXFLAGS=$_SAVE_CXXFLAGS
-    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,
@@ -8890,19 +8819,17 @@ AC_SUBST(MOZILLA_VERSION)
 AC_SUBST(ac_configure_args)
 
 dnl Spit out some output
 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_AMBIGUITY_RESOLVING_USING
-HAVE_CPP_CHAR16_T
 HAVE_CPP_DYNAMIC_CAST_TO_VOID_PTR
 HAVE_CPP_PARTIAL_SPECIALIZATION
 HAVE_CPP_TROUBLE_COMPARING_TO_ZERO
 NEED_CPP_UNUSED_IMPLEMENTATIONS
 HAVE_GETPAGESIZE
 HAVE_ICONV
 HAVE_ICONV_WITH_CONST_INPUT
 HAVE_MBRTOWC
--- a/parser/htmlparser/src/nsHTMLTags.cpp
+++ b/parser/htmlparser/src/nsHTMLTags.cpp
@@ -371,17 +371,17 @@ nsHTMLTags::AddRefTable(void)
                       NS_INT32_TO_PTR(i + 1));
 
       PL_HashTableAdd(gTagAtomTable, sTagAtomTable[i],
                       NS_INT32_TO_PTR(i + 1));
     }
 
 
 
-#if defined(DEBUG) && defined(NS_STATIC_ATOM_USE_WIDE_STRINGS)
+#if defined(DEBUG)
     {
       // let's verify that all names in the the table are lowercase...
       for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
         nsAutoString temp1((PRUnichar*)sTagAtoms_info[i].mStringBuffer->Data());
         nsAutoString temp2((PRUnichar*)sTagAtoms_info[i].mStringBuffer->Data());
         ToLowerCase(temp1);
         NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
       }
--- a/xpcom/base/nscore.h
+++ b/xpcom/base/nscore.h
@@ -323,28 +323,19 @@
 typedef unsigned long nsrefcnt;
 #else
 typedef uint32_t nsrefcnt;
 #endif
 
 /* ------------------------------------------------------------------------ */
 /* Casting macros for hiding C++ features from older compilers */
 
-  /* under VC++ (Windows), we don't have autoconf yet */
-#if defined(_MSC_VER)
-  #define HAVE_CPP_2BYTE_WCHAR_T
-#endif
-
 #ifndef __PRUNICHAR__
 #define __PRUNICHAR__
-  /* For now, don't use wchar_t on Unix because it breaks the Netscape
-   * commercial build.  When this is fixed there will be no need for the
-   * |reinterpret_cast| in nsLiteralString.h either.
-   */
-  #if defined(HAVE_CPP_2BYTE_WCHAR_T) && defined(XP_WIN)
+  #if defined(WIN32)
     typedef wchar_t PRUnichar;
   #else
     typedef uint16_t PRUnichar;
   #endif
 #endif
 
 /*
  * Use these macros to do 64bit safe pointer conversions.
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -552,17 +552,16 @@ RegisterStaticAtoms(const nsStaticAtom* 
   // 2) initializes the address pointed to by each mBits slot
   // 3) puts the atom into the static atom table as well
   
   if (!gStaticAtomTable && !gStaticAtomTableSealed) {
     gStaticAtomTable = new nsDataHashtable<nsStringHashKey, nsIAtom*>();
   }
   
   for (uint32_t i=0; i<aAtomCount; i++) {
-#ifdef NS_STATIC_ATOM_USE_WIDE_STRINGS
     NS_ASSERTION(nsCRT::IsAscii((PRUnichar*)aAtoms[i].mStringBuffer->Data()),
                  "Static atoms must be ASCII!");
 
     uint32_t stringLen =
       aAtoms[i].mStringBuffer->StorageSize() / sizeof(PRUnichar) - 1;
 
     AtomTableEntry *he =
       GetAtomHashEntry((PRUnichar*)aAtoms[i].mStringBuffer->Data(),
@@ -586,32 +585,16 @@ RegisterStaticAtoms(const nsStaticAtom* 
                                              he->keyHash);
       he->mAtom = atom;
       *aAtoms[i].mAtom = atom;
 
       if (!gStaticAtomTableSealed) {
         gStaticAtomTable->Put(nsAtomString(atom), atom);
       }
     }
-#else // NS_STATIC_ATOM_USE_WIDE_STRINGS
-    NS_ASSERTION(nsCRT::IsAscii((char*)aAtoms[i].mStringBuffer->Data()),
-                 "Static atoms must be ASCII!");
-
-    uint32_t stringLen = aAtoms[i].mStringBuffer->StorageSize() - 1;
-
-    NS_ConvertASCIItoUTF16 str((char*)aAtoms[i].mStringBuffer->Data(),
-                               stringLen);
-    nsIAtom* atom = NS_NewPermanentAtom(str);
-    *aAtoms[i].mAtom = atom;
-
-    if (!gStaticAtomTableSealed) {
-      gStaticAtomTable->Put(str, atom);
-    }
-#endif
-
   }
   return NS_OK;
 }
 
 already_AddRefed<nsIAtom>
 NS_NewAtom(const char* aUTF8String)
 {
   return NS_NewAtom(nsDependentCString(aUTF8String));
--- a/xpcom/ds/nsStaticAtom.h
+++ b/xpcom/ds/nsStaticAtom.h
@@ -5,25 +5,17 @@
 
 #ifndef nsStaticAtom_h__
 #define nsStaticAtom_h__
 
 #include "nsIAtom.h"
 #include "nsStringBuffer.h"
 #include "prlog.h"
 
-#if defined(HAVE_CPP_CHAR16_T)
-#define NS_STATIC_ATOM_USE_WIDE_STRINGS
 typedef char16_t nsStaticAtomStringType;
-#elif defined(HAVE_CPP_2BYTE_WCHAR_T)
-#define NS_STATIC_ATOM_USE_WIDE_STRINGS
-typedef wchar_t nsStaticAtomStringType;
-#else
-typedef char nsStaticAtomStringType;
-#endif
 
 #define NS_STATIC_ATOM(buffer_name, atom_ptr)  { (nsStringBuffer*) &buffer_name, atom_ptr }
 #define NS_STATIC_ATOM_BUFFER(buffer_name, str_data) static nsFakeStringBuffer< sizeof(str_data) > buffer_name = { 1, sizeof(str_data) * sizeof(nsStaticAtomStringType), NS_L(str_data) };
 
 /**
  * Holds data used to initialize large number of atoms during startup. Use
  * the above macros to initialize these structs. They should never be accessed
  * directly other than from AtomTable.cpp
--- a/xpcom/glue/nsStringAPI.h
+++ b/xpcom/glue/nsStringAPI.h
@@ -11,16 +11,17 @@
 #ifdef MOZILLA_INTERNAL_API
 #error nsStringAPI.h is only usable from non-MOZILLA_INTERNAL_API code!
 #endif
 
 #ifndef nsStringAPI_h__
 #define nsStringAPI_h__
 
 #include "mozilla/Attributes.h"
+#include "mozilla/Char16.h"
 
 #include "nsXPCOMStrings.h"
 #include "nsISupportsImpl.h"
 #include "prlog.h"
 #include "nsTArray.h"
 
 /**
  * Comparison function for use with nsACString::Equals
@@ -1068,41 +1069,25 @@ public:
 
 private:
   self_type& operator=(const self_type& aString) MOZ_DELETE;
 };
 
 
 /**
  * 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.
  */
+static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
+static_assert(char16_t(-1) > char16_t(0), "char16_t must be unsigned");
 
-#if defined(HAVE_CPP_CHAR16_T) || defined(HAVE_CPP_2BYTE_WCHAR_T)
-#if defined(HAVE_CPP_CHAR16_T)
-  static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
-  #define NS_LL(s)                                u##s
-#else
-  static_assert(sizeof(wchar_t) == 2, "size of wchar_t must be 2");
-  #define NS_LL(s)                                L##s
-#endif
-  #define NS_MULTILINE_LITERAL_STRING(s)          nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
-  #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
-  #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
-  typedef nsDependentString nsLiteralString;
-#else
-  #define NS_LL(s)                                s
-  #define NS_MULTILINE_LITERAL_STRING(s)          NS_ConvertASCIItoUTF16(s, uint32_t(sizeof(s)-1))
-  #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(s, uint32_t(sizeof(s)-1))
-  #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const NS_ConvertASCIItoUTF16 n(s, uint32_t(sizeof(s)-1))
-  typedef NS_ConvertASCIItoUTF16 nsLiteralString;
-#endif
+#define NS_LL(s) MOZ_UTF16(s)
+#define NS_MULTILINE_LITERAL_STRING(s)          nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
+#define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
+#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
+typedef nsDependentString nsLiteralString;
 
 /* Check that PRUnichar is unsigned */
 static_assert(PRUnichar(-1) > PRUnichar(0), "PRUnichar is by definition an unsigned type");
 
 /*
  * Macro arguments used in concatenation or stringification won't be expanded.
  * Therefore, in order for |NS_L(FOO)| to work as expected (which is to expand
  * |FOO| before doing whatever |NS_L| needs to do to it) a helper macro needs
--- a/xpcom/string/public/nsLiteralString.h
+++ b/xpcom/string/public/nsLiteralString.h
@@ -9,64 +9,44 @@
 #ifndef nscore_h___
 #include "nscore.h"
 #endif
 
 #ifndef nsDependentString_h___
 #include "nsDependentString.h"
 #endif
 
+#include "mozilla/Char16.h"
+
 namespace mozilla {
 namespace internal {
 
 // This is the same as sizeof(c) - 1, except it won't compile if c isn't a
 // string literal.  This ensures that NS_LITERAL_CSTRING doesn't compile if you
 // pass it a char* (or something else for that matter).
 template<int n>
 inline uint32_t LiteralStringLength(const char (&c)[n])
 {
   return n - 1;
 }
 
-#if defined(HAVE_CPP_CHAR16_T)
 template<int n>
 inline uint32_t LiteralWStringLength(const char16_t (&c)[n])
 {
   return n - 1;
 }
-#elif defined(HAVE_CPP_2BYTE_WCHAR_T)
-template<int n>
-inline uint32_t LiteralWStringLength(const wchar_t (&c)[n])
-{
-  return n - 1;
-}
-#endif
 
 } // namespace internal
 } // namespace mozilla
 
-#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
-#endif
-  #define NS_MULTILINE_LITERAL_STRING(s)          nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
-  #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
-  #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
-  typedef nsDependentString nsLiteralString;
-#else
-  #define NS_LL(s)                                s
-  #define NS_MULTILINE_LITERAL_STRING(s)          NS_ConvertASCIItoUTF16(s, mozilla::internal::LiteralStringLength(s))
-  #define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(s, mozilla::internal::LiteralStringLength(s))
-  #define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const NS_ConvertASCIItoUTF16 n(s, mozilla::internal::LiteralStringLength(s))
-  typedef NS_ConvertASCIItoUTF16 nsLiteralString;
-#endif
+#define NS_LL(s) MOZ_UTF16(s)
+#define NS_MULTILINE_LITERAL_STRING(s)          nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
+#define NS_MULTILINE_LITERAL_STRING_INIT(n,s)   n(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
+#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s)  const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), mozilla::internal::LiteralWStringLength(s))
+typedef nsDependentString nsLiteralString;
 
 /*
  * Macro arguments used in concatenation or stringification won't be expanded.
  * Therefore, in order for |NS_L(FOO)| to work as expected (which is to expand
  * |FOO| before doing whatever |NS_L| needs to do to it) a helper macro needs
  * to be inserted in between to allow the macro argument to expand.
  * See "3.10.6 Separate Expansion of Macro Arguments" of the CPP manual for a
  * more accurate and precise explanation.
--- a/xpcom/string/public/nsString.h
+++ b/xpcom/string/public/nsString.h
@@ -47,19 +47,22 @@
   // declare nsCString, et. al.
 #include "string-template-def-char.h"
 #include "nsTString.h"
 #include "string-template-undef.h"
 
 static_assert(sizeof(PRUnichar) == 2, "size of PRUnichar must be 2");
 static_assert(sizeof(nsString::char_type) == 2,
               "size of nsString::char_type must be 2");
+static_assert(nsString::char_type(-1) > nsString::char_type(0),
+              "nsString::char_type must be unsigned");
 static_assert(sizeof(nsCString::char_type) == 1,
               "size of nsCString::char_type must be 1");
 
+
   /**
    * A helper class that converts a UTF-16 string to ASCII in a lossy manner
    */
 class NS_LossyConvertUTF16toASCII : public nsAutoCString
   {
     public:
       explicit
       NS_LossyConvertUTF16toASCII( const PRUnichar* aString )
--- a/xpcom/xpcom-config.h.in
+++ b/xpcom/xpcom-config.h.in
@@ -7,25 +7,19 @@
 #ifndef _XPCOM_CONFIG_H_
 #define _XPCOM_CONFIG_H_
 
 /* Define this to throw() if the compiler complains about 
  * constructors returning NULL
  */
 #undef CPP_THROW_NEW
 
-/* Define if the c++ compiler supports a 2-byte wchar_t */
-#undef HAVE_CPP_2BYTE_WCHAR_T
-
 /* Define if the c++ compiler can resolve ambiguity with |using| */
 #undef HAVE_CPP_AMBIGUITY_RESOLVING_USING
 
-/* 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 has trouble comparing a constant
  * reference to a templatized class to zero
  */
 #undef HAVE_CPP_TROUBLE_COMPARING_TO_ZERO