From 596e471aa5053d955fb5d5b5923088c8814469b1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 10 May 2010 18:47:48 -0400 Subject: [PATCH] Cleanup DEFINE_SIZE_VAR2 --- src/hb-open-type-private.hh | 18 +++++++++++------- src/hb-ot-layout-common-private.hh | 6 +++--- src/hb-ot-layout-gdef-private.hh | 4 ++-- src/hb-ot-layout-gpos-private.hh | 4 ++-- src/hb-ot-layout-gsub-private.hh | 2 +- src/hb-ot-layout-gsubgpos-private.hh | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 311f74b88..51947713f 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -81,13 +81,13 @@ inline Type& StructAfter(TObject &X) * Size checking */ -#define _DEFINE_SIZE_ASSERTION(_compare) \ +#define _DEFINE_SIZE_ASSERTION(_assertion) \ inline void _size_assertion (void) const \ - { ASSERT_STATIC ((sizeof (*this)) _compare); } + { ASSERT_STATIC (_assertion); } #define DEFINE_SIZE_STATIC(size) \ - _DEFINE_SIZE_ASSERTION (== (size)); \ + _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size)); \ static const unsigned int static_size = (size); \ static const unsigned int min_size = (size) @@ -95,16 +95,20 @@ inline Type& StructAfter(TObject &X) #define VAR 1 #define VAR0 (VAR+0) +#define DEFINE_SIZE_UNION(size, _member) \ + _DEFINE_SIZE_ASSERTION (this->u._member.static_size == (size)); \ + static const unsigned int min_size = (size) + #define DEFINE_SIZE_MIN(size) \ - _DEFINE_SIZE_ASSERTION (>= (size)); \ + _DEFINE_SIZE_ASSERTION (sizeof (*this) >= (size)); \ static const unsigned int min_size = (size) #define DEFINE_SIZE_VAR(size, _var_type) \ - _DEFINE_SIZE_ASSERTION (== (size) + VAR0 * sizeof (_var_type)); \ + _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + VAR0 * sizeof (_var_type)); \ static const unsigned int min_size = (size) -#define DEFINE_SIZE_VAR2(size, _var_type1, _var_type2) \ - _DEFINE_SIZE_ASSERTION (== (size) + VAR0 * sizeof (_var_type1) + VAR0 * sizeof (_var_type2)); \ +#define DEFINE_SIZE_VAR2(size, array1, array2) \ + _DEFINE_SIZE_ASSERTION (sizeof (*this) == (size) + this->array1[0].static_size + this->array2[0].static_size); \ static const unsigned int min_size = (size) diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 6542e5f8c..d0ab1d136 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -307,7 +307,7 @@ struct Lookup * structure. This field is only present if bit * UseMarkFilteringSet of lookup flags is set. */ public: - DEFINE_SIZE_VAR2 (6, Offset, USHORT); + DEFINE_SIZE_VAR2 (6, subTable, markFilteringSetX); }; typedef OffsetListOf LookupList; @@ -440,7 +440,7 @@ struct Coverage CoverageFormat2 format2[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; @@ -562,7 +562,7 @@ struct ClassDef ClassDefFormat2 format2[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; diff --git a/src/hb-ot-layout-gdef-private.hh b/src/hb-ot-layout-gdef-private.hh index 456efcaf1..85782b07a 100644 --- a/src/hb-ot-layout-gdef-private.hh +++ b/src/hb-ot-layout-gdef-private.hh @@ -196,7 +196,7 @@ struct CaretValue CaretValueFormat3 format3[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; struct LigGlyph @@ -312,7 +312,7 @@ struct MarkGlyphSets MarkGlyphSetsFormat1 format1[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index a84210ad6..5a29c0a79 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -336,7 +336,7 @@ struct Anchor AnchorFormat3 format3[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; @@ -1490,7 +1490,7 @@ struct PosLookupSubTable ExtensionPos extension[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index 707ee61d8..25e2b3a6a 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -759,7 +759,7 @@ struct SubstLookupSubTable ReverseChainSingleSubst reverseChainContextSingle[VAR]; } u; public: - DEFINE_SIZE_MIN (2); + DEFINE_SIZE_UNION (2, format); }; diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index b3af2de20..0814e2151 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -303,7 +303,7 @@ struct Rule LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in * design order */ public: - DEFINE_SIZE_VAR2 (4, USHORT, LookupRecord); + DEFINE_SIZE_VAR2 (4, input, lookupRecordX); }; struct RuleSet @@ -467,7 +467,7 @@ struct ContextFormat3 LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in * design order */ public: - DEFINE_SIZE_VAR2 (6, OffsetTo, LookupRecord); + DEFINE_SIZE_VAR2 (6, coverage, lookupRecordX); }; struct Context