Better fix for MSVC 2008

Follow up on b4c6113032

Fixes https://github.com/harfbuzz/harfbuzz/issues/1374
This commit is contained in:
Behdad Esfahbod 2018-11-10 19:54:08 -05:00
parent b4c6113032
commit 1d66cdcf77
5 changed files with 20 additions and 13 deletions

View File

@ -110,17 +110,17 @@ static inline Type& StructAfter(TObject &X)
static const unsigned int min_size = (size) static const unsigned int min_size = (size)
#define DEFINE_SIZE_ARRAY(size, array) \ #define DEFINE_SIZE_ARRAY(size, array) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * sizeof (array[0])); \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + VAR * (array).item_size); \
DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \ DEFINE_COMPILES_ASSERTION ((void) (array)[0].static_size) \
enum { min_size = (size) } enum { min_size = (size) }
#define DEFINE_SIZE_ARRAY_SIZED(size, array) \ #define DEFINE_SIZE_ARRAY_SIZED(size, array) \
inline unsigned int get_size (void) const { return (size - array.min_size + array.get_size ()); } \ inline unsigned int get_size (void) const { return (size - (array).min_size + (array).get_size ()); } \
DEFINE_SIZE_ARRAY(size, array) DEFINE_SIZE_ARRAY(size, array)
#define DEFINE_SIZE_ARRAY2(size, array1, array2) \ #define DEFINE_SIZE_ARRAY2(size, array1, array2) \
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \ DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \
DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \ DEFINE_COMPILES_ASSERTION ((void) (array1)[0].static_size; (void) (array2)[0].static_size) \
static const unsigned int min_size = (size) static const unsigned int min_size = (size)

View File

@ -335,6 +335,8 @@ static inline Type& operator + (Base &base, OffsetTo<Type, OffsetType, has_null>
template <typename Type> template <typename Type>
struct UnsizedArrayOf struct UnsizedArrayOf
{ {
enum { item_size = Type::static_size };
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type); HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type);
/* Unlikely other places, use "int i" instead of "unsigned int i" for our /* Unlikely other places, use "int i" instead of "unsigned int i" for our
@ -435,6 +437,8 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null>
template <typename Type, typename LenType=HBUINT16> template <typename Type, typename LenType=HBUINT16>
struct ArrayOf struct ArrayOf
{ {
enum { item_size = Type::static_size };
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType); HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType);
inline const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const inline const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const
@ -603,6 +607,8 @@ struct OffsetListOf : OffsetArrayOf<Type>
template <typename Type, typename LenType=HBUINT16> template <typename Type, typename LenType=HBUINT16>
struct HeadlessArrayOf struct HeadlessArrayOf
{ {
enum { item_size = Type::static_size };
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType); HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType);
inline const Type& operator [] (unsigned int i) const inline const Type& operator [] (unsigned int i) const
@ -801,6 +807,8 @@ struct VarSizedBinSearchHeader
template <typename Type> template <typename Type>
struct VarSizedBinSearchArrayOf struct VarSizedBinSearchArrayOf
{ {
enum { item_size = Type::static_size };
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type); HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type);
inline const Type& operator [] (unsigned int i) const inline const Type& operator [] (unsigned int i) const

View File

@ -636,7 +636,7 @@ struct DefaultUVS : SortedArrayOf<UnicodeValueRange, HBUINT32>
} }
public: public:
DEFINE_SIZE_ARRAY (4, arrayZ); DEFINE_SIZE_ARRAY (4, *this);
}; };
struct UVSMapping struct UVSMapping
@ -668,7 +668,7 @@ struct NonDefaultUVS : SortedArrayOf<UVSMapping, HBUINT32>
} }
public: public:
DEFINE_SIZE_ARRAY (4, arrayZ); DEFINE_SIZE_ARRAY (4, *this);
}; };
struct VariationSelectorRecord struct VariationSelectorRecord

View File

@ -53,7 +53,7 @@ enum attach_type_t {
typedef HBUINT16 Value; typedef HBUINT16 Value;
typedef Value ValueRecord[VAR]; typedef UnsizedArrayOf<Value> ValueRecord;
struct ValueFormat : HBUINT16 struct ValueFormat : HBUINT16
{ {
@ -879,7 +879,7 @@ struct PairPosFormat2
unsigned int stride = len1 + len2; unsigned int stride = len1 + len2;
unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size (); unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count; unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
return_trace (c->check_array (values, count, record_size) && return_trace (c->check_array ((const void *) values, count, record_size) &&
valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) && valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride)); valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
} }

View File

@ -94,7 +94,7 @@ struct SegmentMaps : ArrayOf<AxisValueMap>
} }
public: public:
DEFINE_SIZE_ARRAY (2, arrayZ); DEFINE_SIZE_ARRAY (2, *this);
}; };
struct avar struct avar
@ -109,7 +109,7 @@ struct avar
c->check_struct (this)))) c->check_struct (this))))
return_trace (false); return_trace (false);
const SegmentMaps *map = axisSegmentMapsZ.arrayZ; const SegmentMaps *map = &firstAxisSegmentMaps;
unsigned int count = axisCount; unsigned int count = axisCount;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
@ -125,7 +125,7 @@ struct avar
{ {
unsigned int count = MIN<unsigned int> (coords_length, axisCount); unsigned int count = MIN<unsigned int> (coords_length, axisCount);
const SegmentMaps *map = axisSegmentMapsZ.arrayZ; const SegmentMaps *map = &firstAxisSegmentMaps;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
coords[i] = map->map (coords[i]); coords[i] = map->map (coords[i]);
@ -140,8 +140,7 @@ struct avar
HBUINT16 axisCount; /* The number of variation axes in the font. This HBUINT16 axisCount; /* The number of variation axes in the font. This
* must be the same number as axisCount in the * must be the same number as axisCount in the
* 'fvar' table. */ * 'fvar' table. */
UnsizedArrayOf<SegmentMaps> SegmentMaps firstAxisSegmentMaps;
axisSegmentMapsZ;
public: public:
DEFINE_SIZE_MIN (8); DEFINE_SIZE_MIN (8);