зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1277106 - Part 1: Use VS2015's real char16_t instead of aliasing wchar_t. r=Waldo
and remove MOZ_CHAR16_IS_NOT_WCHAR #ifdefs.
This commit is contained in:
Родитель
05710be1e4
Коммит
8949f73d27
|
@ -17,38 +17,8 @@
|
||||||
* is a 16-bit code unit of a Unicode code point, not a "character".
|
* is a 16-bit code unit of a Unicode code point, not a "character".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
#ifdef WIN32
|
||||||
/*
|
# define MOZ_USE_CHAR16_WRAPPER
|
||||||
* C++11 says char16_t is a distinct builtin type, but Windows's yvals.h
|
|
||||||
* typedefs char16_t as an unsigned short prior to MSVC 2015, which
|
|
||||||
* implemented C++11's distinct char16_t type. We would like to alias
|
|
||||||
* char16_t to Windows's 16-bit wchar_t so we can declare UTF-16 literals as
|
|
||||||
* constant expressions (and pass char16_t pointers to Windows APIs). We
|
|
||||||
* #define _CHAR16T here in order to prevent yvals.h from overriding our
|
|
||||||
* char16_t typedefs, which we set to wchar_t for C++ code.
|
|
||||||
*
|
|
||||||
* In addition, #defining _CHAR16T will prevent yvals.h from defining a
|
|
||||||
* char32_t type, so we have to undo that damage here and provide our own,
|
|
||||||
* which is identical to the yvals.h type.
|
|
||||||
*/
|
|
||||||
# define MOZ_UTF16_HELPER(s) L##s
|
|
||||||
# define _CHAR16T
|
|
||||||
typedef wchar_t char16_t;
|
|
||||||
typedef unsigned int char32_t;
|
|
||||||
#else
|
|
||||||
/* C++11 has a builtin char16_t type. */
|
|
||||||
# define MOZ_UTF16_HELPER(s) u##s
|
|
||||||
/**
|
|
||||||
* This macro is used to distinguish when char16_t would be a distinct
|
|
||||||
* typedef from wchar_t.
|
|
||||||
*/
|
|
||||||
# define MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
# ifdef WIN32
|
|
||||||
# define MOZ_USE_CHAR16_WRAPPER
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MOZ_USE_CHAR16_WRAPPER
|
|
||||||
# include <cstdint>
|
# include <cstdint>
|
||||||
/**
|
/**
|
||||||
* Win32 API extensively uses wchar_t, which is represented by a separated
|
* Win32 API extensively uses wchar_t, which is represented by a separated
|
||||||
|
@ -222,12 +192,15 @@ typedef const char16_t* char16ptr_t;
|
||||||
* argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the
|
* argument to expand. See "3.10.6 Separate Expansion of Macro Arguments" of the
|
||||||
* CPP manual for a more accurate and precise explanation.
|
* CPP manual for a more accurate and precise explanation.
|
||||||
*/
|
*/
|
||||||
|
#define MOZ_UTF16_HELPER(s) u##s
|
||||||
#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s)
|
#define MOZ_UTF16(s) MOZ_UTF16_HELPER(s)
|
||||||
|
|
||||||
static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?");
|
static_assert(sizeof(char16_t) == 2, "Is char16_t type 16 bits?");
|
||||||
static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?");
|
static_assert(char16_t(-1) > char16_t(0), "Is char16_t type unsigned?");
|
||||||
static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?");
|
static_assert(sizeof(MOZ_UTF16('A')) == 2, "Is char literal 16 bits?");
|
||||||
static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?");
|
static_assert(sizeof(MOZ_UTF16("")[0]) == 2, "Is string char 16 bits?");
|
||||||
|
static_assert(sizeof(u'A') == 2, "Is unicode char literal 16 bits?");
|
||||||
|
static_assert(sizeof(u""[0]) == 2, "Is unicode string char 16 bits?");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* This file exports functions for hashing data down to a 32-bit value,
|
* This file exports functions for hashing data down to a 32-bit value,
|
||||||
* including:
|
* including:
|
||||||
*
|
*
|
||||||
* - HashString Hash a char* or uint16_t/wchar_t* of known or unknown
|
* - HashString Hash a char* or char16_t/wchar_t* of known or unknown
|
||||||
* length.
|
* length.
|
||||||
*
|
*
|
||||||
* - HashBytes Hash a byte array of known length.
|
* - HashBytes Hash a byte array of known length.
|
||||||
|
@ -259,19 +259,6 @@ HashString(const unsigned char* aStr, size_t aLength)
|
||||||
return detail::HashKnownLength(aStr, aLength);
|
return detail::HashKnownLength(aStr, aLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_MUST_USE inline uint32_t
|
|
||||||
HashString(const uint16_t* aStr)
|
|
||||||
{
|
|
||||||
return detail::HashUntilZero(aStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_MUST_USE inline uint32_t
|
|
||||||
HashString(const uint16_t* aStr, size_t aLength)
|
|
||||||
{
|
|
||||||
return detail::HashKnownLength(aStr, aLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
MOZ_MUST_USE inline uint32_t
|
MOZ_MUST_USE inline uint32_t
|
||||||
HashString(const char16_t* aStr)
|
HashString(const char16_t* aStr)
|
||||||
{
|
{
|
||||||
|
@ -283,10 +270,9 @@ HashString(const char16_t* aStr, size_t aLength)
|
||||||
{
|
{
|
||||||
return detail::HashKnownLength(aStr, aLength);
|
return detail::HashKnownLength(aStr, aLength);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On Windows, wchar_t (char16_t) is not the same as uint16_t, even though it's
|
* On Windows, wchar_t is not the same as char16_t, even though it's
|
||||||
* the same width!
|
* the same width!
|
||||||
*/
|
*/
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
@ -27,13 +27,11 @@ class NumericLimits : public std::numeric_limits<T>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
template<>
|
template<>
|
||||||
class NumericLimits<char16_t> : public std::numeric_limits<uint16_t>
|
class NumericLimits<char16_t> : public std::numeric_limits<uint16_t>
|
||||||
{
|
{
|
||||||
// char16_t and uint16_t numeric limits should be exactly the same.
|
// char16_t and uint16_t numeric limits should be exactly the same.
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,7 @@ template<> struct IsIntegralHelper<long long> : TrueType {};
|
||||||
template<> struct IsIntegralHelper<unsigned long long> : TrueType {};
|
template<> struct IsIntegralHelper<unsigned long long> : TrueType {};
|
||||||
template<> struct IsIntegralHelper<bool> : TrueType {};
|
template<> struct IsIntegralHelper<bool> : TrueType {};
|
||||||
template<> struct IsIntegralHelper<wchar_t> : TrueType {};
|
template<> struct IsIntegralHelper<wchar_t> : TrueType {};
|
||||||
#ifdef MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
template<> struct IsIntegralHelper<char16_t> : TrueType {};
|
template<> struct IsIntegralHelper<char16_t> : TrueType {};
|
||||||
#endif
|
|
||||||
|
|
||||||
} /* namespace detail */
|
} /* namespace detail */
|
||||||
|
|
||||||
|
@ -112,9 +110,6 @@ template<> struct IsIntegralHelper<char16_t> : TrueType {};
|
||||||
* mozilla::IsIntegral<const long>::value is true;
|
* mozilla::IsIntegral<const long>::value is true;
|
||||||
* mozilla::IsIntegral<int*>::value is false;
|
* mozilla::IsIntegral<int*>::value is false;
|
||||||
* mozilla::IsIntegral<double>::value is false;
|
* mozilla::IsIntegral<double>::value is false;
|
||||||
*
|
|
||||||
* Note that the behavior of IsIntegral on char16_t and char32_t is
|
|
||||||
* unspecified.
|
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct IsIntegral : detail::IsIntegralHelper<typename RemoveCV<T>::Type>
|
struct IsIntegral : detail::IsIntegralHelper<typename RemoveCV<T>::Type>
|
||||||
|
@ -444,9 +439,7 @@ template<> struct IsPod<bool> : TrueType {};
|
||||||
template<> struct IsPod<float> : TrueType {};
|
template<> struct IsPod<float> : TrueType {};
|
||||||
template<> struct IsPod<double> : TrueType {};
|
template<> struct IsPod<double> : TrueType {};
|
||||||
template<> struct IsPod<wchar_t> : TrueType {};
|
template<> struct IsPod<wchar_t> : TrueType {};
|
||||||
#ifdef MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
template<> struct IsPod<char16_t> : TrueType {};
|
template<> struct IsPod<char16_t> : TrueType {};
|
||||||
#endif
|
|
||||||
template<typename T> struct IsPod<T*> : TrueType {};
|
template<typename T> struct IsPod<T*> : TrueType {};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
|
@ -1160,13 +1160,11 @@ BuildTempPath(wchar_t* aBuf, size_t aBufLen)
|
||||||
return GetTempPath(pathLen, aBuf);
|
return GetTempPath(pathLen, aBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_CHAR16_IS_NOT_WCHAR
|
|
||||||
static size_t
|
static size_t
|
||||||
BuildTempPath(char16_t* aBuf, size_t aBufLen)
|
BuildTempPath(char16_t* aBuf, size_t aBufLen)
|
||||||
{
|
{
|
||||||
return BuildTempPath(reinterpret_cast<wchar_t*>(aBuf), aBufLen);
|
return BuildTempPath(reinterpret_cast<wchar_t*>(aBuf), aBufLen);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(XP_MACOSX)
|
#elif defined(XP_MACOSX)
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче