Commit e49f2768 authored by Owen Yamauchi's avatar Owen Yamauchi Committed by Sara Golemon

Break dependency on endian.h

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
parent 29ad1ec9
......@@ -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);
......
......@@ -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
......
......@@ -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
......
......@@ -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)); \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment