Make Array types uncopyable-unassignable

Finally!  Catches hard-to-find errors like this:

-    const SortedArrayOf<SVGDocumentIndexEntry> docs = this+svgDocEntries;
+    const SortedArrayOf<SVGDocumentIndexEntry> &docs = this+svgDocEntries;

We implement this for our array types.  This, in turn, trickles down
into all types that embed the arrays.  So, as long as we define all
open-ended structs in terms of Array types (all can be done using
UnsizedArrayOf), this achieves the goal of making uncopyable all
structs that are variable-sized.  Yay!
This commit is contained in:
Behdad Esfahbod 2018-10-29 11:25:35 -07:00
parent 31cc1f74b7
commit a256a92b3f
2 changed files with 17 additions and 0 deletions

View File

@ -335,6 +335,8 @@ static inline Type& operator + (Base &base, OffsetTo<Type, OffsetType, has_null>
template <typename Type>
struct UnsizedArrayOf
{
HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE (UnsizedArrayOf, Type);
inline const Type& operator [] (unsigned int i) const { return arrayZ[i]; }
inline Type& operator [] (unsigned int i) { return arrayZ[i]; }
@ -424,6 +426,8 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null>
template <typename Type, typename LenType=HBUINT16>
struct ArrayOf
{
HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType);
inline const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const
{
unsigned int count = len;
@ -589,6 +593,8 @@ struct OffsetListOf : OffsetArrayOf<Type>
template <typename Type, typename LenType=HBUINT16>
struct HeadlessArrayOf
{
HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType);
inline const Type& operator [] (unsigned int i) const
{
if (unlikely (i >= lenP1 || !i)) return Null(Type);
@ -653,6 +659,8 @@ struct HeadlessArrayOf
template <typename Type, typename LenType=HBUINT16>
struct ArrayOfM1
{
HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE2 (ArrayOfM1, Type, LenType);
inline const Type& operator [] (unsigned int i) const
{
if (unlikely (i > lenM1)) return Null(Type);
@ -757,6 +765,7 @@ struct BinSearchHeader
template <typename Type, typename LenType=HBUINT16>
struct BinSearchArrayOf : SortedArrayOf<Type, BinSearchHeader<LenType> > {};
struct VarSizedBinSearchHeader
{
@ -782,6 +791,8 @@ struct VarSizedBinSearchHeader
template <typename Type>
struct VarSizedBinSearchArrayOf
{
HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE (VarSizedBinSearchArrayOf, Type);
inline const Type& operator [] (unsigned int i) const
{
if (unlikely (i >= header.nUnits)) return Null(Type);

View File

@ -366,6 +366,12 @@ static_assert ((sizeof (hb_var_int_t) == 4), "");
#define HB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#define HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE(TypeName, T) \
TypeName(const TypeName<T>&); \
void operator=(const TypeName<T>&)
#define HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE2(TypeName, T1, T2) \
TypeName(const TypeName<T1, T2>&); \
void operator=(const TypeName<T1, T2>&)
/*