Break dependency on endian.h
authorOwen Yamauchi <oyamauchi@fb.com>
Fri, 3 May 2013 19:16:14 +0000 (12:16 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 20 May 2013 18:01:27 +0000 (11:01 -0700)
Summary:
gcc and clang both give you these three macros pre-defined. I've found a
reference on the interweb to this being broken
(http://gcc.gnu.org/ml/gcc/2011-08/msg00152.html) but that was with gcc
4.4. I've tested with 4.6, 4.7 and clang 3.2 and they all do the right
thing on little-endian (internal build and OS X). Alas, I don't have a
big-endian system handy to test with.

Test Plan: fbconfig/fbmake runtests.

Reviewed By: simpkins@fb.com

FB internal diff: D799416

folly/Bits.h
folly/experimental/EliasFanoCoding.h
folly/experimental/symbolizer/Elf.cpp
folly/test/EndianTest.cpp

index d9bf1ad09119ac287d3d6a5758cec706d795205e..83c61708edc42156361e3cdcfeec18450bd41028 100644 (file)
@@ -76,7 +76,6 @@
 
 #include <cassert>
 #include <cinttypes>
-#include <endian.h>
 #include <iterator>
 #include <limits>
 #include <type_traits>
@@ -268,7 +267,7 @@ FB_GEN(uint16_t, our_bswap16)
 
 #undef FB_GEN
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
 template <class T>
 struct EndianInt : public detail::EndianIntBase<T> {
@@ -277,7 +276,7 @@ struct EndianInt : public detail::EndianIntBase<T> {
   static T little(T x) { return x; }
 };
 
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 
 template <class T>
 struct EndianInt : public detail::EndianIntBase<T> {
@@ -288,7 +287,7 @@ struct EndianInt : public detail::EndianIntBase<T> {
 
 #else
 # error Your machine uses a weird endianness!
-#endif  /* __BYTE_ORDER */
+#endif  /* __BYTE_ORDER__ */
 
 }  // namespace detail
 
@@ -318,13 +317,13 @@ class Endian {
   };
 
   static constexpr Order order =
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
     Order::LITTLE;
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
     Order::BIG;
 #else
 # error Your machine uses a weird endianness!
-#endif  /* __BYTE_ORDER */
+#endif  /* __BYTE_ORDER__ */
 
   template <class T> static T swap(T x) {
     return detail::EndianInt<T>::swap(x);
index 06d54978a7776dfcc627bea56c8a396c15eae3a7..d6232b2df62605a8df4c873f7ead86508712fd90 100644 (file)
@@ -33,7 +33,6 @@
 #endif
 
 #include <cstdlib>
-#include <endian.h>
 #include <algorithm>
 #include <limits>
 #include <type_traits>
@@ -44,7 +43,7 @@
 #include "folly/Likely.h"
 #include "folly/Range.h"
 
-#if __BYTE_ORDER != __LITTLE_ENDIAN
+#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
 #error EliasFanoCoding.h requires little endianness
 #endif
 
index f28ed07b016d8cafb0fa9287f3cf077190571f68..33e20ddefa11745d28c13a4222c8903ccdef49f2 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <endian.h>
 #include <fcntl.h>
 
 #include <string>
@@ -130,9 +129,9 @@ void ElfFile::init() {
 #undef EXPECTED_CLASS
 
   // Validate ELF data encoding (LSB/MSB)
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 # define EXPECTED_ENCODING ELFDATA2LSB
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 # define EXPECTED_ENCODING ELFDATA2MSB
 #else
 # error Unsupported byte order
index cc65d8035069e9aa910e6be803fe6ff56a40345c..a08748bb6bea224c1417c50bb0c7b837bff73d35 100644 (file)
@@ -30,7 +30,7 @@ TEST(Endian, Basic) {
   uint64_t v64 = 0x123456789abcdef0ULL;
   uint64_t v64s = 0xf0debc9a78563412ULL;
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 
 #define GEN1(sz) \
   EXPECT_EQ(v##sz, Endian::little(v##sz)); \
@@ -38,7 +38,7 @@ TEST(Endian, Basic) {
   EXPECT_EQ(v##sz##s, Endian::big(v##sz)); \
   EXPECT_EQ(v##sz##s, Endian::big##sz(v##sz));
 
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 
 #define GEN1(sz) \
   EXPECT_EQ(v##sz##s, Endian::little(v##sz)); \
@@ -48,7 +48,7 @@ TEST(Endian, Basic) {
 
 #else
 # error Your machine uses a weird endianness!
-#endif  /* __BYTE_ORDER */
+#endif  /* __BYTE_ORDER__ */
 
 #define GEN(sz) \
   EXPECT_EQ(v##sz##s, Endian::swap(v##sz)); \