From 52ab3d508ad900cc435aa6529cd4a333db43af78 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Apr 2010 02:27:56 -0400 Subject: [HB] Fix debug build --- pango/opentype/hb-open-type-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 06324ee3..77c5dfe4 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -124,7 +124,7 @@ struct Null \ HB_STMT_START { \ if (sanitize_depth < HB_DEBUG_SANITIZE) \ fprintf (stderr, "SANITIZE(%p) %-*d-> %s\n", \ - (CONST_CHARP (this) == NullPool) ? 0 : this, \ + (CONST_CHARP (this) == CONST_CHARP (&NullPool)) ? 0 : this, \ sanitize_depth, sanitize_depth, \ __PRETTY_FUNCTION__); \ } HB_STMT_END -- cgit v1.2.1 From 5383831f1c73eaed7696fddad3e2fb823858a8ff Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 19 Apr 2010 02:29:04 -0400 Subject: [HB] Fix warnings --- pango/opentype/hb-open-type-private.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 77c5dfe4..98d46bd9 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -117,7 +117,7 @@ struct Null \ #endif #if HB_DEBUG_SANITIZE -#define TRACE_SANITIZE_ARG_DEF , unsigned int sanitize_depth +#define TRACE_SANITIZE_ARG_DEF , unsigned int sanitize_depth HB_GNUC_UNUSED #define TRACE_SANITIZE_ARG , sanitize_depth + 1 #define TRACE_SANITIZE_ARG_INIT , 1 #define TRACE_SANITIZE() \ -- cgit v1.2.1 From fc23518fc6fb391a0e7dc872c6a2e89a09cad018 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 15:25:27 -0400 Subject: [HB] Remove ASSERT_SIZE_DATA --- pango/opentype/hb-open-type-private.hh | 4 ---- 1 file changed, 4 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 98d46bd9..e146a2d3 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -84,10 +84,6 @@ struct Null \ #define Null(Type) (Null::get()) -#define ASSERT_SIZE_DATA(Type, size, data) \ - ASSERT_SIZE (Type, size); \ - DEFINE_NULL_DATA (Type, size, data) - /* get_for_data() is a static class method returning a reference to an * instance of Type located at the input data location. It's just a * fancy, NULL-safe, cast! */ -- cgit v1.2.1 From 851f873072b26b32c514c459ba2ca141dd1b79e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 15:51:53 -0400 Subject: [HB] Add couple consts to operators --- pango/opentype/hb-open-type-private.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index e146a2d3..ea6ba5b4 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007,2008,2009 Red Hat, Inc. + * Copyright (C) 2007,2008,2009,2010 Red Hat, Inc. * * This is part of HarfBuzz, an OpenType Layout engine library. * @@ -346,7 +346,7 @@ struct Sanitizer { \ inline NAME& set (TYPE i) { (TYPE&) v = BIG_ENDIAN (i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN ((TYPE&) v); } \ - inline bool operator== (NAME o) const { return (TYPE&) v == (TYPE&) o.v; } \ + inline bool operator== (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -361,7 +361,7 @@ struct Sanitizer static inline unsigned int get_size () { return BYTES; } \ inline NAME& set (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 operator== (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ -- cgit v1.2.1 From b11755c2f68d0dfe1dac7a7bce29defa25255bc9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Apr 2010 23:50:45 -0400 Subject: [HB] Cosmetic --- pango/opentype/hb-open-type-private.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index ea6ba5b4..590b0d98 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -346,7 +346,7 @@ struct Sanitizer { \ inline NAME& set (TYPE i) { (TYPE&) v = BIG_ENDIAN (i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN ((TYPE&) v); } \ - inline bool operator== (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ + inline bool operator == (const NAME &o) const { return (TYPE&) v == (TYPE&) o.v; } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -361,7 +361,7 @@ struct Sanitizer static inline unsigned int get_size () { return BYTES; } \ inline NAME& set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ - inline bool operator== (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ + inline bool operator == (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ TRACE_SANITIZE (); \ return SANITIZE_SELF (); \ @@ -386,7 +386,7 @@ struct Tag : ULONG inline Tag (const Tag &o) { *(ULONG*)this = (ULONG&) o; } inline Tag (uint32_t i) { (*(ULONG*)this).set (i); } inline Tag (const char *c) { *(ULONG*)this = *(ULONG*)c; } - inline bool operator== (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } + inline bool operator == (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ inline operator const char* (void) const { return CONST_CHARP(this); } inline operator char* (void) { return CHARP(this); } @@ -459,7 +459,7 @@ ASSERT_SIZE (FixedVersion, 4); template struct GenericOffsetTo : OffsetType { - inline const Type& operator() (const void *base) const + inline const Type& operator () (const void *base) const { unsigned int offset = *this; if (HB_UNLIKELY (!offset)) return Null(Type); -- cgit v1.2.1 From 39620ce42fa212d4e76f49ac257d2b2cf6da20fa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:14:12 -0400 Subject: [HB] Simplify Tag struct --- pango/opentype/hb-open-type-private.hh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 590b0d98..4dbff0dc 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -359,7 +359,7 @@ struct Sanitizer struct NAME \ { \ static inline unsigned int get_size () { return BYTES; } \ - inline NAME& set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); return *this; } \ + inline void set (TYPE i) { BIG_ENDIAN##_put_unaligned(v, i); } \ inline operator TYPE(void) const { return BIG_ENDIAN##_get_unaligned (v); } \ inline bool operator == (const NAME &o) const { return BIG_ENDIAN##_cmp_unaligned (v, o.v); } \ inline bool sanitize (SANITIZE_ARG_DEF) { \ @@ -383,10 +383,6 @@ DEFINE_INT_TYPE (LONG, , 32); /* 32-bit signed integer. */ * system, feature, or baseline */ struct Tag : ULONG { - inline Tag (const Tag &o) { *(ULONG*)this = (ULONG&) o; } - inline Tag (uint32_t i) { (*(ULONG*)this).set (i); } - inline Tag (const char *c) { *(ULONG*)this = *(ULONG*)c; } - inline bool operator == (const char *c) const { return *(ULONG*)this == *(ULONG*)c; } /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ inline operator const char* (void) const { return CONST_CHARP(this); } inline operator char* (void) { return CHARP(this); } -- cgit v1.2.1 From 9091e0f4d59b4f6dec4b0992f86ddcc141c0b919 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:32:47 -0400 Subject: [HB] Use a function template instead of struct template for Null --- pango/opentype/hb-open-type-private.hh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 4dbff0dc..832d2ad1 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -61,27 +61,25 @@ /* Null objects */ /* Global nul-content Null pool. Enlarge as necessary. */ -static const void *NullPool[32 / sizeof (void *)]; +static const void *_NullPool[32 / sizeof (void *)]; /* Generic template for nul-content sizeof-sized Null objects. */ template -struct Null -{ - ASSERT_STATIC (sizeof (Type) <= sizeof (NullPool)); - static inline const Type &get () { return CONST_CAST (Type, *NullPool, 0); } -}; +static inline const Type& Null () { + ASSERT_STATIC (sizeof (Type) <= sizeof (_NullPool)); + return CONST_CAST (Type, *_NullPool, 0); +} /* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ #define DEFINE_NULL_DATA(Type, size, data) \ -static const char _Null##Type[size] = data; \ +static const char _Null##Type[size + 1] = data; \ template <> \ -struct Null \ -{ \ - static inline const Type &get () { return CONST_CAST (Type, *_Null##Type, 0); } \ +inline const Type& Null () { \ + return CONST_CAST (Type, *_Null##Type, 0); \ } /* Accessor macro. */ -#define Null(Type) (Null::get()) +#define Null(Type) Null() /* get_for_data() is a static class method returning a reference to an @@ -397,9 +395,7 @@ struct Tag : ULONG } }; ASSERT_SIZE (Tag, 4); -#define _NULL_TAG_INIT {' ', ' ', ' ', ' '} -DEFINE_NULL_DATA (Tag, 4, _NULL_TAG_INIT); -#undef _NULL_TAG_INIT +DEFINE_NULL_DATA (Tag, 4, " "); /* Glyph index number, same as uint16 (length = 16 bits) */ typedef USHORT GlyphID; -- cgit v1.2.1 From 4eca6bc0c98b573cc28005413e40790af8b10930 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:40:50 -0400 Subject: [HB] Remove stale TODO item --- pango/opentype/hb-open-type-private.hh | 1 - 1 file changed, 1 deletion(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 832d2ad1..994f6d8d 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -247,7 +247,6 @@ _hb_sanitize_edit (SANITIZE_ARG_DEF, #define SANITIZE_OBJ(X) SANITIZE_MEM(&(X), sizeof (X)) #define SANITIZE_GET_SIZE() SANITIZE_SELF() && SANITIZE_MEM (this, this->get_size ()) -/* TODO Optimize this if L is fixed (gcc magic) */ #define SANITIZE_MEM(B,L) HB_LIKELY (_hb_sanitize_check (SANITIZE_ARG, CONST_CHARP(B), (L))) #define SANITIZE_ARRAY(A,S,L) HB_LIKELY (_hb_sanitize_array (SANITIZE_ARG, CONST_CHARP(A), S, L)) -- cgit v1.2.1 From 140cfe4b4a40f95a379c1b78881b1edf12f72145 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Apr 2010 00:49:40 -0400 Subject: [HB] Improve comments --- pango/opentype/hb-open-type-private.hh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'pango/opentype/hb-open-type-private.hh') diff --git a/pango/opentype/hb-open-type-private.hh b/pango/opentype/hb-open-type-private.hh index 994f6d8d..9e99175a 100644 --- a/pango/opentype/hb-open-type-private.hh +++ b/pango/opentype/hb-open-type-private.hh @@ -510,11 +510,14 @@ struct GenericArrayOf inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); if (!SANITIZE_GET_SIZE()) return false; - /* Note: - * for non-recursive types, this is not much needed. - * But we keep the code to make sure the objects pointed to - * do have a simple sanitize(). */ + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size, hence the return. + */ return true; + /* We do keep this code though to make sure the structs pointed + * to do have a simple sanitize(), ie. they do not reference + * other structs. */ unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (!SANITIZE (array()[i])) @@ -613,11 +616,14 @@ struct HeadlessArrayOf inline bool sanitize (SANITIZE_ARG_DEF) { TRACE_SANITIZE (); if (!SANITIZE_GET_SIZE()) return false; - /* Note: - * for non-recursive types, this is not much needed. - * But we keep the code to make sure the objects pointed to - * do have a simple sanitize(). */ + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size, hence the return. + */ return true; + /* We do keep this code though to make sure the structs pointed + * to do have a simple sanitize(), ie. they do not reference + * other structs. */ unsigned int count = len ? len - 1 : 0; Type *a = array(); for (unsigned int i = 0; i < count; i++) -- cgit v1.2.1