[set/map/vector] Make constructable, but not copy or assignable Disable copy/assign on them, as they shouldn't. Make constructor / destructor call init_shallow/fini_shallow, and make those idempotent. So, these three can be constructed on stack now and no init/fini call is needed. As such, hb_auto_t<> is not needed anymore. I'll remove that separately.
diff --git a/src/hb-map.hh b/src/hb-map.hh index b55e3a9..e5ca3f5 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh
@@ -44,6 +44,10 @@ 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 @@ 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 2071196..97ff291 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 @@ } 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 8995ae1..fe06add 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh
@@ -34,6 +34,10 @@ template <typename Type, unsigned int StaticSize=8> 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 @@ 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 @@ *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 74dd8ac..6f5d6aa 100644 --- a/src/hb.hh +++ b/src/hb.hh
@@ -339,6 +339,16 @@ #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<T1, T2>&); \ + void operator=(const TypeName<T1, T2>&) #define HB_NO_CREATE_COPY_ASSIGN(TypeName) \ TypeName(void); \ TypeName(const TypeName&); \ @@ -354,6 +364,8 @@ #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)