[pango] [HB] Fix unaligned access
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pango] [HB] Fix unaligned access
- Date: Thu, 6 Aug 2009 22:27:23 +0000 (UTC)
commit 374f30c9d62a0559d71bbd610b10249d049e7778
Author: Behdad Esfahbod <behdad behdad org>
Date: Thu Aug 6 18:24:55 2009 -0400
[HB] Fix unaligned access
pango/opentype/hb-open-type-private.hh | 20 +++++++++++++++++---
pango/opentype/hb-private.h | 22 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
---
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]