diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index e173a5eef..19c061833 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -47,7 +47,7 @@ #include #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 svg_callback (const uint8_t* data, unsigned int length, 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 @@ void dump_glyphs (cairo_font_face_t *cairo_face, unsigned int upem, unsigned int { // 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 1d18983ce..7e1fef618 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 struct LEInt; @@ -344,7 +344,7 @@ struct NE_TYPEINFO { const NE_TYPEINFO& next = OT::StructAfter (*this); if (type_id == 0) - return OT::Null (NE_TYPEINFO); + return Null (NE_TYPEINFO); return next; } @@ -352,7 +352,7 @@ struct NE_TYPEINFO { 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 @@ struct NE_RESOURCE_TABLE 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 @@ struct NE_RESOURCE_TABLE 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 @@ struct LE_IMAGE_OS2_HEADER 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 7bd60272d..18743e3cd 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -52,7 +52,7 @@ _get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr) { 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 @@ _get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr) { 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 @@ _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr) { 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 @@ _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr) { 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 1f22b1825..68e0e410d 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -126,46 +126,6 @@ static inline Type& StructAfter(TObject &X) -/* - * 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 -static inline const Type& Null (void) { - static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); - return *CastP (_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 (void) { \ - return *CastP (_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() - - /* * Dispatch */ @@ -726,7 +686,6 @@ struct Tag : HBUINT32 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 @@ typedef HBUINT16 NameID; struct Index : HBUINT16 { static const unsigned int NOT_FOUND_INDEX = 0xFFFFu; }; -DEFINE_NULL_DATA (Index, "\xff\xff"); /* Offset, Null offset = 0 */ template @@ -1236,7 +1194,7 @@ struct hb_lazy_loader_t inline void fini (void) { - if (instance && instance != &OT::Null(T)) + if (instance && instance != &Null(T)) { instance->fini(); free (instance); @@ -1251,12 +1209,12 @@ struct hb_lazy_loader_t { p = (T *) calloc (1, sizeof (T)); if (unlikely (!p)) - p = const_cast (&OT::Null(T)); + p = const_cast (&Null(T)); else p->init (face); if (unlikely (!hb_atomic_ptr_cmpexch (const_cast(&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 83a0b519b..caffda352 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -682,7 +682,7 @@ struct cmap 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 @@ struct cmap 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 ceebe0b7a..86171c633 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -44,7 +44,7 @@ HB_MARK_AS_FLAG_T (hb_ot_color_palette_flags_t) 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 @@ _get_colr (hb_face_t *face) 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 bd193f9dc..bec694e18 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -165,7 +165,6 @@ struct RangeRecord public: DEFINE_SIZE_STATIC (6); }; -DEFINE_NULL_DATA (RangeRecord, "\000\001"); struct IndexArray : ArrayOf @@ -225,7 +224,6 @@ struct LangSys public: DEFINE_SIZE_ARRAY (6, featureIndex); }; -DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); struct Script @@ -247,7 +245,16 @@ struct Script { 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 ("\0\0\xFF\xFF"); + } + return this+defaultLangSys; + } inline bool sanitize (hb_sanitize_context_t *c, const Record