src/dump-emoji.cc | 10 ++--- src/dump-fon.cc | 17 ++++----- src/hb-aat-layout.cc | 12 +++---- src/hb-blob-private.hh | 11 ++++++ src/hb-face.cc | 9 ++--- src/hb-object-private.hh | 36 ++++++++++++++++----- src/hb-open-type-private.hh | 63 +++++-------------------------------- src/hb-ot-cmap-table.hh | 6 +-- src/hb-ot-color-cbdt-table.hh | 4 +- src/hb-ot-color-sbix-table.hh | 2 - src/hb-ot-color-svg-table.hh | 2 - src/hb-ot-color.cc | 4 +- src/hb-ot-glyf-table.hh | 6 +-- src/hb-ot-hmtx-table.hh | 8 ++-- src/hb-ot-kern-table.hh | 2 - src/hb-ot-layout-common-private.hh | 13 +++++-- src/hb-ot-layout.cc | 28 ++++++++-------- src/hb-ot-math.cc | 4 +- src/hb-ot-post-table.hh | 18 +++++----- src/hb-ot-var.cc | 6 +-- src/hb-private.hh | 43 +++++++++++++++++++++---- src/hb-string-array.hh | 6 +-- src/hb-subset.cc | 6 +-- src/main.cc | 4 +- 24 files changed, 172 insertions(+), 148 deletions(-)
New commits: commit eba1c16a604d1be774f22541bf3e417f27a27c68 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 02:47:42 2018 -0700 Always lock blob in sanitize. Remove blob->lock_as() in favor of blob->lock() diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index 47c6c98b..63af4a6a 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -240,11 +240,11 @@ int main (int argc, char **argv) OT::Sanitizer<OT::COLR> sanitizerCOLR; hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR)); - const OT::COLR *colr = colr_blob->lock_as<OT::COLR> (); + const OT::COLR *colr = colr_blob->as<OT::COLR> (); OT::Sanitizer<OT::CPAL> sanitizerCPAL; hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL)); - const OT::CPAL *cpal = cpal_blob->lock_as<OT::CPAL> (); + const OT::CPAL *cpal = cpal_blob->as<OT::CPAL> (); cairo_font_face_t *cairo_face; { diff --git a/src/dump-fon.cc b/src/dump-fon.cc index dc45d9c4..81525f42 100644 --- a/src/dump-fon.cc +++ b/src/dump-fon.cc @@ -542,7 +542,7 @@ int main (int argc, char** argv) { OT::Sanitizer<LE_IMAGE_DOS_HEADER> sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const LE_IMAGE_DOS_HEADER* dos_header = font_blob->lock_as<LE_IMAGE_DOS_HEADER> (); + const LE_IMAGE_DOS_HEADER* dos_header = font_blob->as<LE_IMAGE_DOS_HEADER> (); const NE_RESOURCE_TABLE &rtable = dos_header->get_os2_header ().get_resource_table (); int shift = rtable.get_shift_value (); diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index e6efaab4..7784fae3 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -118,11 +118,11 @@ _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr) // OT::Sanitizer<AAT::morx> sanitizer; // sanitizer.set_num_glyphs (face->get_num_glyphs ()); // hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx)); -// morx_blob->lock_as<AAT::morx> (); +// morx_blob->as<AAT::morx> (); // if (0) // { -// morx_blob->lock_as<AAT::Lookup<OT::GlyphID> > ()->get_value (1, face->get_num_glyphs ()); +// morx_blob->as<AAT::Lookup<OT::GlyphID> > ()->get_value (1, face->get_num_glyphs ()); // } // } diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh index f564351a..b72fa721 100644 --- a/src/hb-blob-private.hh +++ b/src/hb-blob-private.hh @@ -69,12 +69,6 @@ struct hb_blob_t { return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data); } - template <typename Type> - inline const Type* lock_as (void) - { - lock (); - return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data); - } public: hb_object_header_t header; diff --git a/src/hb-face.cc b/src/hb-face.cc index 9fc40d48..01271413 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -135,7 +135,7 @@ _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void if (tag == HB_TAG_NONE) return hb_blob_reference (data->blob); - const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> (); + const OT::OpenTypeFontFile &ot_file = *data->blob->as<OT::OpenTypeFontFile> (); const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag); @@ -426,7 +426,7 @@ void hb_face_t::load_upem (void) const { hb_blob_t *head_blob = OT::Sanitizer<OT::head>().sanitize (reference_table (HB_OT_TAG_head)); - const OT::head *head_table = head_blob->lock_as<OT::head> (); + const OT::head *head_table = head_blob->as<OT::head> (); upem = head_table->get_upem (); hb_blob_destroy (head_blob); } @@ -470,7 +470,7 @@ void hb_face_t::load_num_glyphs (void) const { hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (reference_table (HB_OT_TAG_maxp)); - const OT::maxp *maxp_table = maxp_blob->lock_as<OT::maxp> (); + const OT::maxp *maxp_table = maxp_blob->as<OT::maxp> (); num_glyphs = maxp_table->get_num_glyphs (); hb_blob_destroy (maxp_blob); } @@ -500,7 +500,7 @@ hb_face_get_table_tags (hb_face_t *face, hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data; - const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> (); + const OT::OpenTypeFontFile &ot_file = *data->blob->as<OT::OpenTypeFontFile> (); const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); return ot_face.get_table_tags (start_offset, table_count, table_tags); diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 9f07b3f5..8bc74169 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -344,8 +344,12 @@ struct Sanitizer DEBUG_MSG_FUNC (SANITIZE, c->start, sane ? "PASSED" : "FAILED"); if (sane) + { + blob->lock (); return blob; - else { + } + else + { hb_blob_destroy (blob); return hb_blob_get_empty (); } @@ -1250,7 +1254,7 @@ struct hb_lazy_table_loader_t if (unlikely (!p)) { hb_blob_t *blob_ = OT::Sanitizer<T>().sanitize (face->reference_table (T::tableTag)); - p = const_cast<T *>(blob_->lock_as<T> ()); + p = const_cast<T *>(blob_->as<T> ()); if (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p)) { hb_blob_destroy (blob_); diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 438063e0..950a0ee1 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -661,7 +661,7 @@ struct cmap inline void init (hb_face_t *face) { this->blob = OT::Sanitizer<OT::cmap>().sanitize (face->reference_table (HB_OT_TAG_cmap)); - const OT::cmap *cmap = this->blob->lock_as<OT::cmap> (); + const OT::cmap *cmap = this->blob->as<OT::cmap> (); const OT::CmapSubtable *subtable = nullptr; const OT::CmapSubtableFormat14 *subtable_uvs = nullptr; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 52364ff7..f4207f2d 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -403,8 +403,8 @@ struct CBDT cbdt = nullptr; return; /* Not a bitmap font. */ } - cblc = cblc_blob->lock_as<CBLC> (); - cbdt = cbdt_blob->lock_as<CBDT> (); + cblc = cblc_blob->as<CBLC> (); + cbdt = cbdt_blob->as<CBDT> (); } diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 17d6c730..09a9517c 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -102,7 +102,7 @@ struct sbix sanitizer.set_num_glyphs (num_glyphs); sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix)); sbix_len = hb_blob_get_length (sbix_blob); - sbix_table = sbix_blob->lock_as<OT::sbix> (); + sbix_table = sbix_blob->as<OT::sbix> (); } diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index ccf4b9c4..ed6cf970 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -99,7 +99,7 @@ struct SVG OT::Sanitizer<OT::SVG> sanitizer; svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG)); svg_len = hb_blob_get_length (svg_blob); - svg = svg_blob->lock_as<OT::SVG> (); + svg = svg_blob->as<OT::SVG> (); } diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 07169687..8c2bfd09 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -237,7 +237,7 @@ struct glyf memset (this, 0, sizeof (accelerator_t)); hb_blob_t *head_blob = Sanitizer<head>().sanitize (face->reference_table (HB_OT_TAG_head)); - const head *head_table = head_blob->lock_as<head> (); + const head *head_table = head_blob->as<head> (); if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0) { /* head table is not present, or in an unknown format. Leave num_glyphs=0, that takes care of disabling us. */ @@ -248,9 +248,9 @@ struct glyf hb_blob_destroy (head_blob); loca_blob = Sanitizer<loca>().sanitize (face->reference_table (HB_OT_TAG_loca)); - loca_table = loca_blob->lock_as<loca> (); + loca_table = loca_blob->as<loca> (); glyf_blob = Sanitizer<glyf>().sanitize (face->reference_table (HB_OT_TAG_glyf)); - glyf_table = glyf_blob->lock_as<glyf> (); + glyf_table = glyf_blob->as<glyf> (); num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1; glyf_len = hb_blob_get_length (glyf_blob); diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 02419a88..c07763e6 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -196,7 +196,7 @@ struct hmtxvmtx if (T::os2Tag) { hb_blob_t *os2_blob = Sanitizer<os2> ().sanitize (face->reference_table (T::os2Tag)); - const os2 *os2_table = os2_blob->lock_as<os2> (); + const os2 *os2_table = os2_blob->as<os2> (); #define USE_TYPO_METRICS (1u<<7) if (0 != (os2_table->fsSelection & USE_TYPO_METRICS)) { @@ -209,7 +209,7 @@ struct hmtxvmtx } hb_blob_t *_hea_blob = Sanitizer<H> ().sanitize (face->reference_table (H::tableTag)); - const H *_hea_table = _hea_blob->lock_as<H> (); + const H *_hea_table = _hea_blob->as<H> (); num_advances = _hea_table->numberOfLongMetrics; if (!got_font_extents) { @@ -238,10 +238,10 @@ struct hmtxvmtx hb_blob_destroy (blob); blob = hb_blob_get_empty (); } - table = blob->lock_as<hmtxvmtx> (); + table = blob->as<hmtxvmtx> (); var_blob = Sanitizer<HVARVVAR> ().sanitize (face->reference_table (T::variationsTag)); - var_table = var_blob->lock_as<HVARVVAR> (); + var_table = var_blob->as<HVARVVAR> (); } inline void fini (void) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 71b368a8..9366dbf4 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -363,7 +363,7 @@ struct kern inline void init (hb_face_t *face) { blob = Sanitizer<kern>().sanitize (face->reference_table (HB_OT_TAG_kern)); - table = blob->lock_as<kern> (); + table = blob->as<kern> (); table_length = hb_blob_get_length (blob); } inline void fini (void) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index a4673fc5..d5efde29 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -59,13 +59,13 @@ _hb_ot_layout_create (hb_face_t *face) return nullptr; layout->gdef_blob = OT::Sanitizer<OT::GDEF>().sanitize (face->reference_table (HB_OT_TAG_GDEF)); - layout->gdef = layout->gdef_blob->lock_as<OT::GDEF> (); + layout->gdef = layout->gdef_blob->as<OT::GDEF> (); layout->gsub_blob = OT::Sanitizer<OT::GSUB>().sanitize (face->reference_table (HB_OT_TAG_GSUB)); - layout->gsub = layout->gsub_blob->lock_as<OT::GSUB> (); + layout->gsub = layout->gsub_blob->as<OT::GSUB> (); layout->gpos_blob = OT::Sanitizer<OT::GPOS>().sanitize (face->reference_table (HB_OT_TAG_GPOS)); - layout->gpos = layout->gpos_blob->lock_as<OT::GPOS> (); + layout->gpos = layout->gpos_blob->as<OT::GPOS> (); layout->math.init (face); layout->fvar.init (face); diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index d1793d35..bb5f9b31 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -110,7 +110,7 @@ struct post inline void init (hb_face_t *face) { blob = Sanitizer<post>().sanitize (face->reference_table (HB_OT_TAG_post)); - const post *table = blob->lock_as<post> (); + const post *table = blob->as<post> (); unsigned int table_length = hb_blob_get_length (blob); version = table->version.to_int (); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index bca56770..d6295a48 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -87,7 +87,7 @@ _subset (hb_subset_plan_t *plan) OT::Sanitizer<TableType> sanitizer; hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag)); - const TableType *table = source_blob->lock_as<TableType> (); + const TableType *table = source_blob->as<TableType> (); hb_tag_t tag = TableType::tableTag; hb_bool_t result = false; diff --git a/src/main.cc b/src/main.cc index 2976c895..9a187366 100644 --- a/src/main.cc +++ b/src/main.cc @@ -56,7 +56,7 @@ main (int argc, char **argv) Sanitizer<OpenTypeFontFile> sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const OpenTypeFontFile* sanitized = font_blob->lock_as<OpenTypeFontFile> (); + const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> (); if (sanitized == &Null (OpenTypeFontFile)) { printf ("Sanitization of the file wasn't successful. Exit"); commit b4fa50501414b7471e840f2ee6b9dfe87080b078 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 02:45:08 2018 -0700 Move Sanitizer::lock_instance<>() to blob->lock_as<>(). diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index 19c06183..47c6c98b 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -240,11 +240,11 @@ int main (int argc, char **argv) OT::Sanitizer<OT::COLR> sanitizerCOLR; hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR)); - const OT::COLR *colr = OT::Sanitizer<OT::COLR>::lock_instance (colr_blob); + const OT::COLR *colr = colr_blob->lock_as<OT::COLR> (); OT::Sanitizer<OT::CPAL> sanitizerCPAL; hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL)); - const OT::CPAL *cpal = OT::Sanitizer<OT::CPAL>::lock_instance (cpal_blob); + const OT::CPAL *cpal = cpal_blob->lock_as<OT::CPAL> (); cairo_font_face_t *cairo_face; { diff --git a/src/dump-fon.cc b/src/dump-fon.cc index 7e1fef61..dc45d9c4 100644 --- a/src/dump-fon.cc +++ b/src/dump-fon.cc @@ -542,8 +542,7 @@ int main (int argc, char** argv) { OT::Sanitizer<LE_IMAGE_DOS_HEADER> sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const LE_IMAGE_DOS_HEADER* dos_header = - OT::Sanitizer<LE_IMAGE_DOS_HEADER>::lock_instance (font_blob); + const LE_IMAGE_DOS_HEADER* dos_header = font_blob->lock_as<LE_IMAGE_DOS_HEADER> (); const NE_RESOURCE_TABLE &rtable = dos_header->get_os2_header ().get_resource_table (); int shift = rtable.get_shift_value (); diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 18743e3c..e6efaab4 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -118,11 +118,11 @@ _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr) // OT::Sanitizer<AAT::morx> sanitizer; // sanitizer.set_num_glyphs (face->get_num_glyphs ()); // hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx)); -// OT::Sanitizer<AAT::morx>::lock_instance (morx_blob); +// morx_blob->lock_as<AAT::morx> (); // if (0) // { -// OT::Sanitizer<AAT::Lookup<OT::GlyphID> >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ()); +// morx_blob->lock_as<AAT::Lookup<OT::GlyphID> > ()->get_value (1, face->get_num_glyphs ()); // } // } diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh index 0d567c28..f564351a 100644 --- a/src/hb-blob-private.hh +++ b/src/hb-blob-private.hh @@ -59,6 +59,23 @@ struct hb_blob_t HB_INTERNAL bool try_make_writable_inplace (void); HB_INTERNAL bool try_make_writable_inplace_unix (void); + inline void lock (void) + { + hb_blob_make_immutable (this); + } + + template <typename Type> + inline const Type* as (void) const + { + return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data); + } + template <typename Type> + inline const Type* lock_as (void) + { + lock (); + return unlikely (!data) ? &Null(Type) : reinterpret_cast<const Type *> (data); + } + public: hb_object_header_t header; ASSERT_POD (); diff --git a/src/hb-face.cc b/src/hb-face.cc index d8af8c1f..9fc40d48 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -29,6 +29,7 @@ #include "hb-private.hh" #include "hb-face-private.hh" +#include "hb-blob-private.hh" #include "hb-open-file-private.hh" #include "hb-ot-head-table.hh" #include "hb-ot-maxp-table.hh" @@ -134,7 +135,7 @@ _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void if (tag == HB_TAG_NONE) return hb_blob_reference (data->blob); - const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob); + const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> (); const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag); @@ -425,7 +426,7 @@ void hb_face_t::load_upem (void) const { hb_blob_t *head_blob = OT::Sanitizer<OT::head>().sanitize (reference_table (HB_OT_TAG_head)); - const OT::head *head_table = OT::Sanitizer<OT::head>::lock_instance (head_blob); + const OT::head *head_table = head_blob->lock_as<OT::head> (); upem = head_table->get_upem (); hb_blob_destroy (head_blob); } @@ -469,7 +470,7 @@ void hb_face_t::load_num_glyphs (void) const { hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (reference_table (HB_OT_TAG_maxp)); - const OT::maxp *maxp_table = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob); + const OT::maxp *maxp_table = maxp_blob->lock_as<OT::maxp> (); num_glyphs = maxp_table->get_num_glyphs (); hb_blob_destroy (maxp_blob); } @@ -499,7 +500,7 @@ hb_face_get_table_tags (hb_face_t *face, hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) face->user_data; - const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob); + const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as<OT::OpenTypeFontFile> (); const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); return ot_face.get_table_tags (start_offset, table_count, table_tags); diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 68e0e410..9f07b3f5 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -31,6 +31,7 @@ #include "hb-private.hh" #include "hb-debug.hh" +#include "hb-blob-private.hh" #include "hb-face-private.hh" @@ -350,12 +351,6 @@ struct Sanitizer } } - static const Type* lock_instance (hb_blob_t *blob) { - hb_blob_make_immutable (blob); - const char *base = hb_blob_get_data (blob, nullptr); - return unlikely (!base) ? &Null(Type) : CastP<Type> (base); - } - inline void set_num_glyphs (unsigned int num_glyphs) { c->num_glyphs = num_glyphs; } private: @@ -1255,7 +1250,7 @@ struct hb_lazy_table_loader_t if (unlikely (!p)) { hb_blob_t *blob_ = OT::Sanitizer<T>().sanitize (face->reference_table (T::tableTag)); - p = const_cast<T *>(OT::Sanitizer<T>::lock_instance (blob_)); + p = const_cast<T *>(blob_->lock_as<T> ()); if (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p)) { hb_blob_destroy (blob_); diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index caffda35..438063e0 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -661,7 +661,7 @@ struct cmap inline void init (hb_face_t *face) { this->blob = OT::Sanitizer<OT::cmap>().sanitize (face->reference_table (HB_OT_TAG_cmap)); - const OT::cmap *cmap = OT::Sanitizer<OT::cmap>::lock_instance (this->blob); + const OT::cmap *cmap = this->blob->lock_as<OT::cmap> (); const OT::CmapSubtable *subtable = nullptr; const OT::CmapSubtableFormat14 *subtable_uvs = nullptr; diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 528d144a..52364ff7 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -403,8 +403,8 @@ struct CBDT cbdt = nullptr; return; /* Not a bitmap font. */ } - cblc = Sanitizer<CBLC>::lock_instance (cblc_blob); - cbdt = Sanitizer<CBDT>::lock_instance (cbdt_blob); + cblc = cblc_blob->lock_as<CBLC> (); + cbdt = cbdt_blob->lock_as<CBDT> (); } diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 09d0cc57..17d6c730 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -102,7 +102,7 @@ struct sbix sanitizer.set_num_glyphs (num_glyphs); sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix)); sbix_len = hb_blob_get_length (sbix_blob); - sbix_table = OT::Sanitizer<OT::sbix>::lock_instance (sbix_blob); + sbix_table = sbix_blob->lock_as<OT::sbix> (); } diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 47b3292b..ccf4b9c4 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -99,7 +99,7 @@ struct SVG OT::Sanitizer<OT::SVG> sanitizer; svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG)); svg_len = hb_blob_get_length (svg_blob); - svg = OT::Sanitizer<OT::SVG>::lock_instance (svg_blob); + svg = svg_blob->lock_as<OT::SVG> (); } diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 4b02153c..07169687 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -237,7 +237,7 @@ struct glyf memset (this, 0, sizeof (accelerator_t)); hb_blob_t *head_blob = Sanitizer<head>().sanitize (face->reference_table (HB_OT_TAG_head)); - const head *head_table = Sanitizer<head>::lock_instance (head_blob); + const head *head_table = head_blob->lock_as<head> (); if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0) { /* head table is not present, or in an unknown format. Leave num_glyphs=0, that takes care of disabling us. */ @@ -248,9 +248,9 @@ struct glyf hb_blob_destroy (head_blob); loca_blob = Sanitizer<loca>().sanitize (face->reference_table (HB_OT_TAG_loca)); - loca_table = Sanitizer<loca>::lock_instance (loca_blob); + loca_table = loca_blob->lock_as<loca> (); glyf_blob = Sanitizer<glyf>().sanitize (face->reference_table (HB_OT_TAG_glyf)); - glyf_table = Sanitizer<glyf>::lock_instance (glyf_blob); + glyf_table = glyf_blob->lock_as<glyf> (); num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1; glyf_len = hb_blob_get_length (glyf_blob); diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 5944688a..02419a88 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -196,7 +196,7 @@ struct hmtxvmtx if (T::os2Tag) { hb_blob_t *os2_blob = Sanitizer<os2> ().sanitize (face->reference_table (T::os2Tag)); - const os2 *os2_table = Sanitizer<os2>::lock_instance (os2_blob); + const os2 *os2_table = os2_blob->lock_as<os2> (); #define USE_TYPO_METRICS (1u<<7) if (0 != (os2_table->fsSelection & USE_TYPO_METRICS)) { @@ -209,7 +209,7 @@ struct hmtxvmtx } hb_blob_t *_hea_blob = Sanitizer<H> ().sanitize (face->reference_table (H::tableTag)); - const H *_hea_table = Sanitizer<H>::lock_instance (_hea_blob); + const H *_hea_table = _hea_blob->lock_as<H> (); num_advances = _hea_table->numberOfLongMetrics; if (!got_font_extents) { @@ -238,10 +238,10 @@ struct hmtxvmtx hb_blob_destroy (blob); blob = hb_blob_get_empty (); } - table = Sanitizer<hmtxvmtx>::lock_instance (blob); + table = blob->lock_as<hmtxvmtx> (); var_blob = Sanitizer<HVARVVAR> ().sanitize (face->reference_table (T::variationsTag)); - var_table = Sanitizer<HVARVVAR>::lock_instance (var_blob); + var_table = var_blob->lock_as<HVARVVAR> (); } inline void fini (void) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index ec331698..71b368a8 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -363,7 +363,7 @@ struct kern inline void init (hb_face_t *face) { blob = Sanitizer<kern>().sanitize (face->reference_table (HB_OT_TAG_kern)); - table = Sanitizer<kern>::lock_instance (blob); + table = blob->lock_as<kern> (); table_length = hb_blob_get_length (blob); } inline void fini (void) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 5ee03dc8..a4673fc5 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -59,13 +59,13 @@ _hb_ot_layout_create (hb_face_t *face) return nullptr; layout->gdef_blob = OT::Sanitizer<OT::GDEF>().sanitize (face->reference_table (HB_OT_TAG_GDEF)); - layout->gdef = OT::Sanitizer<OT::GDEF>::lock_instance (layout->gdef_blob); + layout->gdef = layout->gdef_blob->lock_as<OT::GDEF> (); layout->gsub_blob = OT::Sanitizer<OT::GSUB>().sanitize (face->reference_table (HB_OT_TAG_GSUB)); - layout->gsub = OT::Sanitizer<OT::GSUB>::lock_instance (layout->gsub_blob); + layout->gsub = layout->gsub_blob->lock_as<OT::GSUB> (); layout->gpos_blob = OT::Sanitizer<OT::GPOS>().sanitize (face->reference_table (HB_OT_TAG_GPOS)); - layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); + layout->gpos = layout->gpos_blob->lock_as<OT::GPOS> (); layout->math.init (face); layout->fvar.init (face); diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 63aa83ad..d1793d35 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -110,7 +110,7 @@ struct post inline void init (hb_face_t *face) { blob = Sanitizer<post>().sanitize (face->reference_table (HB_OT_TAG_post)); - const post *table = Sanitizer<post>::lock_instance (blob); + const post *table = blob->lock_as<post> (); unsigned int table_length = hb_blob_get_length (blob); version = table->version.to_int (); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 6c3d7591..bca56770 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -87,7 +87,7 @@ _subset (hb_subset_plan_t *plan) OT::Sanitizer<TableType> sanitizer; hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag)); - const TableType *table = OT::Sanitizer<TableType>::lock_instance (source_blob); + const TableType *table = source_blob->lock_as<TableType> (); hb_tag_t tag = TableType::tableTag; hb_bool_t result = false; diff --git a/src/main.cc b/src/main.cc index 0436c85f..2976c895 100644 --- a/src/main.cc +++ b/src/main.cc @@ -56,7 +56,7 @@ main (int argc, char **argv) Sanitizer<OpenTypeFontFile> sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const OpenTypeFontFile* sanitized = Sanitizer<OpenTypeFontFile>::lock_instance (font_blob); + const OpenTypeFontFile* sanitized = font_blob->lock_as<OpenTypeFontFile> (); if (sanitized == &Null (OpenTypeFontFile)) { printf ("Sanitization of the file wasn't successful. Exit"); commit abc12f7b8157c3981216d82ead60627db31a6c14 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 02:23:36 2018 -0700 Move null pool to hb-private diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index e173a5ee..19c06183 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 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 1d18983c..7e1fef61 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 @@ struct NE_TYPEINFO { 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 @@ 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 7bd60272..18743e3c 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 1f22b182..68e0e410 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -127,46 +127,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 <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 @@ 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 <typename Type> @@ -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<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 83a0b519..caffda35 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 ceebe0b7..86171c63 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 bd193f9d..bec694e1 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<Index> @@ -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<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 f7e49648..5ee03dc8 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 @@ _hb_ot_layout_create (hb_face_t *face) * 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 @@ _hb_ot_layout_create (hb_face_t *face) * 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 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) // 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 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) 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 @@ get_gsubgpos_table (hb_face_t *face, 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_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, 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_ot_layout_lookup_substitute_closure (hb_face_t *face, 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_ot_layout_substitute_lookup (OT::hb_ot_apply_context_t *c, // 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 f82a0735..1667a7da 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 @@ _get_math (hb_face_t *face) 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 90ba0bd0..f0612a61 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 @@ _get_avar (hb_face_t *face) 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 21561ce4..9e075a31 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1089,4 +1089,33 @@ round (double x) #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 35fe0ef8..6c3d7591 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 @@ _subset (hb_subset_plan_t *plan) 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 935fa392..0436c85f 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 commit 08e280fd84384f73d395918646ee044a5bbfee45 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 01:57:27 2018 -0700 Rename hb_string_t to hb_bytes_t diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index 0cd97fa2..63aa83ad 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -141,7 +141,7 @@ struct post inline bool get_glyph_name (hb_codepoint_t glyph, char *buf, unsigned int buf_len) const { - hb_string_t s = find_glyph_name (glyph); + hb_bytes_t s = find_glyph_name (glyph); if (!s.len) return false; if (!buf_len) @@ -185,7 +185,7 @@ struct post } } - hb_string_t st (name, len); + hb_bytes_t st (name, len); const uint16_t *gid = (const uint16_t *) hb_bsearch_r (&st, gids, count, sizeof (gids[0]), cmp_key, (void *) this); if (gid) { @@ -220,23 +220,23 @@ struct post static inline int cmp_key (const void *pk, const void *po, void *arg) { const accelerator_t *thiz = (const accelerator_t *) arg; - const hb_string_t *key = (const hb_string_t *) pk; + const hb_bytes_t *key = (const hb_bytes_t *) pk; uint16_t o = * (const uint16_t *) po; return thiz->find_glyph_name (o).cmp (*key); } - inline hb_string_t find_glyph_name (hb_codepoint_t glyph) const + inline hb_bytes_t find_glyph_name (hb_codepoint_t glyph) const { if (version == 0x00010000) { if (glyph >= NUM_FORMAT1_NAMES) - return hb_string_t (); + return hb_bytes_t (); return format1_names (glyph); } if (version != 0x00020000 || glyph >= glyphNameIndex->len) - return hb_string_t (); + return hb_bytes_t (); unsigned int index = glyphNameIndex->array[glyph]; if (index < NUM_FORMAT1_NAMES) @@ -244,14 +244,14 @@ struct post index -= NUM_FORMAT1_NAMES; if (index >= index_to_offset.len) - return hb_string_t (); + return hb_bytes_t (); unsigned int offset = index_to_offset.array[index]; const uint8_t *data = pool + offset; unsigned int name_length = *data; data++; - return hb_string_t ((const char *) data, name_length); + return hb_bytes_t ((const char *) data, name_length); } private: diff --git a/src/hb-private.hh b/src/hb-private.hh index 1b1e83f4..21561ce4 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -1052,12 +1052,12 @@ hb_options (void) /* String type. */ -struct hb_string_t +struct hb_bytes_t { - inline hb_string_t (void) : bytes (nullptr), len (0) {} - inline hb_string_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {} + inline hb_bytes_t (void) : bytes (nullptr), len (0) {} + inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {} - inline int cmp (const hb_string_t &a) const + inline int cmp (const hb_bytes_t &a) const { if (len != a.len) return (int) a.len - (int) len; @@ -1066,8 +1066,8 @@ struct hb_string_t } static inline int cmp (const void *pa, const void *pb) { - hb_string_t *a = (hb_string_t *) pa; - hb_string_t *b = (hb_string_t *) pb; + hb_bytes_t *a = (hb_bytes_t *) pa; + hb_bytes_t *b = (hb_bytes_t *) pb; return b->cmp (*a); } diff --git a/src/hb-string-array.hh b/src/hb-string-array.hh index d83553dd..679841c8 100644 --- a/src/hb-string-array.hh +++ b/src/hb-string-array.hh @@ -66,12 +66,12 @@ static const unsigned int HB_STRING_ARRAY_OFFS_NAME[] = sizeof (HB_STRING_ARRAY_TYPE_NAME) }; -static inline hb_string_t +static inline hb_bytes_t HB_STRING_ARRAY_NAME (unsigned int i) { assert (i < ARRAY_LENGTH (HB_STRING_ARRAY_OFFS_NAME) - 1); - return hb_string_t (HB_STRING_ARRAY_POOL_NAME.str + HB_STRING_ARRAY_OFFS_NAME[i], - HB_STRING_ARRAY_OFFS_NAME[i + 1] - HB_STRING_ARRAY_OFFS_NAME[i] - 1); + return hb_bytes_t (HB_STRING_ARRAY_POOL_NAME.str + HB_STRING_ARRAY_OFFS_NAME[i], + HB_STRING_ARRAY_OFFS_NAME[i + 1] - HB_STRING_ARRAY_OFFS_NAME[i] - 1); } #undef HB_STRING_ARRAY_TYPE_NAME commit bd021a67203aa5b07c31c02d63e6154da0c05d31 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 01:50:30 2018 -0700 Minor diff --git a/src/hb-private.hh b/src/hb-private.hh index d7c8fef8..1b1e83f4 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -829,7 +829,7 @@ static inline unsigned char TOLOWER (unsigned char c) * light-weight) to be enabled, then HB_DEBUG can be defined to disable * the costlier checks. */ #ifdef NDEBUG -#define HB_NDEBUG +#define HB_NDEBUG 1 #endif commit 16e4ccf7b417f021948643012cbe7641ba02c039 Author: Behdad Esfahbod <[email protected]> Date: Tue May 8 01:47:05 2018 -0700 Allocate user-data-array on the heap This saves each object allocation 72 bytes. Now object overhead is just 16 bytes (on x86) instead of 88 bytes. Neat. diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 75a72f4b..1f61dcea 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -62,7 +62,6 @@ struct hb_reference_count_t /* user_data */ -#define HB_USER_DATA_ARRAY_INIT {HB_MUTEX_INIT, HB_LOCKABLE_SET_INIT} struct hb_user_data_array_t { struct hb_user_data_item_t { @@ -97,9 +96,9 @@ struct hb_user_data_array_t struct hb_object_header_t { hb_reference_count_t ref_count; - hb_user_data_array_t user_data; + hb_user_data_array_t *user_data; -#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_USER_DATA_ARRAY_INIT} +#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, nullptr} private: ASSERT_POD (); @@ -133,7 +132,7 @@ template <typename Type> static inline void hb_object_init (Type *obj) { obj->header.ref_count.init (1); - obj->header.user_data.init (); + obj->header.user_data = nullptr; } template <typename Type> static inline bool hb_object_is_inert (const Type *obj) @@ -172,7 +171,11 @@ template <typename Type> static inline void hb_object_fini (Type *obj) { obj->header.ref_count.fini (); /* Do this before user_data */ - obj->header.user_data.fini (); + if (obj->header.user_data) + { + obj->header.user_data->fini (); + free (obj->header.user_data); + } } template <typename Type> static inline bool hb_object_set_user_data (Type *obj, @@ -184,17 +187,34 @@ static inline bool hb_object_set_user_data (Type *obj, if (unlikely (!obj || hb_object_is_inert (obj))) return false; assert (hb_object_is_valid (obj)); - return obj->header.user_data.set (key, data, destroy, replace); + +retry: + hb_user_data_array_t *user_data = (hb_user_data_array_t *) hb_atomic_ptr_get (&obj->header.user_data); + if (unlikely (!user_data)) + { + user_data = (hb_user_data_array_t *) calloc (sizeof (hb_user_data_array_t), 1); + if (unlikely (!user_data)) + return false; + user_data->init (); + if (unlikely (!hb_atomic_ptr_cmpexch (&obj->header.user_data, nullptr, user_data))) + { + user_data->fini (); + free (user_data); + goto retry; + } + } + + return user_data->set (key, data, destroy, replace); } template <typename Type> static inline void *hb_object_get_user_data (Type *obj, hb_user_data_key_t *key) { - if (unlikely (!obj || hb_object_is_inert (obj))) + if (unlikely (!obj || hb_object_is_inert (obj) || !obj->header.user_data)) return nullptr; assert (hb_object_is_valid (obj)); - return obj->header.user_data.get (key); + return obj->header.user_data->get (key); } _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
