diff --git a/src/hb-map.hh b/src/hb-map.hh index b55e3a954..e5ca3f515 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -44,6 +44,10 @@ inline uint32_t Hash (const T &v) struct hb_map_t { + HB_NO_COPY_ASSIGN (hb_map_t); + inline hb_map_t (void) { init_shallow (); } + inline ~hb_map_t (void) { fini_shallow (); } + struct item_t { hb_codepoint_t key; @@ -77,9 +81,11 @@ struct hb_map_t inline void fini_shallow (void) { free (items); + items = nullptr; } inline void fini (void) { + population = occupancy = 0; hb_object_fini (this); fini_shallow (); } diff --git a/src/hb-set.hh b/src/hb-set.hh index 2071196bc..97ff291eb 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -39,6 +39,10 @@ struct hb_set_t { + HB_NO_COPY_ASSIGN (hb_set_t); + inline hb_set_t (void) { init_shallow (); } + inline ~hb_set_t (void) { fini_shallow (); } + struct page_map_t { inline int cmp (const page_map_t *o) const { return (int) o->major - (int) major; } @@ -199,6 +203,7 @@ struct hb_set_t } inline void fini_shallow (void) { + population = 0; page_map.fini (); pages.fini (); } diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 8995ae104..fe06addf7 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -34,6 +34,10 @@ template struct hb_vector_t { + HB_NO_COPY_ASSIGN_TEMPLATE2 (hb_vector_t, Type, StaticSize); + inline hb_vector_t (void) { init (); } + inline ~hb_vector_t (void) { fini (); } + unsigned int len; private: unsigned int allocated; /* == 0 means allocation failed. */ @@ -48,6 +52,22 @@ struct hb_vector_t arrayZ_ = nullptr; } + inline void fini (void) + { + if (arrayZ_) + free (arrayZ_); + arrayZ_ = nullptr; + allocated = len = 0; + } + inline void fini_deep (void) + { + Type *array = arrayZ(); + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + array[i].fini (); + fini (); + } + inline Type * arrayZ (void) { return arrayZ_ ? arrayZ_ : static_array; } inline const Type * arrayZ (void) const @@ -255,23 +275,6 @@ struct hb_vector_t *i = max; return false; } - - inline void fini_deep (void) - { - Type *array = arrayZ(); - unsigned int count = len; - for (unsigned int i = 0; i < count; i++) - array[i].fini (); - fini (); - } - - inline void fini (void) - { - if (arrayZ_) - free (arrayZ_); - arrayZ_ = nullptr; - allocated = len = 0; - } }; diff --git a/src/hb.hh b/src/hb.hh index 74dd8ace0..6f5d6aab2 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -339,6 +339,16 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); #if __cplusplus >= 201103L +/* We only enable these with C++11 or later, since earlier language + * does not allow structs with constructors in unions, and we need + * those. */ + +#define HB_NO_COPY_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) +#define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) #define HB_NO_CREATE_COPY_ASSIGN(TypeName) \ TypeName(void); \ TypeName(const TypeName&); \ @@ -354,6 +364,8 @@ static_assert ((sizeof (hb_var_int_t) == 4), ""); #else /* __cpluspplus >= 201103L */ +#define HB_NO_COPY_ASSIGN(TypeName) +#define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) #define HB_NO_CREATE_COPY_ASSIGN(TypeName) #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T) #define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2)