Add hb_blob_ptr_t

Use in a couple of places.  Push to bots to see how many unhappy before
I convert the rest.
This commit is contained in:
Behdad Esfahbod 2018-11-10 23:52:15 -05:00
parent e44046ec49
commit 5d0078a48b
5 changed files with 39 additions and 23 deletions

View File

@ -80,4 +80,27 @@ struct hb_blob_t
DECLARE_NULL_INSTANCE (hb_blob_t); DECLARE_NULL_INSTANCE (hb_blob_t);
/*
* hb_blob_ptr_t
*/
template <typename P>
struct hb_blob_ptr_t
{
typedef typename hb_remove_pointer<P>::value T;
inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {}
inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; }
inline const T * operator -> (void) const { return get (); }
inline const T & operator * (void) const { return *get (); }
template <typename C> inline operator const C * (void) const { return get (); }
inline operator const char * (void) const { return (const char *) get (); }
inline const T * get (void) const { return b->as<T> (); }
inline hb_blob_t * get_blob (void) const { return b.get_raw (); }
inline unsigned int get_length (void) const { return get_blob ()->length; }
hb_nonnull_ptr_t<hb_blob_t> b;
};
#endif /* HB_BLOB_HH */ #endif /* HB_BLOB_HH */

View File

@ -412,11 +412,10 @@ struct GDEF
inline void fini (void) inline void fini (void)
{ {
hb_blob_destroy (this->blob); hb_blob_destroy (this->table.get_blob ());
} }
hb_blob_t *blob; hb_blob_ptr_t<GDEF> table;
hb_nonnull_ptr_t<const GDEF> table;
}; };
inline unsigned int get_size (void) const inline unsigned int get_size (void) const

View File

@ -2752,8 +2752,7 @@ struct GSUBGPOS
{ {
inline void init (hb_face_t *face) inline void init (hb_face_t *face)
{ {
this->blob = hb_sanitize_context_t().reference_table<T> (face); this->table = hb_sanitize_context_t().reference_table<T> (face);
table = this->blob->template as<T> ();
this->lookup_count = table->get_lookup_count (); this->lookup_count = table->get_lookup_count ();
@ -2770,11 +2769,10 @@ struct GSUBGPOS
for (unsigned int i = 0; i < this->lookup_count; i++) for (unsigned int i = 0; i < this->lookup_count; i++)
this->accels[i].fini (); this->accels[i].fini ();
free (this->accels); free (this->accels);
hb_blob_destroy (this->blob); hb_blob_destroy (this->table.get_blob ());
} }
hb_blob_t *blob; hb_blob_ptr_t<T> table;
hb_nonnull_ptr_t<const T> table;
unsigned int lookup_count; unsigned int lookup_count;
hb_ot_layout_lookup_accelerator_t *accels; hb_ot_layout_lookup_accelerator_t *accels;
}; };

View File

@ -194,17 +194,15 @@ _hb_ot_blacklist_gdef (unsigned int gdef_len,
void void
OT::GDEF::accelerator_t::init (hb_face_t *face) OT::GDEF::accelerator_t::init (hb_face_t *face)
{ {
this->blob = hb_sanitize_context_t().reference_table<GDEF> (face); this->table = hb_sanitize_context_t().reference_table<GDEF> (face);
if (unlikely (_hb_ot_blacklist_gdef (this->blob->length, if (unlikely (_hb_ot_blacklist_gdef (this->table.get_length (),
face->table.GSUB->blob->length, face->table.GSUB->table.get_length (),
face->table.GPOS->blob->length))) face->table.GPOS->table.get_length ())))
{ {
hb_blob_destroy (this->blob); hb_blob_destroy (this->table.get_blob ());
this->blob = hb_blob_get_empty (); this->table = hb_blob_get_empty ();
} }
table = this->blob->as<GDEF> ();
} }
static void static void

View File

@ -179,11 +179,10 @@ struct name
{ {
inline void init (hb_face_t *face) inline void init (hb_face_t *face)
{ {
this->blob = hb_sanitize_context_t().reference_table<name> (face); this->table = hb_sanitize_context_t().reference_table<name> (face);
this->table = this->blob->as<name> (); assert (this->table.get_length () >= this->table->stringOffset);
assert (this->blob->length >= this->table->stringOffset);
this->pool = (this->table+this->table->stringOffset).arrayZ; this->pool = (this->table+this->table->stringOffset).arrayZ;
this->pool_len = this->blob->length - this->table->stringOffset; this->pool_len = this->table.get_length () - this->table->stringOffset;
const hb_array_t<const NameRecord> all_names (this->table->nameRecordZ.arrayZ, const hb_array_t<const NameRecord> all_names (this->table->nameRecordZ.arrayZ,
this->table->count); this->table->count);
@ -221,7 +220,7 @@ struct name
inline void fini (void) inline void fini (void)
{ {
this->names.fini (); this->names.fini ();
hb_blob_destroy (this->blob); hb_blob_destroy (this->table.get_blob ());
} }
inline int get_index (hb_ot_name_id_t name_id, inline int get_index (hb_ot_name_id_t name_id,
@ -253,11 +252,10 @@ struct name
} }
private: private:
hb_blob_t *blob;
const void *pool; const void *pool;
unsigned int pool_len; unsigned int pool_len;
public: public:
hb_nonnull_ptr_t<const name> table; hb_blob_ptr_t<name> table;
hb_vector_t<hb_ot_name_entry_t> names; hb_vector_t<hb_ot_name_entry_t> names;
}; };