Remove ASSERT_SIZE in favor of the safer DEFINE_SIZE_STATIC
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 10 May 2010 20:57:29 +0000 (16:57 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 10 May 2010 20:59:57 +0000 (16:59 -0400)
src/hb-open-file-private.hh
src/hb-open-type-private.hh
src/hb-ot-layout-common-private.hh
src/hb-ot-layout-gdef-private.hh
src/hb-ot-layout-gpos-private.hh
src/hb-ot-layout-gsub-private.hh
src/hb-ot-layout-gsubgpos-private.hh
src/hb-private.h

index 53e947a..d8d70e5 100644 (file)
@@ -139,8 +139,9 @@ struct TTCHeaderVersion1
   LongOffsetLongArrayOf<OffsetTable>
                table;          /* Array of offsets to the OffsetTable for each font
                                 * from the beginning of the file */
+  public:
+  DEFINE_SIZE_STATIC (12);
 };
-ASSERT_SIZE (TTCHeaderVersion1, 12);
 
 struct TTCHeader
 {
index aab85fd..56a8bae 100644 (file)
@@ -96,6 +96,15 @@ inline Type& StructAfter(TObject &X)
   static const unsigned int static_size = (size); \
   static const unsigned int min_size = (size)
 
+/* Size signifying variable-sized array */
+#define VAR 1
+#define VAR0 (VAR+0)
+
+#define DEFINE_SIZE_VAR0(size) \
+  inline void _size_assertion (void) const \
+  { ASSERT_STATIC (sizeof (*this) == (size)); } \
+  static const unsigned int min_size = (size)
+
 #define DEFINE_SIZE_VAR(size, _var_type) \
   inline void _size_assertion (void) const \
   { ASSERT_STATIC (sizeof (*this) == (size) + VAR0 * sizeof (_var_type)); } \
@@ -397,8 +406,9 @@ struct Tag : ULONG
   /* What the char* converters return is NOT nul-terminated.  Print using "%.4s" */
   inline operator const char* (void) const { return CharP(this); }
   inline operator char* (void) { return CharP(this); }
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (Tag, 4);
 DEFINE_NULL_DATA (Tag, "    ");
 
 /* Glyph index number, same as uint16 (length = 16 bits) */
@@ -423,8 +433,9 @@ struct CheckSum : ULONG
       Sum += *Table++;
     return Sum;
   }
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (CheckSum, 4);
 
 
 /*
@@ -442,8 +453,9 @@ struct FixedVersion
 
   USHORT major;
   USHORT minor;
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (FixedVersion, 4);
 
 
 
@@ -577,6 +589,8 @@ struct GenericArrayOf
   public:
   LenType len;
 /*Type array[VAR];*/
+  public:
+  DEFINE_SIZE_VAR0 (sizeof (LenType));
 };
 
 /* An array with a USHORT number of elements. */
index 7215415..dc1229f 100644 (file)
@@ -216,11 +216,11 @@ struct Script
   RecordArrayOf<LangSys>
                langSys;        /* Array of LangSysRecords--listed
                                 * alphabetically by LangSysTag */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (Script, 4);
 
 typedef RecordListOf<Script> ScriptList;
-ASSERT_SIZE (ScriptList, 2);
 
 
 struct Feature
@@ -247,11 +247,11 @@ struct Feature
                                 * to the beginning of the Feature Table; = Null
                                 * if not required */
   IndexArray    lookupIndex;   /* Array of LookupList indices */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (Feature, 4);
 
 typedef RecordListOf<Feature> FeatureList;
-ASSERT_SIZE (FeatureList, 2);
 
 
 struct LookupFlag : USHORT
@@ -266,8 +266,9 @@ struct LookupFlag : USHORT
     Reserved           = 0x00E0u,
     MarkAttachmentType = 0xFF00u
   };
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (LookupFlag, 2);
 
 struct Lookup
 {
@@ -310,7 +311,6 @@ struct Lookup
 };
 
 typedef OffsetListOf<Lookup> LookupList;
-ASSERT_SIZE (LookupList, 2);
 
 
 /*
@@ -345,8 +345,9 @@ struct CoverageFormat1
   USHORT       coverageFormat; /* Format identifier--format = 1 */
   ArrayOf<GlyphID>
                glyphArray;     /* Array of GlyphIDs--in numerical order */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (CoverageFormat1, 4);
 
 struct CoverageRangeRecord
 {
@@ -405,8 +406,9 @@ struct CoverageFormat2
                rangeRecord;    /* Array of glyph ranges--ordered by
                                 * Start GlyphID. rangeCount entries
                                 * long */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (CoverageFormat2, 4);
 
 struct Coverage
 {
@@ -466,8 +468,9 @@ struct ClassDefFormat1
   GlyphID      startGlyph;             /* First GlyphID of the classValueArray */
   ArrayOf<USHORT>
                classValue;             /* Array of Class Values--one per GlyphID */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (ClassDefFormat1, 6);
 
 struct ClassRangeRecord
 {
@@ -523,8 +526,9 @@ struct ClassDefFormat2
   ArrayOf<ClassRangeRecord>
                rangeRecord;    /* Array of glyph ranges--ordered by
                                 * Start GlyphID */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (ClassDefFormat2, 4);
 
 struct ClassDef
 {
index e6cf7b8..4e06673 100644 (file)
@@ -38,7 +38,6 @@
 
 typedef ArrayOf<USHORT> AttachPoint;   /* Array of contour point indices--in
                                         * increasing numerical order */
-ASSERT_SIZE (AttachPoint, 2);
 
 struct AttachList
 {
@@ -80,8 +79,9 @@ struct AttachList
   OffsetArrayOf<AttachPoint>
                attachPoint;            /* Array of AttachPoint tables
                                         * in Coverage Index order */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (AttachList, 4);
 
 /*
  * Ligature Caret Table
@@ -106,8 +106,9 @@ struct CaretValueFormat1
   private:
   USHORT       caretValueFormat;       /* Format identifier--format = 1 */
   SHORT                coordinate;             /* X or Y value, in design units */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (CaretValueFormat1, 4);
 
 struct CaretValueFormat2
 {
@@ -132,8 +133,9 @@ struct CaretValueFormat2
   private:
   USHORT       caretValueFormat;       /* Format identifier--format = 2 */
   USHORT       caretValuePoint;        /* Contour point index on glyph */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (CaretValueFormat2, 4);
 
 struct CaretValueFormat3
 {
@@ -159,8 +161,9 @@ struct CaretValueFormat3
                deviceTable;            /* Offset to Device table for X or Y
                                         * value--from beginning of CaretValue
                                         * table */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (CaretValueFormat3, 6);
 
 struct CaretValue
 {
@@ -222,8 +225,9 @@ struct LigGlyph
                carets;                 /* Offset array of CaretValue tables
                                         * --from beginning of LigGlyph table
                                         * --in increasing coordinate order */
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (LigGlyph, 2);
 
 struct LigCaretList
 {
@@ -257,8 +261,9 @@ struct LigCaretList
   OffsetArrayOf<LigGlyph>
                ligGlyph;               /* Array of LigGlyph tables
                                         * in Coverage Index order */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (LigCaretList, 4);
 
 
 struct MarkGlyphSetsFormat1
@@ -276,8 +281,9 @@ struct MarkGlyphSetsFormat1
   LongOffsetArrayOf<Coverage>
                coverage;               /* Array of long offsets to mark set
                                         * coverage tables */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (MarkGlyphSetsFormat1, 4);
 
 struct MarkGlyphSets
 {
index eb53ac1..65e26eb 100644 (file)
@@ -202,7 +202,6 @@ struct ValueFormat : USHORT
     return true;
   }
 };
-ASSERT_SIZE (ValueFormat, 2);
 
 
 struct AnchorFormat1
@@ -226,8 +225,9 @@ struct AnchorFormat1
   USHORT       format;                 /* Format identifier--format = 1 */
   SHORT                xCoordinate;            /* Horizontal value--in design units */
   SHORT                yCoordinate;            /* Vertical value--in design units */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (AnchorFormat1, 6);
 
 struct AnchorFormat2
 {
@@ -258,8 +258,9 @@ struct AnchorFormat2
   SHORT                xCoordinate;            /* Horizontal value--in design units */
   SHORT                yCoordinate;            /* Vertical value--in design units */
   USHORT       anchorPoint;            /* Index to glyph contour point */
+  public:
+  DEFINE_SIZE_STATIC (8);
 };
-ASSERT_SIZE (AnchorFormat2, 8);
 
 struct AnchorFormat3
 {
@@ -298,8 +299,9 @@ struct AnchorFormat3
                yDeviceTable;           /* Offset to Device table for Y
                                         * coordinate-- from beginning of
                                         * Anchor table (may be NULL) */
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (AnchorFormat3, 10);
 
 struct Anchor
 {
@@ -421,8 +423,9 @@ struct MarkArray
   private:
   ArrayOf<MarkRecord>
                markRecord;     /* Array of MarkRecords--in Coverage order */
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (MarkArray, 2);
 
 
 /* Lookups */
@@ -669,8 +672,9 @@ struct PairPosFormat1
   OffsetArrayOf<PairSet>
                pairSet;                /* Array of PairSet tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (PairPosFormat1, 10);
 
 struct PairPosFormat2
 {
@@ -1014,8 +1018,9 @@ struct CursivePosFormat1
   ArrayOf<EntryExitRecord>
                entryExitRecord;        /* Array of EntryExit records--in
                                         * Coverage Index order */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (CursivePosFormat1, 6);
 
 struct CursivePos
 {
@@ -1075,11 +1080,9 @@ struct MarkBasePosFormat1
       j--;
     } while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property));
 
-#if 0
-    /* The following assertion is too strong. */
-    if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
+    /* The following assertion is too strong, so we've disabled it. */
+    if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH))
       return false;
-#endif
 
     unsigned int base_index = (this+baseCoverage) (IN_GLYPH (j));
     if (base_index == NOT_COVERED)
@@ -1112,8 +1115,9 @@ struct MarkBasePosFormat1
   OffsetTo<BaseArray>
                baseArray;              /* Offset to BaseArray table--from
                                         * beginning of MarkBasePos subtable */
+  public:
+  DEFINE_SIZE_STATIC (12);
 };
-ASSERT_SIZE (MarkBasePosFormat1, 12);
 
 struct MarkBasePos
 {
@@ -1178,11 +1182,9 @@ struct MarkLigPosFormat1
       j--;
     } while (_hb_ot_layout_skip_mark (context->layout->face, IN_INFO (j), LookupFlag::IgnoreMarks, &property));
 
-#if 0
-    /* The following assertion is too strong. */
-    if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
+    /* The following assertion is too strong, so we've disabled it. */
+    if (false && !(property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE))
       return false;
-#endif
 
     unsigned int lig_index = (this+ligatureCoverage) (IN_GLYPH (j));
     if (lig_index == NOT_COVERED)
@@ -1237,8 +1239,9 @@ struct MarkLigPosFormat1
   OffsetTo<LigatureArray>
                ligatureArray;          /* Offset to LigatureArray table--from
                                         * beginning of MarkLigPos subtable */
+  public:
+  DEFINE_SIZE_STATIC (12);
 };
-ASSERT_SIZE (MarkLigPosFormat1, 12);
 
 struct MarkLigPos
 {
@@ -1341,8 +1344,9 @@ struct MarkMarkPosFormat1
   OffsetTo<Mark2Array>
                mark2Array;             /* Offset to Mark2Array table--from
                                         * beginning of MarkMarkPos subtable */
+  public:
+  DEFINE_SIZE_STATIC (12);
 };
-ASSERT_SIZE (MarkMarkPosFormat1, 12);
 
 struct MarkMarkPos
 {
@@ -1567,7 +1571,6 @@ struct PosLookup : Lookup
 };
 
 typedef OffsetListOf<PosLookup> PosLookupList;
-ASSERT_SIZE (PosLookupList, 2);
 
 /*
  * GPOS
@@ -1592,8 +1595,9 @@ struct GPOS : GSUBGPOS
     OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList);
     return list.sanitize (context, this);
   }
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (GPOS, 10);
 
 
 /* Out-of-class implementation for methods recursing */
index 5585409..4a464b6 100644 (file)
@@ -71,8 +71,9 @@ struct SingleSubstFormat1
                                         * beginning of Substitution table */
   SHORT                deltaGlyphID;           /* Add to original GlyphID to get
                                         * substitute GlyphID */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (SingleSubstFormat1, 6);
 
 struct SingleSubstFormat2
 {
@@ -115,8 +116,9 @@ struct SingleSubstFormat2
   ArrayOf<GlyphID>
                substitute;             /* Array of substitute
                                         * GlyphIDs--ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (SingleSubstFormat2, 6);
 
 struct SingleSubst
 {
@@ -192,8 +194,9 @@ struct Sequence
   private:
   ArrayOf<GlyphID>
                substitute;             /* String of GlyphIDs to substitute */
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (Sequence, 2);
 
 struct MultipleSubstFormat1
 {
@@ -226,8 +229,9 @@ struct MultipleSubstFormat1
   OffsetArrayOf<Sequence>
                sequence;               /* Array of Sequence tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (MultipleSubstFormat1, 6);
 
 struct MultipleSubst
 {
@@ -263,7 +267,6 @@ struct MultipleSubst
 
 typedef ArrayOf<GlyphID> AlternateSet; /* Array of alternate GlyphIDs--in
                                         * arbitrary order */
-ASSERT_SIZE (AlternateSet, 2);
 
 struct AlternateSubstFormat1
 {
@@ -322,8 +325,9 @@ struct AlternateSubstFormat1
   OffsetArrayOf<AlternateSet>
                alternateSet;           /* Array of AlternateSet tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (AlternateSubstFormat1, 6);
 
 struct AlternateSubst
 {
@@ -438,8 +442,9 @@ struct Ligature
                component;              /* Array of component GlyphIDs--start
                                         * with the second  component--ordered
                                         * in writing direction */
+  public:
+  DEFINE_SIZE_STATIC (4);
 };
-ASSERT_SIZE (Ligature, 4);
 
 struct LigatureSet
 {
@@ -470,8 +475,9 @@ struct LigatureSet
   OffsetArrayOf<Ligature>
                ligature;               /* Array LigatureSet tables
                                         * ordered by preference */
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (LigatureSet, 2);
 
 struct LigatureSubstFormat1
 {
@@ -507,8 +513,9 @@ struct LigatureSubstFormat1
   OffsetArrayOf<LigatureSet>
                ligatureSet;            /* Array LigatureSet tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (LigatureSubstFormat1, 6);
 
 struct LigatureSubst
 {
@@ -652,8 +659,9 @@ struct ReverseChainSingleSubstFormat1
   ArrayOf<GlyphID>
                substituteX;            /* Array of substitute
                                         * GlyphIDs--ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (ReverseChainSingleSubstFormat1, 10);
 
 struct ReverseChainSingleSubst
 {
@@ -865,7 +873,6 @@ struct SubstLookup : Lookup
 };
 
 typedef OffsetListOf<SubstLookup> SubstLookupList;
-ASSERT_SIZE (SubstLookupList, 2);
 
 /*
  * GSUB
@@ -890,8 +897,9 @@ struct GSUB : GSUBGPOS
     OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList);
     return list.sanitize (context, this);
   }
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (GSUB, 10);
 
 
 /* Out-of-class implementation for methods recursing */
index 0b59748..86285d1 100644 (file)
@@ -367,8 +367,9 @@ struct ContextFormat1
   OffsetArrayOf<RuleSet>
                ruleSet;                /* Array of RuleSet tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (ContextFormat1, 6);
 
 
 struct ContextFormat2
@@ -414,8 +415,9 @@ struct ContextFormat2
   OffsetArrayOf<RuleSet>
                ruleSet;                /* Array of RuleSet tables
                                         * ordered by class */
+  public:
+  DEFINE_SIZE_STATIC (8);
 };
-ASSERT_SIZE (ContextFormat2, 8);
 
 
 struct ContextFormat3
@@ -590,8 +592,9 @@ struct ChainRule
   ArrayOf<LookupRecord>
                lookupX;                /* Array of LookupRecords--in
                                         * design order) */
+  public:
+  DEFINE_SIZE_STATIC (8);
 };
-ASSERT_SIZE (ChainRule, 8);
 
 struct ChainRuleSet
 {
@@ -617,8 +620,9 @@ struct ChainRuleSet
   OffsetArrayOf<ChainRule>
                rule;                   /* Array of ChainRule tables
                                         * ordered by preference */
+  public:
+  DEFINE_SIZE_STATIC (2);
 };
-ASSERT_SIZE (ChainRuleSet, 2);
 
 struct ChainContextFormat1
 {
@@ -654,8 +658,9 @@ struct ChainContextFormat1
   OffsetArrayOf<ChainRuleSet>
                ruleSet;                /* Array of ChainRuleSet tables
                                         * ordered by Coverage Index */
+  public:
+  DEFINE_SIZE_STATIC (6);
 };
-ASSERT_SIZE (ChainContextFormat1, 6);
 
 struct ChainContextFormat2
 {
@@ -716,8 +721,9 @@ struct ChainContextFormat2
   OffsetArrayOf<ChainRuleSet>
                ruleSet;                /* Array of ChainRuleSet tables
                                         * ordered by class */
+  public:
+  DEFINE_SIZE_STATIC (12);
 };
-ASSERT_SIZE (ChainContextFormat2, 12);
 
 struct ChainContextFormat3
 {
@@ -777,8 +783,9 @@ struct ChainContextFormat3
   ArrayOf<LookupRecord>
                lookupX;                /* Array of LookupRecords--in
                                         * design order) */
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (ChainContextFormat3, 10);
 
 struct ChainContext
 {
@@ -835,8 +842,9 @@ struct ExtensionFormat1
                                         * extension subtable). */
   ULONG                extensionOffset;        /* Offset to the extension subtable,
                                         * of lookup type subtable. */
+  public:
+  DEFINE_SIZE_STATIC (8);
 };
-ASSERT_SIZE (ExtensionFormat1, 8);
 
 struct Extension
 {
@@ -929,8 +937,9 @@ struct GSUBGPOS
                featureList;    /* FeatureList table */
   OffsetTo<LookupList>
                lookupList;     /* LookupList table */
+  public:
+  DEFINE_SIZE_STATIC (10);
 };
-ASSERT_SIZE (GSUBGPOS, 10);
 
 
 #endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */
index 3f8515b..8a323de 100644 (file)
@@ -83,8 +83,6 @@
 
 /* Misc */
 
-#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
-
 
 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
 #define _HB_BOOLEAN_EXPR(expr) \