Refactor _LIBCPP_<LITTLE|BIG>_ENDIAN
authorEric Fiselier <eric@efcs.ca>
Tue, 17 Oct 2017 13:16:01 +0000 (13:16 +0000)
committerEric Fiselier <eric@efcs.ca>
Tue, 17 Oct 2017 13:16:01 +0000 (13:16 +0000)
Previously this macro used 0/1 to indicate if it was set.
This is unlike all other libc++ configuration macros which
use ifdef/ifndef.

This patch makes this macro consistent with everything else.

llvm-svn: 315995

libcxx/include/__config
libcxx/include/string

index b5b1fd5..d621723 100644 (file)
 
 #ifdef __LITTLE_ENDIAN__
 #if __LITTLE_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 1
-#define _LIBCPP_BIG_ENDIAN    0
+#define _LIBCPP_LITTLE_ENDIAN
 #endif  // __LITTLE_ENDIAN__
 #endif  // __LITTLE_ENDIAN__
 
 #ifdef __BIG_ENDIAN__
 #if __BIG_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 0
-#define _LIBCPP_BIG_ENDIAN    1
+#define _LIBCPP_BIG_ENDIAN
 #endif  // __BIG_ENDIAN__
 #endif  // __BIG_ENDIAN__
 
 #ifdef __BYTE_ORDER__
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 1
-#define _LIBCPP_BIG_ENDIAN 0
+#define _LIBCPP_LITTLE_ENDIAN
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 0
-#define _LIBCPP_BIG_ENDIAN 1
+#define _LIBCPP_BIG_ENDIAN
 #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #endif // __BYTE_ORDER__
 
 #ifdef __FreeBSD__
 # include <sys/endian.h>
 #  if _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN    0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else  // _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN    1
+#   define _LIBCPP_BIG_ENDIAN
 # endif  // _BYTE_ORDER == _LITTLE_ENDIAN
 # ifndef __LONG_LONG_SUPPORTED
 #  define _LIBCPP_HAS_NO_LONG_LONG
 #ifdef __NetBSD__
 # include <sys/endian.h>
 #  if _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN    0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else  // _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN    1
+#   define _LIBCPP_BIG_ENDIAN
 # endif  // _BYTE_ORDER == _LITTLE_ENDIAN
 # define _LIBCPP_HAS_QUICK_EXIT
 #endif  // __NetBSD__
 
 #if defined(_WIN32)
 #  define _LIBCPP_WIN32API
-#  define _LIBCPP_LITTLE_ENDIAN 1
-#  define _LIBCPP_BIG_ENDIAN    0
+#  define _LIBCPP_LITTLE_ENDIAN
 #  define _LIBCPP_SHORT_WCHAR   1
 // Both MinGW and native MSVC provide a "MSVC"-like enviroment
 #  define _LIBCPP_MSVCRT_LIKE
 #ifdef __sun__
 # include <sys/isa_defs.h>
 # ifdef _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN    0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN    1
+#   define _LIBCPP_BIG_ENDIAN
 # endif
 #endif // __sun__
 
 # define _LIBCPP_USING_DEV_RANDOM
 #endif
 
-#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
 # include <endian.h>
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define _LIBCPP_LITTLE_ENDIAN 1
-#  define _LIBCPP_BIG_ENDIAN    0
+#  define _LIBCPP_LITTLE_ENDIAN
 # elif __BYTE_ORDER == __BIG_ENDIAN
-#  define _LIBCPP_LITTLE_ENDIAN 0
-#  define _LIBCPP_BIG_ENDIAN    1
+#  define _LIBCPP_BIG_ENDIAN
 # else  // __BYTE_ORDER == __BIG_ENDIAN
 #  error unable to determine endian
 # endif
-#endif  // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+#endif  // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
 
 #if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
 #define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
index 7775587..acd2876 100644 (file)
@@ -670,7 +670,7 @@ private:
         size_type __cap_;
     };
 
-#if _LIBCPP_BIG_ENDIAN
+#ifdef _LIBCPP_BIG_ENDIAN
     static const size_type __short_mask = 0x01;
     static const size_type __long_mask  = 0x1ul;
 #else  // _LIBCPP_BIG_ENDIAN
@@ -700,7 +700,7 @@ private:
         pointer   __data_;
     };
 
-#if _LIBCPP_BIG_ENDIAN
+#ifdef _LIBCPP_BIG_ENDIAN
     static const size_type __short_mask = 0x80;
     static const size_type __long_mask  = ~(size_type(~0) >> 1);
 #else  // _LIBCPP_BIG_ENDIAN
@@ -1241,7 +1241,7 @@ private:
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_short_size(size_type __s) _NOEXCEPT
-#   if _LIBCPP_BIG_ENDIAN
+#   ifdef _LIBCPP_BIG_ENDIAN
         {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
 #   else
         {__r_.first().__s.__size_ = (unsigned char)(__s);}
@@ -1249,7 +1249,7 @@ private:
 
     _LIBCPP_INLINE_VISIBILITY
     size_type __get_short_size() const _NOEXCEPT
-#   if _LIBCPP_BIG_ENDIAN
+#   ifdef _LIBCPP_BIG_ENDIAN
         {return __r_.first().__s.__size_ >> 1;}
 #   else
         {return __r_.first().__s.__size_;}
@@ -1259,7 +1259,7 @@ private:
 
     _LIBCPP_INLINE_VISIBILITY
     void __set_short_size(size_type __s) _NOEXCEPT
-#   if _LIBCPP_BIG_ENDIAN
+#   ifdef _LIBCPP_BIG_ENDIAN
         {__r_.first().__s.__size_ = (unsigned char)(__s);}
 #   else
         {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
@@ -1267,7 +1267,7 @@ private:
 
     _LIBCPP_INLINE_VISIBILITY
     size_type __get_short_size() const _NOEXCEPT
-#   if _LIBCPP_BIG_ENDIAN
+#   ifdef _LIBCPP_BIG_ENDIAN
         {return __r_.first().__s.__size_;}
 #   else
         {return __r_.first().__s.__size_ >> 1;}
@@ -2870,7 +2870,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
 {
     size_type __m = __alloc_traits::max_size(__alloc());
-#if _LIBCPP_BIG_ENDIAN
+#ifdef _LIBCPP_BIG_ENDIAN
     return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
 #else
     return __m - __alignment;