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!
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index 6e545a6..ee45286 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -335,6 +335,8 @@
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 @@
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 @@
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 @@
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 @@
template <typename Type, typename LenType=HBUINT16>
struct BinSearchArrayOf : SortedArrayOf<Type, BinSearchHeader<LenType> > {};
+
struct VarSizedBinSearchHeader
{
@@ -782,6 +791,8 @@
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);
diff --git a/src/hb.hh b/src/hb.hh
index ea47429..e5bec50 100644
--- a/src/hb.hh
+++ b/src/hb.hh
@@ -366,6 +366,12 @@
#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>&)
/*