From 04a9262151dfc34311a44ccad828e624dc812594 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 7 Oct 2017 17:02:31 -0400 Subject: [PATCH] ARROW-1656: [C++] Endianness Macro is Incorrect on Windows And Mac --- cpp/src/arrow/util/bit-util.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index dd102459697..2509de21ffb 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -18,13 +18,29 @@ #ifndef ARROW_UTIL_BIT_UTIL_H #define ARROW_UTIL_BIT_UTIL_H -#if defined(__APPLE__) +#ifdef _WIN32 +#define ARROW_LITTLE_ENDIAN 1 +#else +#ifdef __APPLE__ #include -#elif defined(_WIN32) -#define __LITTLE_ENDIAN 1 #else #include #endif +# +#ifndef __BYTE_ORDER__ +#error "__BYTE_ORDER__ not defined" +#endif +# +#ifndef __ORDER_LITTLE_ENDIAN__ +#error "__ORDER_LITTLE_ENDIAN__ not defined" +#endif +# +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define ARROW_LITTLE_ENDIAN 1 +#else +#define ARROW_LITTLE_ENDIAN 0 +#endif +#endif #if defined(_MSC_VER) #define ARROW_BYTE_SWAP64 _byteswap_uint64 @@ -324,7 +340,7 @@ static inline void ByteSwap(void* dst, const void* src, int len) { /// Converts to big endian format (if not already in big endian) from the /// machine's native endian format. -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if ARROW_LITTLE_ENDIAN static inline int64_t ToBigEndian(int64_t value) { return ByteSwap(value); } static inline uint64_t ToBigEndian(uint64_t value) { return ByteSwap(value); } static inline int32_t ToBigEndian(int32_t value) { return ByteSwap(value); } @@ -341,7 +357,7 @@ static inline uint16_t ToBigEndian(uint16_t val) { return val; } #endif /// Converts from big endian format to the machine's native endian format. -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if ARROW_LITTLE_ENDIAN static inline int64_t FromBigEndian(int64_t value) { return ByteSwap(value); } static inline uint64_t FromBigEndian(uint64_t value) { return ByteSwap(value); } static inline int32_t FromBigEndian(int32_t value) { return ByteSwap(value); }