From a256a92b3fbb72487cf073a63e646eab952b42ed Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 29 Oct 2018 11:25:35 -0700 Subject: [PATCH] Make Array types uncopyable-unassignable Finally! Catches hard-to-find errors like this: - const SortedArrayOf docs = this+svgDocEntries; + const SortedArrayOf &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! --- src/hb-open-type.hh | 11 +++++++++++ src/hb.hh | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 6e545a6d3..ee452864d 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -335,6 +335,8 @@ static inline Type& operator + (Base &base, OffsetTo template 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 template 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 template 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 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 struct BinSearchArrayOf : SortedArrayOf > {}; + struct VarSizedBinSearchHeader { @@ -782,6 +791,8 @@ struct VarSizedBinSearchHeader template 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); diff --git a/src/hb.hh b/src/hb.hh index ea474298f..e5bec5087 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -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&); \ + void operator=(const TypeName&) +#define HB_DISALLOW_COPY_AND_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) /*