From 4220b7bdd7706622563401bf8f055c4b1482b4e5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 20 Dec 2018 11:48:45 -0500 Subject: [PATCH] Fix code on big-endian gcc / clang Ouch! We need a bigendian bot... Fixes https://github.com/harfbuzz/harfbuzz/issues/1498 --- src/hb-machinery.hh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 8cce61c9c..1205b1fea 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -682,11 +682,17 @@ struct BEInt } 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. * https://github.com/harfbuzz/harfbuzz/pull/1398 */ struct __attribute__((packed)) packed_uint16_t { uint16_t v; }; +#if __BYTE_ORDER == __LITTLE_ENDIAN return __builtin_bswap16 (((packed_uint16_t *) this)->v); +#else /* __BYTE_ORDER == __BIG_ENDIAN */ + return ((packed_uint16_t *) this)->v; +#endif #endif return (v[0] << 8) + (v[1] );