[HarfBuzz] harfbuzz: Branch 'master' - 4 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Sun Nov 25 04:50:26 UTC 2018


 src/hb-aat-layout-kerx-table.hh |   19 ++++++-----------
 src/hb-aat-layout-morx-table.hh |   18 ++++++++--------
 src/hb-machinery.hh             |   43 +++++++++++++++++++++++++++-------------
 3 files changed, 46 insertions(+), 34 deletions(-)

New commits:
commit c5a6b355e165e90d8d90454ceeca7b100282945f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 23:49:23 2018 -0500

    [kerx] Port to hb_sanitize_with_object_t

diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh
index 33f626c6..8dc74991 100644
--- a/src/hb-aat-layout-kerx-table.hh
+++ b/src/hb-aat-layout-kerx-table.hh
@@ -926,13 +926,11 @@ struct KerxTable
       if (reverse)
 	c->buffer->reverse ();
 
-      /* See comment in sanitize() for conditional here. */
-      if (i < count - 1)
-	c->sanitizer.set_object (st);
-      else
-	c->sanitizer.set_object ();
-
-      ret |= st->dispatch (c);
+      {
+	/* See comment in sanitize() for conditional here. */
+	hb_sanitize_with_object_t with (&c->sanitizer, i < count - 1 ? st : (const SubTable *) nullptr);
+	ret |= st->dispatch (c);
+      }
 
       if (reverse)
 	c->buffer->reverse ();
@@ -943,7 +941,6 @@ struct KerxTable
       st = &StructAfter<SubTable> (*st);
       c->set_lookup_index (c->lookup_index + 1);
     }
-    c->sanitizer.set_object ();
 
     return ret;
   }
@@ -962,7 +959,6 @@ struct KerxTable
     unsigned int count = thiz()->tableCount;
     for (unsigned int i = 0; i < count; i++)
     {
-      c->set_object ();
       if (unlikely (!st->u.header.sanitize (c)))
 	return_trace (false);
       /* OpenType kern table has 2-byte subtable lengths.  That's limiting.
@@ -972,14 +968,13 @@ struct KerxTable
        * is simply ignored.  Which makes sense.  It's only needed if you
        * have multiple subtables.  To handle such fonts, we just ignore
        * the length for the last subtable. */
-      if (i < count - 1)
-	c->set_object (st);
+      hb_sanitize_with_object_t with (c, i < count - 1 ? st : (const SubTable *) nullptr);
 
       if (unlikely (!st->sanitize (c)))
 	return_trace (false);
+
       st = &StructAfter<SubTable> (*st);
     }
-    c->set_object ();
 
     return_trace (true);
   }
commit c405ed0509afaa7c3846e8e461bedfbceb0cd937
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 23:46:15 2018 -0500

    [morx] Port to hb_sanitize_with_object_t

diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh
index bc7c3c37..15332d0f 100644
--- a/src/hb-aat-layout-morx-table.hh
+++ b/src/hb-aat-layout-morx-table.hh
@@ -911,6 +911,13 @@ struct ChainSubtable
     }
   }
 
+  inline bool apply (hb_aat_apply_context_t *c) const
+  {
+    TRACE_APPLY (this);
+    hb_sanitize_with_object_t with (&c->sanitizer, this);
+    return_trace (dispatch (c));
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
@@ -919,6 +926,7 @@ struct ChainSubtable
 	!c->check_range (this, length))
       return_trace (false);
 
+    hb_sanitize_with_object_t with (c, this);
     return_trace (dispatch (c));
   }
 
@@ -1026,9 +1034,7 @@ struct Chain
       if (reverse)
         c->buffer->reverse ();
 
-      c->sanitizer.set_object (subtable);
-
-      subtable->dispatch (c);
+      subtable->apply (c);
 
       if (reverse)
         c->buffer->reverse ();
@@ -1041,7 +1047,6 @@ struct Chain
       subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
       c->set_lookup_index (c->lookup_index + 1);
     }
-    c->sanitizer.set_object ();
   }
 
   inline unsigned int get_size (void) const { return length; }
@@ -1061,15 +1066,10 @@ struct Chain
     unsigned int count = subtableCount;
     for (unsigned int i = 0; i < count; i++)
     {
-      c->set_object ();
-      if (unlikely (!c->check_struct (subtable)))
-	return_trace (false);
-      c->set_object (subtable);
       if (!subtable->sanitize (c))
 	return_trace (false);
       subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
     }
-    c->set_object ();
 
     return_trace (true);
   }
commit 1e8994221fb5cfdb1902d5249c7a75cde6d6e3c8
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 23:38:06 2018 -0500

    Add hb_sanitize_with_object_t
    
    Context manager.

diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh
index 7457a099..56e279e6 100644
--- a/src/hb-machinery.hh
+++ b/src/hb-machinery.hh
@@ -480,6 +480,23 @@ struct hb_sanitize_context_t :
   bool  num_glyphs_set;
 };
 
+struct hb_sanitize_with_object_t
+{
+  template <typename T = hb_sanitize_context_t::dummy_get_size_t>
+  inline hb_sanitize_with_object_t (hb_sanitize_context_t *c,
+				    const T& obj) : c (c)
+  {
+    c->set_object (obj);
+  }
+  inline ~hb_sanitize_with_object_t (void)
+  {
+    c->set_object ();
+  }
+
+  private:
+  hb_sanitize_context_t *c;
+};
+
 
 /*
  * Serialize
commit b3c5affc05a3c7bbcfbd98521703d3d3447fcd7d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Nov 24 23:34:34 2018 -0500

    Simplify sanitize set_object()

diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh
index fbeb35b0..33f626c6 100644
--- a/src/hb-aat-layout-kerx-table.hh
+++ b/src/hb-aat-layout-kerx-table.hh
@@ -928,9 +928,9 @@ struct KerxTable
 
       /* See comment in sanitize() for conditional here. */
       if (i < count - 1)
-	c->sanitizer.set_object (*st);
+	c->sanitizer.set_object (st);
       else
-	c->sanitizer.reset_object ();
+	c->sanitizer.set_object ();
 
       ret |= st->dispatch (c);
 
@@ -943,7 +943,7 @@ struct KerxTable
       st = &StructAfter<SubTable> (*st);
       c->set_lookup_index (c->lookup_index + 1);
     }
-    c->sanitizer.reset_object ();
+    c->sanitizer.set_object ();
 
     return ret;
   }
@@ -962,7 +962,7 @@ struct KerxTable
     unsigned int count = thiz()->tableCount;
     for (unsigned int i = 0; i < count; i++)
     {
-      c->reset_object ();
+      c->set_object ();
       if (unlikely (!st->u.header.sanitize (c)))
 	return_trace (false);
       /* OpenType kern table has 2-byte subtable lengths.  That's limiting.
@@ -973,13 +973,13 @@ struct KerxTable
        * have multiple subtables.  To handle such fonts, we just ignore
        * the length for the last subtable. */
       if (i < count - 1)
-	c->set_object (*st);
+	c->set_object (st);
 
       if (unlikely (!st->sanitize (c)))
 	return_trace (false);
       st = &StructAfter<SubTable> (*st);
     }
-    c->reset_object ();
+    c->set_object ();
 
     return_trace (true);
   }
diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh
index dc406f59..bc7c3c37 100644
--- a/src/hb-aat-layout-morx-table.hh
+++ b/src/hb-aat-layout-morx-table.hh
@@ -1026,7 +1026,7 @@ struct Chain
       if (reverse)
         c->buffer->reverse ();
 
-      c->sanitizer.set_object (*subtable);
+      c->sanitizer.set_object (subtable);
 
       subtable->dispatch (c);
 
@@ -1041,7 +1041,7 @@ struct Chain
       subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
       c->set_lookup_index (c->lookup_index + 1);
     }
-    c->sanitizer.reset_object ();
+    c->sanitizer.set_object ();
   }
 
   inline unsigned int get_size (void) const { return length; }
@@ -1061,15 +1061,15 @@ struct Chain
     unsigned int count = subtableCount;
     for (unsigned int i = 0; i < count; i++)
     {
-      c->reset_object ();
+      c->set_object ();
       if (unlikely (!c->check_struct (subtable)))
 	return_trace (false);
-      c->set_object (*subtable);
+      c->set_object (subtable);
       if (!subtable->sanitize (c))
 	return_trace (false);
       subtable = &StructAfter<ChainSubtable<Types> > (*subtable);
     }
-    c->reset_object ();
+    c->set_object ();
 
     return_trace (true);
   }
diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh
index edef5405..7457a099 100644
--- a/src/hb-machinery.hh
+++ b/src/hb-machinery.hh
@@ -259,13 +259,20 @@ struct hb_sanitize_context_t :
 
   inline void set_max_ops (int max_ops_) { max_ops = max_ops_; }
 
-  template <typename T>
-  inline void set_object (const T& obj)
+  struct dummy_get_size_t
+  { inline unsigned int get_size (void) const { return 0; } };
+
+  template <typename T = dummy_get_size_t>
+  inline void set_object (const T *obj = nullptr)
   {
-    reset_object ();
+    this->start = this->blob->data;
+    this->end = this->start + this->blob->length;
+    assert (this->start <= this->end); /* Must not overflow. */
+
+    if (!obj) return;
 
-    const char *obj_start = (const char *) &obj;
-    const char *obj_end = (const char *) &obj + obj.get_size ();
+    const char *obj_start = (const char *) obj;
+    const char *obj_end = (const char *) obj + obj->get_size ();
     assert (obj_start <= obj_end); /* Must not overflow. */
 
     if (unlikely (obj_end < this->start || this->end < obj_start))
@@ -277,16 +284,9 @@ struct hb_sanitize_context_t :
     }
   }
 
-  inline void reset_object (void)
-  {
-    this->start = this->blob->data;
-    this->end = this->start + this->blob->length;
-    assert (this->start <= this->end); /* Must not overflow. */
-  }
-
   inline void start_processing (void)
   {
-    reset_object ();
+    set_object ();
     this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
 			 (unsigned) HB_SANITIZE_MAX_OPS_MIN);
     this->edit_count = 0;


More information about the HarfBuzz mailing list