Imported Upstream version 1.8.1
[platform/upstream/harfbuzz.git] / src / hb-uniscribe.cc
index cd25769..6d6afe8 100644 (file)
@@ -223,11 +223,19 @@ struct hb_uniscribe_shaper_funcs_t {
 };
 static hb_uniscribe_shaper_funcs_t *uniscribe_funcs;
 
+#ifdef HB_USE_ATEXIT
 static inline void
 free_uniscribe_funcs (void)
 {
+retry:
+  hb_uniscribe_shaper_funcs_t *local_uniscribe_funcs =
+    (hb_uniscribe_shaper_funcs_t *) hb_atomic_ptr_get (&uniscribe_funcs);
+  if (!hb_atomic_ptr_cmpexch (&uniscribe_funcs, local_uniscribe_funcs, nullptr))
+    goto retry;
+
   free (uniscribe_funcs);
 }
+#endif
 
 static hb_uniscribe_shaper_funcs_t *
 hb_uniscribe_shaper_get_funcs (void)
@@ -363,9 +371,10 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
   unsigned int name_table_length = OT::name::min_size +
                                    ARRAY_LENGTH (name_IDs) * OT::NameRecord::static_size +
                                    name_str_len * 2; /* for name data in UTF16BE form */
+  unsigned int padded_name_table_length = ((name_table_length + 3) & ~3);
   unsigned int name_table_offset = (length + 3) & ~3;
 
-  new_length = name_table_offset + ((name_table_length + 3) & ~3);
+  new_length = name_table_offset + padded_name_table_length;
   void *new_sfnt_data = calloc (1, new_length);
   if (!new_sfnt_data)
   {
@@ -410,7 +419,7 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
     if (face.find_table_index (HB_OT_TAG_name, &index))
     {
       OT::TableRecord &record = const_cast<OT::TableRecord &> (face.get_table (index));
-      record.checkSum.set_for_data (&name, name_table_length);
+      record.checkSum.set_for_data (&name, padded_name_table_length);
       record.offset.set (name_table_offset);
       record.length.set (name_table_length);
     }
@@ -621,12 +630,12 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
   /*
    * Set up features.
    */
-  hb_auto_array_t<OPENTYPE_FEATURE_RECORD> feature_records;
-  hb_auto_array_t<range_record_t> range_records;
+  hb_auto_t<hb_vector_t<OPENTYPE_FEATURE_RECORD> > feature_records;
+  hb_auto_t<hb_vector_t<range_record_t> > range_records;
   if (num_features)
   {
     /* Sort features by start/end events. */
-    hb_auto_array_t<feature_event_t> feature_events;
+    hb_auto_t<hb_vector_t<feature_event_t> > feature_events;
     for (unsigned int i = 0; i < num_features; i++)
     {
       active_feature_t feature;
@@ -637,15 +646,11 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
       feature_event_t *event;
 
       event = feature_events.push ();
-      if (unlikely (!event))
-       goto fail_features;
       event->index = features[i].start;
       event->start = true;
       event->feature = feature;
 
       event = feature_events.push ();
-      if (unlikely (!event))
-       goto fail_features;
       event->index = features[i].end;
       event->start = false;
       event->feature = feature;
@@ -659,15 +664,13 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
       feature.order = num_features + 1;
 
       feature_event_t *event = feature_events.push ();
-      if (unlikely (!event))
-       goto fail_features;
       event->index = 0; /* This value does magic. */
       event->start = false;
       event->feature = feature;
     }
 
     /* Scan events and save features for each range. */
-    hb_auto_array_t<active_feature_t> active_features;
+    hb_auto_t<hb_vector_t<active_feature_t> > active_features;
     unsigned int last_index = 0;
     for (unsigned int i = 0; i < feature_events.len; i++)
     {
@@ -677,8 +680,6 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
       {
         /* Save a snapshot of active features and the range. */
        range_record_t *range = range_records.push ();
-       if (unlikely (!range))
-         goto fail_features;
 
        unsigned int offset = feature_records.len;
 
@@ -687,10 +688,7 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
        {
          if (!j || active_features[j].rec.tagFeature != feature_records[feature_records.len - 1].tagFeature)
          {
-           OPENTYPE_FEATURE_RECORD *feature = feature_records.push ();
-           if (unlikely (!feature))
-             goto fail_features;
-           *feature = active_features[j].rec;
+           feature_records.push (active_features[j].rec);
          }
          else
          {
@@ -709,33 +707,28 @@ _hb_uniscribe_shape (hb_shape_plan_t    *shape_plan,
        last_index = event->index;
       }
 
-      if (event->start) {
-        active_feature_t *feature = active_features.push ();
-       if (unlikely (!feature))
-         goto fail_features;
-       *feature = event->feature;
-      } else {
+      if (event->start)
+      {
+       active_features.push (event->feature);
+      }
+      else
+      {
         active_feature_t *feature = active_features.find (&event->feature);
        if (feature)
-         active_features.remove (feature - active_features.array);
+         active_features.remove (feature - active_features.arrayZ);
       }
     }
 
     if (!range_records.len) /* No active feature found. */
-      goto fail_features;
+      num_features = 0;
 
     /* Fixup the pointers. */
     for (unsigned int i = 0; i < range_records.len; i++)
     {
       range_record_t *range = &range_records[i];
-      range->props.potfRecords = feature_records.array + reinterpret_cast<uintptr_t> (range->props.potfRecords);
+      range->props.potfRecords = feature_records.arrayZ + reinterpret_cast<uintptr_t> (range->props.potfRecords);
     }
   }
-  else
-  {
-  fail_features:
-    num_features = 0;
-  }
 
 #define FAIL(...) \
   HB_STMT_START { \
@@ -849,8 +842,8 @@ retry:
 #undef MAX_ITEMS
 
   OPENTYPE_TAG language_tag = hb_uint32_swap (hb_ot_tag_from_language (buffer->props.language));
-  hb_auto_array_t<TEXTRANGE_PROPERTIES*> range_properties;
-  hb_auto_array_t<int> range_char_counts;
+  hb_auto_t<hb_vector_t<TEXTRANGE_PROPERTIES*> > range_properties;
+  hb_auto_t<hb_vector_t<int> > range_char_counts;
 
   unsigned int glyphs_offset = 0;
   unsigned int glyphs_len;
@@ -907,8 +900,8 @@ retry:
                                     &items[i].a,
                                     script_tags[i],
                                     language_tag,
-                                    range_char_counts.array,
-                                    range_properties.array,
+                                    range_char_counts.arrayZ,
+                                    range_properties.arrayZ,
                                     range_properties.len,
                                     pchars + chars_offset,
                                     item_chars_len,
@@ -948,8 +941,8 @@ retry:
                                     &items[i].a,
                                     script_tags[i],
                                     language_tag,
-                                    range_char_counts.array,
-                                    range_properties.array,
+                                    range_char_counts.arrayZ,
+                                    range_properties.arrayZ,
                                     range_properties.len,
                                     pchars + chars_offset,
                                     log_clusters + chars_offset,