Revert "[glib/ucdn/icu/ft/ot] Make returned funcs inert"
authorBehdad Esfahbod <behdad@behdad.org>
Tue, 14 Nov 2017 18:59:54 +0000 (10:59 -0800)
committerBehdad Esfahbod <behdad@behdad.org>
Tue, 14 Nov 2017 18:59:54 +0000 (10:59 -0800)
This reverts commit 5daf3bd4494cce6b4fb074533be9e99c4d9e0edd.

If other atexit callbacks try to destruct the objects we destruct
in atexit callbacks, bad things will happen.

I'll come up with some other way to catch premature destruction
of HB-owned objects.

Fixes https://github.com/behdad/harfbuzz/issues/618

src/hb-ft.cc
src/hb-glib.cc
src/hb-icu.cc
src/hb-object-private.hh
src/hb-ot-font.cc
src/hb-ucdn.cc

index 68c7745471653cddc9bcb8250077576c727971ad..0f15f8c3d0fca0f9a7157af1c539fe333ce7e30f 100644 (file)
@@ -423,7 +423,6 @@ static hb_font_funcs_t *static_ft_funcs = nullptr;
 static
 void free_static_ft_funcs (void)
 {
-  hb_object_undo_inert (static_ft_funcs);
   hb_font_funcs_destroy (static_ft_funcs);
 }
 #endif
@@ -454,10 +453,8 @@ retry:
     hb_font_funcs_set_glyph_from_name_func (funcs, hb_ft_get_glyph_from_name, nullptr, nullptr);
 
     hb_font_funcs_make_immutable (funcs);
-    hb_object_make_inert (funcs);
 
     if (!hb_atomic_ptr_cmpexch (&static_ft_funcs, nullptr, funcs)) {
-      hb_object_undo_inert (funcs);
       hb_font_funcs_destroy (funcs);
       goto retry;
     }
index 31de68e864471fc1b483053909dbc62cfa07382c..50c30e9c7b9beb042604307b4a56ce7be561c29d 100644 (file)
@@ -370,7 +370,6 @@ static hb_unicode_funcs_t *static_glib_funcs = nullptr;
 static
 void free_static_glib_funcs (void)
 {
-  hb_object_undo_inert (static_glib_funcs);
   hb_unicode_funcs_destroy (static_glib_funcs);
 }
 #endif
@@ -391,10 +390,8 @@ retry:
 #undef HB_UNICODE_FUNC_IMPLEMENT
 
     hb_unicode_funcs_make_immutable (funcs);
-    hb_object_make_inert (funcs);
 
     if (!hb_atomic_ptr_cmpexch (&static_glib_funcs, nullptr, funcs)) {
-      hb_object_undo_inert (funcs);
       hb_unicode_funcs_destroy (funcs);
       goto retry;
     }
index 44a198937b0f71e76e4d025e07b9c5ee0fffe9cd..552eaeca51ea5264a6fe9003900a7fae0bd2c6a3 100644 (file)
@@ -351,7 +351,6 @@ static hb_unicode_funcs_t *static_icu_funcs = nullptr;
 static
 void free_static_icu_funcs (void)
 {
-  hb_object_undo_inert (static_icu_funcs);
   hb_unicode_funcs_destroy (static_icu_funcs);
 }
 #endif
@@ -380,10 +379,8 @@ retry:
 #undef HB_UNICODE_FUNC_IMPLEMENT
 
     hb_unicode_funcs_make_immutable (funcs);
-    hb_object_make_inert (funcs);
 
     if (!hb_atomic_ptr_cmpexch (&static_icu_funcs, nullptr, funcs)) {
-      hb_object_undo_inert (funcs);
       hb_unicode_funcs_destroy (funcs);
       goto retry;
     }
index 0dada492c9439ba21e69374843b3780f7761fa1a..baa1f8f05cc3f3b4358c45c784717215f822810a 100644 (file)
 
 /* reference_count */
 
-#define HB_REFERENCE_COUNT_UNCHANGABLE_VALUE   -0x53043
-#define HB_REFERENCE_COUNT_UNREFFABLE_VALUE    -0x07734
-#define HB_REFERENCE_COUNT_UNTOUCHABLE_VALUE   -0xBEDAD
-#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT (HB_REFERENCE_COUNT_UNCHANGABLE_VALUE)}
+#define HB_REFERENCE_COUNT_INERT_VALUE -1
+#define HB_REFERENCE_COUNT_POISON_VALUE -0x0000DEAD
+#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT(HB_REFERENCE_COUNT_INERT_VALUE)}
 
 struct hb_reference_count_t
 {
@@ -54,23 +53,9 @@ struct hb_reference_count_t
   inline int get_unsafe (void) const { return ref_count.get_unsafe (); }
   inline int inc (void) { return ref_count.inc (); }
   inline int dec (void) { return ref_count.dec (); }
-  inline void finish (void) { ref_count.set_unsafe (HB_REFERENCE_COUNT_UNTOUCHABLE_VALUE); }
-
-  inline void make_inert (void)
-  {
-    if (get_unsafe () == HB_REFERENCE_COUNT_UNCHANGABLE_VALUE)
-      return;
-    ref_count.set_unsafe (HB_REFERENCE_COUNT_UNREFFABLE_VALUE);
-  }
-  inline void undo_inert (void)
-  {
-    if (get_unsafe () == HB_REFERENCE_COUNT_UNCHANGABLE_VALUE)
-      return;
-    assert (get_unsafe () == HB_REFERENCE_COUNT_UNREFFABLE_VALUE);
-    ref_count.set_unsafe (1);
-  }
-
-  inline bool is_inert (void) const { return ref_count.get_unsafe () < 0; }
+  inline void finish (void) { ref_count.set_unsafe (HB_REFERENCE_COUNT_POISON_VALUE); }
+
+  inline bool is_inert (void) const { return ref_count.get_unsafe () == HB_REFERENCE_COUNT_INERT_VALUE; }
   inline bool is_valid (void) const { return ref_count.get_unsafe () > 0; }
 };
 
@@ -161,16 +146,6 @@ static inline bool hb_object_is_valid (const Type *obj)
   return likely (obj->header.ref_count.is_valid ());
 }
 template <typename Type>
-static inline void hb_object_make_inert (Type *obj)
-{
-  obj->header.ref_count.make_inert ();
-}
-template <typename Type>
-static inline void hb_object_undo_inert (Type *obj)
-{
-  obj->header.ref_count.undo_inert ();
-}
-template <typename Type>
 static inline Type *hb_object_reference (Type *obj)
 {
   hb_object_trace (obj, HB_FUNC);
index 72d3c583618029ec57878d64721a883e19beb8bf..47416012c9d860e810c1b3adc99275cfaaeea7cf 100644 (file)
@@ -663,7 +663,6 @@ static hb_font_funcs_t *static_ot_funcs = nullptr;
 static
 void free_static_ot_funcs (void)
 {
-  hb_object_undo_inert (static_ot_funcs);
   hb_font_funcs_destroy (static_ot_funcs);
 }
 #endif
@@ -694,10 +693,8 @@ retry:
     hb_font_funcs_set_glyph_from_name_func (funcs, hb_ot_get_glyph_from_name, nullptr, nullptr);
 
     hb_font_funcs_make_immutable (funcs);
-    hb_object_make_inert (funcs);
 
     if (!hb_atomic_ptr_cmpexch (&static_ot_funcs, nullptr, funcs)) {
-      hb_object_undo_inert (funcs);
       hb_font_funcs_destroy (funcs);
       goto retry;
     }
index 99266724fbf2641313d5c0526b638c6f37cb4768..9515bda256737190f7b37f4ad79f5e133e140860 100644 (file)
@@ -237,7 +237,6 @@ static hb_unicode_funcs_t *static_ucdn_funcs = nullptr;
 static
 void free_static_ucdn_funcs (void)
 {
-  hb_object_undo_inert (static_ucdn_funcs);
   hb_unicode_funcs_destroy (static_ucdn_funcs);
 }
 #endif
@@ -259,10 +258,8 @@ retry:
 #undef HB_UNICODE_FUNC_IMPLEMENT
 
     hb_unicode_funcs_make_immutable (funcs);
-    hb_object_make_inert (funcs);
 
     if (!hb_atomic_ptr_cmpexch (&static_ucdn_funcs, nullptr, funcs)) {
-      hb_object_undo_inert (funcs);
       hb_unicode_funcs_destroy (funcs);
       goto retry;
     }