Move null pool to hb-private
diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index e173a5e..19c0618 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc
@@ -47,7 +47,7 @@ #include <stdio.h> #ifndef HB_NO_VISIBILITY -const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif void cbdt_callback (const uint8_t* data, unsigned int length, @@ -91,7 +91,7 @@ void colr_cpal_rendering (cairo_font_face_t *cairo_face, unsigned int upem, unsigned int num_glyphs, const OT::COLR *colr, const OT::CPAL *cpal) { - for (int i = 0; i < num_glyphs; ++i) + for (unsigned int i = 0; i < num_glyphs; ++i) { unsigned int first_layer_index, num_layers; if (colr->get_base_glyph_record (i, &first_layer_index, &num_layers)) @@ -171,7 +171,7 @@ { // Dump every glyph available on the font return; // disabled for now - for (int i = 0; i < num_glyphs; ++i) + for (unsigned int i = 0; i < num_glyphs; ++i) { cairo_text_extents_t extents; cairo_glyph_t glyph = {0};
diff --git a/src/dump-fon.cc b/src/dump-fon.cc index 1d18983..7e1fef6 100644 --- a/src/dump-fon.cc +++ b/src/dump-fon.cc
@@ -27,7 +27,7 @@ #include "hb-open-type-private.hh" #ifndef HB_NO_VISIBILITY -const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif template <typename Type, int Bytes> struct LEInt; @@ -344,7 +344,7 @@ { const NE_TYPEINFO& next = OT::StructAfter<NE_TYPEINFO> (*this); if (type_id == 0) - return OT::Null (NE_TYPEINFO); + return Null (NE_TYPEINFO); return next; } @@ -352,7 +352,7 @@ { if (idx < count) return resources[idx].get_font (base, shift); - return OT::Null (LE_FONTINFO16); + return Null (LE_FONTINFO16); } inline unsigned int get_count () const @@ -401,7 +401,7 @@ return_trace (false); const NE_TYPEINFO* n = &chain; - while (n != &OT::Null (NE_TYPEINFO) && c->check_struct (n) && n->get_type_id () != 0) + while (n != &Null (NE_TYPEINFO) && c->check_struct (n) && n->get_type_id () != 0) { if (n->get_type_id () == NE_TYPEINFO::FONT) return_trace (n->sanitize (c, base, alignmentShiftCount)); @@ -418,13 +418,13 @@ inline const NE_TYPEINFO& get_fonts_entry () const { const NE_TYPEINFO* n = &chain; - while (n != &OT::Null (NE_TYPEINFO) && n->get_type_id () != 0) + while (n != &Null (NE_TYPEINFO) && n->get_type_id () != 0) { if (n->get_type_id () == NE_TYPEINFO::FONT) return *n; n = &n->next(); } - return OT::Null (NE_TYPEINFO); + return Null (NE_TYPEINFO); } protected: @@ -447,7 +447,7 @@ inline const NE_RESOURCE_TABLE& get_resource_table () const { if (magic != 0x454E) // Only NE containers are support for now, NE == 0x454E - return OT::Null (NE_RESOURCE_TABLE); + return Null (NE_RESOURCE_TABLE); return this+rsrctab; }
diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 7bd6027..18743e3 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc
@@ -52,7 +52,7 @@ { if (blob) *blob = hb_blob_get_empty (); - return OT::Null(AAT::ankr); + return Null(AAT::ankr); } hb_ot_layout_t * layout = hb_ot_layout_from_face (face); const AAT::ankr& ankr = *(layout->ankr.get ()); @@ -68,7 +68,7 @@ { if (blob) *blob = hb_blob_get_empty (); - return OT::Null(AAT::kerx); + return Null(AAT::kerx); } hb_ot_layout_t * layout = hb_ot_layout_from_face (face); /* XXX this doesn't call set_num_glyphs on sanitizer. */ @@ -85,7 +85,7 @@ { if (blob) *blob = hb_blob_get_empty (); - return OT::Null(AAT::morx); + return Null(AAT::morx); } hb_ot_layout_t * layout = hb_ot_layout_from_face (face); /* XXX this doesn't call set_num_glyphs on sanitizer. */ @@ -102,7 +102,7 @@ { if (blob) *blob = hb_blob_get_empty (); - return OT::Null(AAT::trak); + return Null(AAT::trak); } hb_ot_layout_t * layout = hb_ot_layout_from_face (face); const AAT::trak& trak = *(layout->trak.get ());
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 1f22b18..68e0e41 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh
@@ -127,46 +127,6 @@ /* - * Null objects - */ - -/* Global nul-content Null pool. Enlarge as necessary. */ - -#define HB_NULL_POOL_SIZE 264 -static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE."); - -#ifdef HB_NO_VISIBILITY -static -#else -extern HB_INTERNAL -#endif -const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] -#ifdef HB_NO_VISIBILITY -= {} -#endif -; - -/* Generic nul-content Null objects. */ -template <typename Type> -static inline const Type& Null (void) { - static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); - return *CastP<Type> (_hb_NullPool); -} - -/* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ -#define DEFINE_NULL_DATA(Type, data) \ -static const char _Null##Type[sizeof (Type) + 1] = data; /* +1 is for nul-termination in data */ \ -template <> \ -/*static*/ inline const Type& Null<Type> (void) { \ - return *CastP<Type> (_Null##Type); \ -} /* The following line really exists such that we end in a place needing semicolon */ \ -static_assert (Type::min_size + 1 <= sizeof (_Null##Type), "Null pool too small. Enlarge.") - -/* Accessor macro. */ -#define Null(Type) Null<Type>() - - -/* * Dispatch */ @@ -726,7 +686,6 @@ public: DEFINE_SIZE_STATIC (4); }; -DEFINE_NULL_DATA (Tag, " "); /* Glyph index number, same as uint16 (length = 16 bits) */ typedef HBUINT16 GlyphID; @@ -738,7 +697,6 @@ struct Index : HBUINT16 { static const unsigned int NOT_FOUND_INDEX = 0xFFFFu; }; -DEFINE_NULL_DATA (Index, "\xff\xff"); /* Offset, Null offset = 0 */ template <typename Type> @@ -1236,7 +1194,7 @@ inline void fini (void) { - if (instance && instance != &OT::Null(T)) + if (instance && instance != &Null(T)) { instance->fini(); free (instance); @@ -1251,12 +1209,12 @@ { p = (T *) calloc (1, sizeof (T)); if (unlikely (!p)) - p = const_cast<T *> (&OT::Null(T)); + p = const_cast<T *> (&Null(T)); else p->init (face); if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p))) { - if (p != &OT::Null(T)) + if (p != &Null(T)) p->fini (); goto retry; }
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 83a0b51..caffda3 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh
@@ -682,7 +682,7 @@ if (subtable) symbol = true; } /* Meh. */ - if (!subtable) subtable = &OT::Null(OT::CmapSubtable); + if (!subtable) subtable = &Null(OT::CmapSubtable); /* UVS subtable. */ if (!subtable_uvs) @@ -692,7 +692,7 @@ subtable_uvs = &st->u.format14; } /* Meh. */ - if (!subtable_uvs) subtable_uvs = &OT::Null(OT::CmapSubtableFormat14); + if (!subtable_uvs) subtable_uvs = &Null(OT::CmapSubtableFormat14); this->uvs_table = subtable_uvs;
diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index ceebe0b..86171c6 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc
@@ -44,7 +44,7 @@ static inline const OT::COLR& _get_colr (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::COLR); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::COLR); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); return *(layout->colr.get ()); } @@ -52,7 +52,7 @@ static inline const OT::CPAL& _get_cpal (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::CPAL); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::CPAL); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); return *(layout->cpal.get ()); }
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index bd193f9..bec694e 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh
@@ -165,7 +165,6 @@ public: DEFINE_SIZE_STATIC (6); }; -DEFINE_NULL_DATA (RangeRecord, "\000\001"); struct IndexArray : ArrayOf<Index> @@ -225,7 +224,6 @@ public: DEFINE_SIZE_ARRAY (6, featureIndex); }; -DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); struct Script @@ -247,7 +245,16 @@ { return langSys.find_index (tag, index); } inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } - inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } + inline const LangSys& get_default_lang_sys (void) const + { + if (!defaultLangSys) + { + /* This is the ONLY place where our null data is not all zeros. + * So, return special data instead of using the null pool. */ + return *reinterpret_cast<const LangSys *> ("\0\0\xFF\xFF"); + } + return this+defaultLangSys; + } inline bool sanitize (hb_sanitize_context_t *c, const Record<Script>::sanitize_closure_t * = nullptr) const
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index f7e4964..5ee03dc 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc
@@ -47,7 +47,7 @@ #ifndef HB_NO_VISIBILITY -const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif @@ -102,7 +102,7 @@ * https://lists.freedesktop.org/archives/harfbuzz/2016-February/005489.html */ if (3 == layout->gdef->get_glyph_class (5)) - layout->gdef = &OT::Null(OT::GDEF); + layout->gdef = &Null(OT::GDEF); } else if (0 /* sha1sum:96eda93f7d33e79962451c6c39a6b51ee893ce8c tahoma.ttf from Windows 8 */ @@ -174,7 +174,7 @@ * https://bugzilla.mozilla.org/show_bug.cgi?id=1279693 * https://bugzilla.mozilla.org/show_bug.cgi?id=1279875 */ - layout->gdef = &OT::Null(OT::GDEF); + layout->gdef = &Null(OT::GDEF); } } @@ -226,7 +226,7 @@ // static inline const OT::BASE& // _get_base (hb_face_t *face) // { -// if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::BASE); +// if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::BASE); // hb_ot_layout_t * layout = hb_ot_layout_from_face (face); // return *(layout->base.get ()); // } @@ -234,19 +234,19 @@ static inline const OT::GDEF& _get_gdef (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GDEF); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GDEF); return *hb_ot_layout_from_face (face)->gdef; } static inline const OT::GSUB& _get_gsub (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GSUB); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GSUB); return *hb_ot_layout_from_face (face)->gsub; } static inline const OT::GPOS& _get_gpos (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GPOS); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::GPOS); return *hb_ot_layout_from_face (face)->gpos; } @@ -318,7 +318,7 @@ switch (table_tag) { case HB_OT_TAG_GSUB: return _get_gsub (face); case HB_OT_TAG_GPOS: return _get_gpos (face); - default: return OT::Null(OT::GSUBGPOS); + default: return Null(OT::GSUBGPOS); } } @@ -898,7 +898,7 @@ hb_bool_t hb_ot_layout_has_substitution (hb_face_t *face) { - return &_get_gsub (face) != &OT::Null(OT::GSUB); + return &_get_gsub (face) != &Null(OT::GSUB); } /** @@ -962,7 +962,7 @@ hb_bool_t hb_ot_layout_has_positioning (hb_face_t *face) { - return &_get_gpos (face) != &OT::Null(OT::GPOS); + return &_get_gpos (face) != &Null(OT::GPOS); } void @@ -1298,5 +1298,5 @@ // hb_bool_t // hb_ot_base_has_data (hb_face_t *face) // { -// return &_get_base (face) != &OT::Null(OT::BASE); +// return &_get_base (face) != &Null(OT::BASE); // }
diff --git a/src/hb-ot-math.cc b/src/hb-ot-math.cc index f82a073..1667a7d 100644 --- a/src/hb-ot-math.cc +++ b/src/hb-ot-math.cc
@@ -32,7 +32,7 @@ static inline const OT::MATH& _get_math (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::MATH); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::MATH); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); return *(layout->math.get ()); } @@ -55,7 +55,7 @@ hb_bool_t hb_ot_math_has_data (hb_face_t *face) { - return &_get_math (face) != &OT::Null(OT::MATH); + return &_get_math (face) != &Null(OT::MATH); } /**
diff --git a/src/hb-ot-var.cc b/src/hb-ot-var.cc index 90ba0bd..f0612a6 100644 --- a/src/hb-ot-var.cc +++ b/src/hb-ot-var.cc
@@ -39,14 +39,14 @@ static inline const OT::fvar& _get_fvar (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::fvar); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::fvar); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); return *(layout->fvar.get ()); } static inline const OT::avar& _get_avar (hb_face_t *face) { - if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::avar); + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return Null(OT::avar); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); return *(layout->avar.get ()); } @@ -65,7 +65,7 @@ hb_bool_t hb_ot_var_has_data (hb_face_t *face) { - return &_get_fvar (face) != &OT::Null(OT::fvar); + return &_get_fvar (face) != &Null(OT::fvar); } /**
diff --git a/src/hb-private.hh b/src/hb-private.hh index 21561ce..9e075a3 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh
@@ -1089,4 +1089,33 @@ #endif +/* + * Null objects + */ + +/* Global nul-content Null pool. Enlarge as necessary. */ + +#define HB_NULL_POOL_SIZE 264 +static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE."); + +#ifdef HB_NO_VISIBILITY +static +#else +extern HB_INTERNAL +#endif +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] +#ifdef HB_NO_VISIBILITY += {} +#endif +; + +/* Generic nul-content Null objects. */ +template <typename Type> +static inline const Type& Null (void) { + static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); + return *reinterpret_cast<const Type *> (_hb_NullPool); +} +#define Null(Type) Null<Type>() + + #endif /* HB_PRIVATE_HH */
diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 35fe0ef..6c3d759 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc
@@ -45,7 +45,7 @@ #if !defined(HB_NO_VISIBILITY) && !defined(HB_SUBSET_BUILTIN) -const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif @@ -91,7 +91,7 @@ hb_tag_t tag = TableType::tableTag; hb_bool_t result = false; - if (table != &OT::Null(TableType)) + if (table != &Null(TableType)) { result = table->subset(plan); } else {
diff --git a/src/main.cc b/src/main.cc index 935fa39..0436c85 100644 --- a/src/main.cc +++ b/src/main.cc
@@ -38,7 +38,7 @@ using namespace OT; #ifndef HB_NO_VISIBILITY -const void * const OT::_hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; +const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; #endif int