Fix code on big-endian gcc / clang

Ouch!  We need a bigendian bot...

Fixes https://github.com/harfbuzz/harfbuzz/issues/1498
This commit is contained in:
Behdad Esfahbod 2018-12-20 11:48:45 -05:00
parent c87ee72232
commit 4220b7bdd7
1 changed files with 7 additions and 1 deletions

View File

@ -682,11 +682,17 @@ struct BEInt<Type, 2>
} }
operator Type () const operator Type () const
{ {
#if (defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__) #if ((defined(__GNUC__) && __GNUC__ >= 5) || defined(__clang__)) && \
defined(__BYTE_ORDER) && \
(__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN)
/* Spoon-feed the compiler a big-endian integer with alignment 1. /* Spoon-feed the compiler a big-endian integer with alignment 1.
* https://github.com/harfbuzz/harfbuzz/pull/1398 */ * https://github.com/harfbuzz/harfbuzz/pull/1398 */
struct __attribute__((packed)) packed_uint16_t { uint16_t v; }; struct __attribute__((packed)) packed_uint16_t { uint16_t v; };
#if __BYTE_ORDER == __LITTLE_ENDIAN
return __builtin_bswap16 (((packed_uint16_t *) this)->v); return __builtin_bswap16 (((packed_uint16_t *) this)->v);
#else /* __BYTE_ORDER == __BIG_ENDIAN */
return ((packed_uint16_t *) this)->v;
#endif
#endif #endif
return (v[0] << 8) return (v[0] << 8)
+ (v[1] ); + (v[1] );