From: Behdad Esfahbod Date: Thu, 6 Aug 2009 22:24:55 +0000 (-0400) Subject: [HB] Fix unaligned access X-Git-Tag: 1.25.1~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=374f30c9d62a0559d71bbd610b10249d049e7778;p=platform%2Fupstream%2Fpango.git [HB] Fix unaligned access --- diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index e580203..08dd075 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -389,8 +389,8 @@ struct Sanitizer * Int types */ -/* TODO On machines that do not allow unaligned access, fix the accessors. */ -#define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN, BYTES) \ +/* TODO On machines that allow unaligned access, use this version. */ +#define _DEFINE_INT_TYPE1_UNALIGNED(NAME, TYPE, BIG_ENDIAN, BYTES) \ struct NAME \ { \ inline NAME& operator = (TYPE i) { (TYPE&) v = BIG_ENDIAN (i); return *this; } \ @@ -400,7 +400,21 @@ struct Sanitizer SANITIZE_DEBUG (); \ return SANITIZE_SELF (); \ } \ - private: char v[BYTES]; \ + private: unsigned char v[BYTES]; \ + }; \ + ASSERT_SIZE (NAME, BYTES) + +#define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN, BYTES) \ + struct NAME \ + { \ + inline NAME& operator = (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ + inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ + inline bool operator== (NAME o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ + inline bool sanitize (SANITIZE_ARG_DEF) { \ + SANITIZE_DEBUG (); \ + return SANITIZE_SELF (); \ + } \ + private: unsigned char v[BYTES]; \ }; \ ASSERT_SIZE (NAME, BYTES) #define DEFINE_INT_TYPE0(NAME, type, b) DEFINE_INT_TYPE1 (NAME, type##_t, hb_be_##type, b) diff --git a/pango/opentype/hb-private.h b/pango/opentype/hb-private.h index 5cb2f56..98b322f 100644 --- a/pango/opentype/hb-private.h +++ b/pango/opentype/hb-private.h @@ -78,6 +78,28 @@ typedef GStaticMutex hb_mutex_t; #endif +#define hb_be_uint8_put_unaligned(v,V) (v[0] = (V), 0) +#define hb_be_uint8_get_unaligned(v) (uint8_t) (v[0]) +#define hb_be_uint8_cmp_unaligned(a,b) (a[0] == b[0]) +#define hb_be_int8_put_unaligned hb_be_uint8_put_unaligned +#define hb_be_int8_get_unaligned (int8_t) hb_be_uint8_get_unaligned +#define hb_be_int8_cmp_unaligned hb_be_uint8_cmp_unaligned + +#define hb_be_uint16_put_unaligned(v,V) (v[0] = (V>>8), v[1] = (V), 0) +#define hb_be_uint16_get_unaligned(v) (uint16_t) ((v[0] << 8) + v[1]) +#define hb_be_uint16_cmp_unaligned(a,b) (a[0] == b[0] && a[1] == b[1]) +#define hb_be_int16_put_unaligned hb_be_uint16_put_unaligned +#define hb_be_int16_get_unaligned (int16_t) hb_be_uint16_get_unaligned +#define hb_be_int16_cmp_unaligned hb_be_uint16_cmp_unaligned + +#define hb_be_uint32_put_unaligned(v,V) (v[0] = (V>>24), v[1] = (V>>16), v[2] = (V>>8), v[3] = (V), 0) +#define hb_be_uint32_get_unaligned(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3]) +#define hb_be_uint32_cmp_unaligned(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) +#define hb_be_int32_put_unaligned hb_be_uint32_put_unaligned +#define hb_be_int32_get_unaligned (int32_t) hb_be_uint32_get_unaligned +#define hb_be_int32_cmp_unaligned hb_be_uint32_cmp_unaligned + + /* Basics */ #undef MIN