mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 21:58:06 +00:00
Bug 904985, part 2: Use char16_t for NS_LITERAL_STRING, r=glandium, dbaron.
--HG-- extra : rebase_source : b4c9def93d907724fb4a1bc3f6279db87a11fb1f
This commit is contained in:
parent
44ee5d6929
commit
69250ebe86
73
configure.in
73
configure.in
@ -2592,77 +2592,6 @@ 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.
|
||||
@ -8895,9 +8824,7 @@ 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
|
||||
|
@ -376,7 +376,7 @@ nsHTMLTags::AddRefTable(void)
|
||||
|
||||
|
||||
|
||||
#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) {
|
||||
|
@ -328,18 +328,9 @@ typedef uint32_t nsrefcnt;
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* 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;
|
||||
|
@ -557,7 +557,6 @@ RegisterStaticAtoms(const nsStaticAtom* aAtoms, uint32_t aAtomCount)
|
||||
}
|
||||
|
||||
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!");
|
||||
|
||||
@ -591,22 +590,6 @@ RegisterStaticAtoms(const nsStaticAtom* aAtoms, uint32_t aAtomCount)
|
||||
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;
|
||||
}
|
||||
|
@ -10,15 +10,7 @@
|
||||
#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) };
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define nsStringAPI_h__
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Char16.h"
|
||||
|
||||
#include "nsXPCOMStrings.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
@ -1073,31 +1074,15 @@ 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.
|
||||
*/
|
||||
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");
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include "nsDependentString.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/Char16.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace internal {
|
||||
|
||||
@ -26,42 +28,20 @@ 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.
|
||||
|
@ -52,9 +52,12 @@
|
||||
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
|
||||
*/
|
||||
|
@ -12,15 +12,9 @@
|
||||
*/
|
||||
#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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user