diff --git a/src/dump-emoji.cc b/src/dump-emoji.cc index 19c0618334a359cd2f601b225b3e59ccaa201ce9..47c6c98baad0668f0036c5292d0e79aa28500796 100644 --- a/src/dump-emoji.cc +++ b/src/dump-emoji.cc @@ -240,11 +240,11 @@ int main (int argc, char **argv) OT::Sanitizer sanitizerCOLR; hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR)); - const OT::COLR *colr = OT::Sanitizer::lock_instance (colr_blob); + const OT::COLR *colr = colr_blob->lock_as (); OT::Sanitizer sanitizerCPAL; hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL)); - const OT::CPAL *cpal = OT::Sanitizer::lock_instance (cpal_blob); + const OT::CPAL *cpal = cpal_blob->lock_as (); cairo_font_face_t *cairo_face; { diff --git a/src/dump-fon.cc b/src/dump-fon.cc index 7e1fef618962003e22469cfdadab8e1432dd78a1..dc45d9c4f9a89b57da176f7e23f8b645c0199f37 100644 --- a/src/dump-fon.cc +++ b/src/dump-fon.cc @@ -542,8 +542,7 @@ int main (int argc, char** argv) { OT::Sanitizer sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const LE_IMAGE_DOS_HEADER* dos_header = - OT::Sanitizer::lock_instance (font_blob); + const LE_IMAGE_DOS_HEADER* dos_header = font_blob->lock_as (); 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 18743e3cd6d9ee08ead363e2566ca05087f406f5..e6efaab4cc6f2948748788dc290f7d751bd39f52 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 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::lock_instance (morx_blob); +// morx_blob->lock_as (); // if (0) // { -// OT::Sanitizer >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ()); +// morx_blob->lock_as > ()->get_value (1, face->get_num_glyphs ()); // } // } diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh index 0d567c288cd470b2cdcb19665dbff110ce6d3a08..f564351adb096ba964729cd6582980a7342cd204 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 + inline const Type* as (void) const + { + return unlikely (!data) ? &Null(Type) : reinterpret_cast (data); + } + template + inline const Type* lock_as (void) + { + lock (); + return unlikely (!data) ? &Null(Type) : reinterpret_cast (data); + } + public: hb_object_header_t header; ASSERT_POD (); diff --git a/src/hb-face.cc b/src/hb-face.cc index d8af8c1f37e8dc67bee8b57e5bb6b0e96db593f8..9fc40d48a9d61d8ad0a6e4a69693c2a1ec148033 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::lock_instance (data->blob); + const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as (); 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().sanitize (reference_table (HB_OT_TAG_head)); - const OT::head *head_table = OT::Sanitizer::lock_instance (head_blob); + const OT::head *head_table = head_blob->lock_as (); 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().sanitize (reference_table (HB_OT_TAG_maxp)); - const OT::maxp *maxp_table = OT::Sanitizer::lock_instance (maxp_blob); + const OT::maxp *maxp_table = maxp_blob->lock_as (); 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::lock_instance (data->blob); + const OT::OpenTypeFontFile &ot_file = *data->blob->lock_as (); 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 68e0e410df38fba817c9e3e325f98225ff132217..9f07b3f56e91f5fa660c22811a7bed9cde163a03 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 (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().sanitize (face->reference_table (T::tableTag)); - p = const_cast(OT::Sanitizer::lock_instance (blob_)); + p = const_cast(blob_->lock_as ()); if (!hb_atomic_ptr_cmpexch (const_cast(&instance), nullptr, p)) { hb_blob_destroy (blob_); diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index caffda352715388d1967c913551a8ad777a6dd63..438063e0e22d961c3538e571cf209fb4d0dfd2a3 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().sanitize (face->reference_table (HB_OT_TAG_cmap)); - const OT::cmap *cmap = OT::Sanitizer::lock_instance (this->blob); + const OT::cmap *cmap = this->blob->lock_as (); 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 528d144a8dc62b7e4c2f81de537a058abe6e493b..52364ff79259d131144a57d94ab377e09f8cfdb5 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::lock_instance (cblc_blob); - cbdt = Sanitizer::lock_instance (cbdt_blob); + cblc = cblc_blob->lock_as (); + cbdt = cbdt_blob->lock_as (); } diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 09d0cc57a4dea7af35e2c272259001ce3c574312..17d6c730cb64850303bb5affdb24bbfcb0be3231 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::lock_instance (sbix_blob); + sbix_table = sbix_blob->lock_as (); } diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index 47b3292b71a08e723cc7c426bd828cc1b2bd8708..ccf4b9c419f96c833ca66ec22186ee1b8e602a04 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 sanitizer; svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG)); svg_len = hb_blob_get_length (svg_blob); - svg = OT::Sanitizer::lock_instance (svg_blob); + svg = svg_blob->lock_as (); } diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 4b02153cbf669e6ec38ccf9c926252a43f1df19a..071696877e432dbb7b46e19af309b54d522c498d 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().sanitize (face->reference_table (HB_OT_TAG_head)); - const head *head_table = Sanitizer::lock_instance (head_blob); + const head *head_table = head_blob->lock_as (); 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().sanitize (face->reference_table (HB_OT_TAG_loca)); - loca_table = Sanitizer::lock_instance (loca_blob); + loca_table = loca_blob->lock_as (); glyf_blob = Sanitizer().sanitize (face->reference_table (HB_OT_TAG_glyf)); - glyf_table = Sanitizer::lock_instance (glyf_blob); + glyf_table = glyf_blob->lock_as (); 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 5944688aab2aa46dd8e3de0a40be1f0343392408..02419a886742104e4a39c669282b7a6b1b603e38 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 ().sanitize (face->reference_table (T::os2Tag)); - const os2 *os2_table = Sanitizer::lock_instance (os2_blob); + const os2 *os2_table = os2_blob->lock_as (); #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 ().sanitize (face->reference_table (H::tableTag)); - const H *_hea_table = Sanitizer::lock_instance (_hea_blob); + const H *_hea_table = _hea_blob->lock_as (); 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::lock_instance (blob); + table = blob->lock_as (); var_blob = Sanitizer ().sanitize (face->reference_table (T::variationsTag)); - var_table = Sanitizer::lock_instance (var_blob); + var_table = var_blob->lock_as (); } inline void fini (void) diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index ec3316989340499c7030918fddd44b6a4c8ef376..71b368a87e11cd44f4412ec1958c7c0aec510c8e 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().sanitize (face->reference_table (HB_OT_TAG_kern)); - table = Sanitizer::lock_instance (blob); + table = blob->lock_as (); 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 5ee03dc8ad936f1b2221f24d5d00692dd57d2071..a4673fc54fdaf587ea3d3c04150ef2f636f63002 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().sanitize (face->reference_table (HB_OT_TAG_GDEF)); - layout->gdef = OT::Sanitizer::lock_instance (layout->gdef_blob); + layout->gdef = layout->gdef_blob->lock_as (); layout->gsub_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_GSUB)); - layout->gsub = OT::Sanitizer::lock_instance (layout->gsub_blob); + layout->gsub = layout->gsub_blob->lock_as (); layout->gpos_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_GPOS)); - layout->gpos = OT::Sanitizer::lock_instance (layout->gpos_blob); + layout->gpos = layout->gpos_blob->lock_as (); 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 63aa83ad0d1ae8a6e6f3ee25b881bc221e4bd737..d1793d353d5cc716e4113257d807290afbf8e0dc 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().sanitize (face->reference_table (HB_OT_TAG_post)); - const post *table = Sanitizer::lock_instance (blob); + const post *table = blob->lock_as (); 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 6c3d7591784fca36b095bdc0e7cda2279f6fb286..bca567702f988d50499844db646674ae0e27daec 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -87,7 +87,7 @@ _subset (hb_subset_plan_t *plan) OT::Sanitizer sanitizer; hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag)); - const TableType *table = OT::Sanitizer::lock_instance (source_blob); + const TableType *table = source_blob->lock_as (); hb_tag_t tag = TableType::tableTag; hb_bool_t result = false; diff --git a/src/main.cc b/src/main.cc index 0436c85f812bd0c95fe51b0d84686480ff44274e..2976c895bd5be3e5b33453ce3ebb596b3fe12b2e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -56,7 +56,7 @@ main (int argc, char **argv) Sanitizer sanitizer; hb_blob_t *font_blob = sanitizer.sanitize (blob); - const OpenTypeFontFile* sanitized = Sanitizer::lock_instance (font_blob); + const OpenTypeFontFile* sanitized = font_blob->lock_as (); if (sanitized == &Null (OpenTypeFontFile)) { printf ("Sanitization of the file wasn't successful. Exit");