Cleanup ASSERT_SIZE_VAR

This commit is contained in:
Behdad Esfahbod 2010-05-10 16:38:32 -04:00
parent 99bf03459f
commit 569da92bc6
7 changed files with 49 additions and 39 deletions

View File

@ -45,6 +45,7 @@ struct OpenTypeFontFile;
struct OffsetTable; struct OffsetTable;
struct TTCHeader; struct TTCHeader;
typedef struct TableDirectory typedef struct TableDirectory
{ {
inline bool sanitize (hb_sanitize_context_t *context) { inline bool sanitize (hb_sanitize_context_t *context) {
@ -52,13 +53,13 @@ typedef struct TableDirectory
return context->check_struct (this); return context->check_struct (this);
} }
DEFINE_SIZE_STATIC (16);
Tag tag; /* 4-byte identifier. */ Tag tag; /* 4-byte identifier. */
CheckSum checkSum; /* CheckSum for this table. */ CheckSum checkSum; /* CheckSum for this table. */
ULONG offset; /* Offset from beginning of TrueType font ULONG offset; /* Offset from beginning of TrueType font
* file. */ * file. */
ULONG length; /* Length of this table. */ ULONG length; /* Length of this table. */
public:
DEFINE_SIZE_STATIC (16);
} OpenTypeTable; } OpenTypeTable;
typedef struct OffsetTable typedef struct OffsetTable
@ -110,8 +111,10 @@ typedef struct OffsetTable
USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */ USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */
USHORT rangeShift; /* NumTables x 16-searchRange. */ USHORT rangeShift; /* NumTables x 16-searchRange. */
TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */ TableDirectory tableDir[VAR]; /* TableDirectory entries. numTables items */
public:
DEFINE_SIZE_VAR (12, TableDirectory);
} OpenTypeFontFace; } OpenTypeFontFace;
ASSERT_SIZE_VAR (OffsetTable, 12, TableDirectory);
/* /*
* TrueType Collections * TrueType Collections

View File

@ -101,7 +101,7 @@ inline Type& StructAfter(TObject &X)
{ ASSERT_STATIC (sizeof (*this) == (size) + VAR0 * sizeof (_var_type)); } \ { ASSERT_STATIC (sizeof (*this) == (size) + VAR0 * sizeof (_var_type)); } \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
#define DEFINE_SIZE_VAR2(_type, size, _var_type1, _var_type2) \ #define DEFINE_SIZE_VAR2(size, _var_type1, _var_type2) \
inline void _size_assertion (void) const \ inline void _size_assertion (void) const \
{ ASSERT_STATIC (sizeof (*this) == (size) + VAR0 * sizeof (_var_type1) + VAR0 * sizeof (_var_type2)); } \ { ASSERT_STATIC (sizeof (*this) == (size) + VAR0 * sizeof (_var_type1) + VAR0 * sizeof (_var_type2)); } \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
@ -379,8 +379,10 @@ struct IntType
TRACE_SANITIZE (); TRACE_SANITIZE ();
return context->check_struct (this); return context->check_struct (this);
} }
private:
BEInt<Type, sizeof (Type)> v;
public:
DEFINE_SIZE_STATIC (sizeof (Type)); DEFINE_SIZE_STATIC (sizeof (Type));
private: BEInt<Type, sizeof (Type)> v;
}; };
typedef IntType<uint16_t> USHORT; /* 16-bit unsigned integer. */ typedef IntType<uint16_t> USHORT; /* 16-bit unsigned integer. */

View File

@ -57,12 +57,12 @@ struct Record
&& offset.sanitize (context, base); && offset.sanitize (context, base);
} }
DEFINE_SIZE_STATIC (6);
Tag tag; /* 4-byte Tag identifier */ Tag tag; /* 4-byte Tag identifier */
OffsetTo<Type> OffsetTo<Type>
offset; /* Offset from beginning of object holding offset; /* Offset from beginning of object holding
* the Record */ * the Record */
public:
DEFINE_SIZE_STATIC (6);
}; };
template <typename Type> template <typename Type>
@ -170,14 +170,14 @@ struct LangSys
&& featureIndex.sanitize (context); && featureIndex.sanitize (context);
} }
DEFINE_SIZE_STATIC (6);
Offset lookupOrder; /* = Null (reserved for an offset to a Offset lookupOrder; /* = Null (reserved for an offset to a
* reordering table) */ * reordering table) */
USHORT reqFeatureIndex;/* Index of a feature required for this USHORT reqFeatureIndex;/* Index of a feature required for this
* language system--if no required features * language system--if no required features
* = 0xFFFF */ * = 0xFFFF */
IndexArray featureIndex; /* Array of indices into the FeatureList */ IndexArray featureIndex; /* Array of indices into the FeatureList */
public:
DEFINE_SIZE_STATIC (6);
}; };
DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF");
@ -305,8 +305,9 @@ struct Lookup
USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets
* structure. This field is only present if bit * structure. This field is only present if bit
* UseMarkFilteringSet of lookup flags is set. */ * UseMarkFilteringSet of lookup flags is set. */
public:
DEFINE_SIZE_VAR (6, USHORT);
}; };
ASSERT_SIZE_VAR (Lookup, 6, USHORT);
typedef OffsetListOf<Lookup> LookupList; typedef OffsetListOf<Lookup> LookupList;
ASSERT_SIZE (LookupList, 2); ASSERT_SIZE (LookupList, 2);
@ -365,13 +366,13 @@ struct CoverageRangeRecord
return context->check_struct (this); return context->check_struct (this);
} }
DEFINE_SIZE_STATIC (6);
private: private:
GlyphID start; /* First GlyphID in the range */ GlyphID start; /* First GlyphID in the range */
GlyphID end; /* Last GlyphID in the range */ GlyphID end; /* Last GlyphID in the range */
USHORT startCoverageIndex; /* Coverage Index of first GlyphID in USHORT startCoverageIndex; /* Coverage Index of first GlyphID in
* range */ * range */
public:
DEFINE_SIZE_STATIC (6);
}; };
DEFINE_NULL_DATA (CoverageRangeRecord, "\000\001"); DEFINE_NULL_DATA (CoverageRangeRecord, "\000\001");
@ -486,12 +487,12 @@ struct ClassRangeRecord
return context->check_struct (this); return context->check_struct (this);
} }
DEFINE_SIZE_STATIC (6);
private: private:
GlyphID start; /* First GlyphID in the range */ GlyphID start; /* First GlyphID in the range */
GlyphID end; /* Last GlyphID in the range */ GlyphID end; /* Last GlyphID in the range */
USHORT classValue; /* Applied to all glyphs in the range */ USHORT classValue; /* Applied to all glyphs in the range */
public:
DEFINE_SIZE_STATIC (6);
}; };
DEFINE_NULL_DATA (ClassRangeRecord, "\000\001"); DEFINE_NULL_DATA (ClassRangeRecord, "\000\001");
@ -610,8 +611,9 @@ struct Device
* 3 Signed 8-bit value, 2 values per uint16 * 3 Signed 8-bit value, 2 values per uint16
*/ */
USHORT deltaValue[VAR]; /* Array of compressed data */ USHORT deltaValue[VAR]; /* Array of compressed data */
public:
DEFINE_SIZE_VAR (6, USHORT);
}; };
ASSERT_SIZE_VAR (Device, 6, USHORT);
#endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */

View File

@ -383,8 +383,9 @@ struct GDEF
* definitions--from beginning of GDEF * definitions--from beginning of GDEF
* header (may be NULL). Introduced * header (may be NULL). Introduced
* in version 00010002. */ * in version 00010002. */
public:
DEFINE_SIZE_VAR (12, OffsetTo<MarkGlyphSets>);
}; };
ASSERT_SIZE_VAR (GDEF, 12, OffsetTo<MarkGlyphSets>);
#endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */ #endif /* HB_OT_LAYOUT_GDEF_PRIVATE_HH */

View File

@ -41,7 +41,6 @@
typedef USHORT Value; typedef USHORT Value;
typedef Value ValueRecord[VAR0]; typedef Value ValueRecord[VAR0];
ASSERT_SIZE_VAR (ValueRecord, 0, Value);
struct ValueFormat : USHORT struct ValueFormat : USHORT
{ {
@ -360,8 +359,9 @@ struct AnchorMatrix
OffsetTo<Anchor> OffsetTo<Anchor>
matrix[VAR]; /* Matrix of offsets to Anchor tables-- matrix[VAR]; /* Matrix of offsets to Anchor tables--
* from beginning of AnchorMatrix table */ * from beginning of AnchorMatrix table */
public:
DEFINE_SIZE_VAR (2, OffsetTo<Anchor>);
}; };
ASSERT_SIZE_VAR (AnchorMatrix, 2, OffsetTo<Anchor>);
struct MarkRecord struct MarkRecord
@ -374,13 +374,13 @@ struct MarkRecord
&& markAnchor.sanitize (context, base); && markAnchor.sanitize (context, base);
} }
DEFINE_SIZE_STATIC (4);
private: private:
USHORT klass; /* Class defined for this mark */ USHORT klass; /* Class defined for this mark */
OffsetTo<Anchor> OffsetTo<Anchor>
markAnchor; /* Offset to Anchor table--from markAnchor; /* Offset to Anchor table--from
* beginning of MarkArray table */ * beginning of MarkArray table */
public:
DEFINE_SIZE_STATIC (4);
}; };
struct MarkArray struct MarkArray
@ -462,8 +462,9 @@ struct SinglePosFormat1
ValueRecord values; /* Defines positioning ValueRecord values; /* Defines positioning
* value(s)--applied to all glyphs in * value(s)--applied to all glyphs in
* the Coverage table */ * the Coverage table */
public:
DEFINE_SIZE_VAR (6, ValueRecord);
}; };
ASSERT_SIZE_VAR (SinglePosFormat1, 6, ValueRecord);
struct SinglePosFormat2 struct SinglePosFormat2
{ {
@ -505,8 +506,9 @@ struct SinglePosFormat2
USHORT valueCount; /* Number of ValueRecords */ USHORT valueCount; /* Number of ValueRecords */
ValueRecord values; /* Array of ValueRecords--positioning ValueRecord values; /* Array of ValueRecords--positioning
* values applied to glyphs */ * values applied to glyphs */
public:
DEFINE_SIZE_VAR (8, ValueRecord);
}; };
ASSERT_SIZE_VAR (SinglePosFormat2, 8, ValueRecord);
struct SinglePos struct SinglePos
{ {
@ -552,8 +554,9 @@ struct PairValueRecord
* Coverage table */ * Coverage table */
ValueRecord values; /* Positioning data for the first glyph ValueRecord values; /* Positioning data for the first glyph
* followed by for second glyph */ * followed by for second glyph */
public:
DEFINE_SIZE_VAR (2, ValueRecord);
}; };
ASSERT_SIZE_VAR (PairValueRecord, 2, ValueRecord);
struct PairSet struct PairSet
{ {
@ -572,8 +575,9 @@ struct PairSet
PairValueRecord PairValueRecord
array[VAR]; /* Array of PairValueRecords--ordered array[VAR]; /* Array of PairValueRecords--ordered
* by GlyphID of the second glyph */ * by GlyphID of the second glyph */
public:
DEFINE_SIZE_VAR (2, PairValueRecord);
}; };
ASSERT_SIZE_VAR (PairSet, 2, PairValueRecord);
struct PairPosFormat1 struct PairPosFormat1
{ {
@ -755,8 +759,9 @@ struct PairPosFormat2
ValueRecord values; /* Matrix of value pairs: ValueRecord values; /* Matrix of value pairs:
* class1-major, class2-minor, * class1-major, class2-minor,
* Each entry has value1 and value2 */ * Each entry has value1 and value2 */
public:
DEFINE_SIZE_VAR (16, ValueRecord);
}; };
ASSERT_SIZE_VAR (PairPosFormat2, 16, ValueRecord);
struct PairPos struct PairPos
{ {
@ -794,14 +799,15 @@ struct PairPos
struct EntryExitRecord struct EntryExitRecord
{ {
friend struct CursivePosFormat1;
inline bool sanitize (hb_sanitize_context_t *context, void *base) { inline bool sanitize (hb_sanitize_context_t *context, void *base) {
TRACE_SANITIZE (); TRACE_SANITIZE ();
return entryAnchor.sanitize (context, base) return entryAnchor.sanitize (context, base)
&& exitAnchor.sanitize (context, base); && exitAnchor.sanitize (context, base);
} }
DEFINE_SIZE_STATIC (4); private:
OffsetTo<Anchor> OffsetTo<Anchor>
entryAnchor; /* Offset to EntryAnchor table--from entryAnchor; /* Offset to EntryAnchor table--from
* beginning of CursivePos * beginning of CursivePos
@ -810,6 +816,8 @@ struct EntryExitRecord
exitAnchor; /* Offset to ExitAnchor table--from exitAnchor; /* Offset to ExitAnchor table--from
* beginning of CursivePos * beginning of CursivePos
* subtable--may be NULL */ * subtable--may be NULL */
public:
DEFINE_SIZE_STATIC (4);
}; };
struct CursivePosFormat1 struct CursivePosFormat1

View File

@ -177,12 +177,12 @@ struct LookupRecord
return context->check_struct (this); return context->check_struct (this);
} }
DEFINE_SIZE_STATIC (4);
USHORT sequenceIndex; /* Index into current glyph USHORT sequenceIndex; /* Index into current glyph
* sequence--first glyph = 0 */ * sequence--first glyph = 0 */
USHORT lookupListIndex; /* Lookup to apply to that USHORT lookupListIndex; /* Lookup to apply to that
* position--zero--based */ * position--zero--based */
public:
DEFINE_SIZE_STATIC (4);
}; };
static inline bool apply_lookup (hb_apply_context_t *context, static inline bool apply_lookup (hb_apply_context_t *context,
@ -302,8 +302,9 @@ struct Rule
* second glyph */ * second glyph */
LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */ * design order */
public:
DEFINE_SIZE_VAR2 (4, USHORT, LookupRecord);
}; };
ASSERT_SIZE_VAR2 (Rule, 4, USHORT, LookupRecord);
struct RuleSet struct RuleSet
{ {
@ -461,8 +462,9 @@ struct ContextFormat3
* table in glyph sequence order */ * table in glyph sequence order */
LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in
* design order */ * design order */
public:
DEFINE_SIZE_VAR2 (6, OffsetTo<Coverage>, LookupRecord);
}; };
ASSERT_SIZE_VAR2 (ContextFormat3, 6, OffsetTo<Coverage>, LookupRecord);
struct Context struct Context
{ {

View File

@ -85,14 +85,6 @@
#define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size)) #define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
/* Size signifying variable-sized array */
#define VAR 1
#define VAR0 (VAR+0)
#define ASSERT_SIZE_VAR(_type, _size, _var_type) \
ASSERT_STATIC (sizeof (_type) == (_size) + VAR0 * sizeof (_var_type))
#define ASSERT_SIZE_VAR2(_type, _size, _var_type1, _var_type2) \
ASSERT_STATIC (sizeof (_type) == (_size) + VAR0 * sizeof (_var_type1) + VAR0 * sizeof (_var_type2))
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _HB_BOOLEAN_EXPR(expr) \ #define _HB_BOOLEAN_EXPR(expr) \