Call atexit() via hb_atexit()

Part of https://github.com/harfbuzz/harfbuzz/issues/3197
This commit is contained in:
Behdad Esfahbod 2021-09-14 07:09:54 -04:00
parent ad4df20dd6
commit ed1163208d
10 changed files with 41 additions and 90 deletions

View File

@ -280,8 +280,7 @@ struct hb_language_item_t {
static hb_atomic_ptr_t <hb_language_item_t> langs;
#if HB_USE_ATEXIT
static void
static inline void
free_langs ()
{
retry:
@ -296,7 +295,6 @@ retry:
first_lang = next;
}
}
#endif
static hb_language_item_t *
lang_find_or_insert (const char *key)
@ -327,10 +325,8 @@ retry:
goto retry;
}
#if HB_USE_ATEXIT
if (!first_lang)
atexit (free_langs); /* First person registers atexit() callback. */
#endif
hb_atexit (free_langs); /* First person registers atexit() callback. */
return lang;
}

View File

@ -561,9 +561,7 @@ hb_ft_get_font_h_extents (hb_font_t *font HB_UNUSED,
return true;
}
#if HB_USE_ATEXIT
static void free_static_ft_funcs ();
#endif
static inline void free_static_ft_funcs ();
static struct hb_ft_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ft_font_funcs_lazy_loader_t>
{
@ -591,21 +589,17 @@ static struct hb_ft_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ft
hb_font_funcs_make_immutable (funcs);
#if HB_USE_ATEXIT
atexit (free_static_ft_funcs);
#endif
hb_atexit (free_static_ft_funcs);
return funcs;
}
} static_ft_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_ft_funcs ()
{
static_ft_funcs.free_instance ();
}
#endif
static hb_font_funcs_t *
_hb_ft_get_font_funcs ()
@ -905,9 +899,7 @@ hb_ft_font_create_referenced (FT_Face ft_face)
return hb_ft_font_create (ft_face, _hb_ft_face_destroy);
}
#if HB_USE_ATEXIT
static void free_static_ft_library ();
#endif
static inline void free_static_ft_library ();
static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<FT_Library>,
hb_ft_library_lazy_loader_t>
@ -918,9 +910,7 @@ static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<F
if (FT_Init_FreeType (&l))
return nullptr;
#if HB_USE_ATEXIT
atexit (free_static_ft_library);
#endif
hb_atexit (free_static_ft_library);
return l;
}
@ -934,13 +924,11 @@ static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t<hb_remove_pointer<F
}
} static_ft_library;
#if HB_USE_ATEXIT
static
static inline
void free_static_ft_library ()
{
static_ft_library.free_instance ();
}
#endif
static FT_Library
get_ft_library ()

View File

@ -218,9 +218,7 @@ hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
}
#if HB_USE_ATEXIT
static void free_static_glib_funcs ();
#endif
static inline void free_static_glib_funcs ();
static struct hb_glib_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_glib_unicode_funcs_lazy_loader_t>
{
@ -237,21 +235,17 @@ static struct hb_glib_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader
hb_unicode_funcs_make_immutable (funcs);
#if HB_USE_ATEXIT
atexit (free_static_glib_funcs);
#endif
hb_atexit (free_static_glib_funcs);
return funcs;
}
} static_glib_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_glib_funcs ()
{
static_glib_funcs.free_instance ();
}
#endif
/**
* hb_glib_get_unicode_funcs:

View File

@ -233,9 +233,7 @@ hb_icu_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
}
#if HB_USE_ATEXIT
static void free_static_icu_funcs ();
#endif
static inline void free_static_icu_funcs ();
static struct hb_icu_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_icu_unicode_funcs_lazy_loader_t>
{
@ -257,21 +255,17 @@ static struct hb_icu_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_
hb_unicode_funcs_make_immutable (funcs);
#if HB_USE_ATEXIT
atexit (free_static_icu_funcs);
#endif
hb_atexit (free_static_icu_funcs);
return funcs;
}
} static_icu_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_icu_funcs ()
{
static_icu_funcs.free_instance ();
}
#endif
/**
* hb_icu_get_unicode_funcs:

View File

@ -253,9 +253,7 @@ hb_ot_get_font_v_extents (hb_font_t *font,
_hb_ot_metrics_get_position_common (font, HB_OT_METRICS_TAG_VERTICAL_LINE_GAP, &metrics->line_gap);
}
#if HB_USE_ATEXIT
static void free_static_ot_funcs ();
#endif
static inline void free_static_ot_funcs ();
static struct hb_ot_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ot_font_funcs_lazy_loader_t>
{
@ -281,21 +279,17 @@ static struct hb_ot_font_funcs_lazy_loader_t : hb_font_funcs_lazy_loader_t<hb_ot
hb_font_funcs_make_immutable (funcs);
#if HB_USE_ATEXIT
atexit (free_static_ot_funcs);
#endif
hb_atexit (free_static_ot_funcs);
return funcs;
}
} static_ot_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_ot_funcs ()
{
static_ot_funcs.free_instance ();
}
#endif
static hb_font_funcs_t *
_hb_ot_get_font_funcs ()

View File

@ -48,9 +48,7 @@
**/
#if HB_USE_ATEXIT
static void free_static_shaper_list ();
#endif
static inline void free_static_shaper_list ();
static const char *nil_shaper_list[] = {nullptr};
@ -69,9 +67,7 @@ static struct hb_shaper_list_lazy_loader_t : hb_lazy_loader_t<const char *,
shaper_list[i] = shapers[i].name;
shaper_list[i] = nullptr;
#if HB_USE_ATEXIT
atexit (free_static_shaper_list);
#endif
hb_atexit (free_static_shaper_list);
return shaper_list;
}
@ -81,13 +77,11 @@ static struct hb_shaper_list_lazy_loader_t : hb_lazy_loader_t<const char *,
{ return nil_shaper_list; }
} static_shaper_list;
#if HB_USE_ATEXIT
static
static inline
void free_static_shaper_list ()
{
static_shaper_list.free_instance ();
}
#endif
/**

View File

@ -38,9 +38,7 @@ static const hb_shaper_entry_t all_shapers[] = {
static_assert (0 != ARRAY_LENGTH_CONST (all_shapers), "No shaper enabled.");
#endif
#if HB_USE_ATEXIT
static void free_static_shapers ();
#endif
static inline void free_static_shapers ();
static struct hb_shapers_lazy_loader_t : hb_lazy_loader_t<const hb_shaper_entry_t,
hb_shapers_lazy_loader_t>
@ -83,9 +81,7 @@ static struct hb_shapers_lazy_loader_t : hb_lazy_loader_t<const hb_shaper_entry_
p = end + 1;
}
#if HB_USE_ATEXIT
atexit (free_static_shapers);
#endif
hb_atexit (free_static_shapers);
return shapers;
}
@ -93,13 +89,11 @@ static struct hb_shapers_lazy_loader_t : hb_lazy_loader_t<const hb_shaper_entry_
static const hb_shaper_entry_t *get_null () { return all_shapers; }
} static_shapers;
#if HB_USE_ATEXIT
static
static inline
void free_static_shapers ()
{
static_shapers.free_instance ();
}
#endif
const hb_shaper_entry_t *
_hb_shapers_get ()

View File

@ -203,9 +203,7 @@ hb_ucd_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED,
}
#if HB_USE_ATEXIT
static void free_static_ucd_funcs ();
#endif
static struct hb_ucd_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_t<hb_ucd_unicode_funcs_lazy_loader_t>
{
@ -222,21 +220,17 @@ static struct hb_ucd_unicode_funcs_lazy_loader_t : hb_unicode_funcs_lazy_loader_
hb_unicode_funcs_make_immutable (funcs);
#if HB_USE_ATEXIT
atexit (free_static_ucd_funcs);
#endif
hb_atexit (free_static_ucd_funcs);
return funcs;
}
} static_ucd_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_ucd_funcs ()
{
static_ucd_funcs.free_instance ();
}
#endif
hb_unicode_funcs_t *
hb_ucd_get_unicode_funcs ()

View File

@ -239,9 +239,7 @@ struct hb_uniscribe_shaper_funcs_t
}
};
#if HB_USE_ATEXIT
static void free_static_uniscribe_shaper_funcs ();
#endif
static inline void free_static_uniscribe_shaper_funcs ();
static struct hb_uniscribe_shaper_funcs_lazy_loader_t : hb_lazy_loader_t<hb_uniscribe_shaper_funcs_t,
hb_uniscribe_shaper_funcs_lazy_loader_t>
@ -254,9 +252,7 @@ static struct hb_uniscribe_shaper_funcs_lazy_loader_t : hb_lazy_loader_t<hb_unis
funcs->init ();
#if HB_USE_ATEXIT
atexit (free_static_uniscribe_shaper_funcs);
#endif
hb_atexit (free_static_uniscribe_shaper_funcs);
return funcs;
}
@ -270,13 +266,11 @@ static struct hb_uniscribe_shaper_funcs_lazy_loader_t : hb_lazy_loader_t<hb_unis
}
} static_uniscribe_shaper_funcs;
#if HB_USE_ATEXIT
static
static inline
void free_static_uniscribe_shaper_funcs ()
{
static_uniscribe_shaper_funcs.free_instance ();
}
#endif
static hb_uniscribe_shaper_funcs_t *
hb_uniscribe_shaper_get_funcs ()

View File

@ -405,6 +405,9 @@ static int HB_UNUSED _hb_errno = 0;
# define errno _hb_errno
#endif
#define HB_STMT_START do
#define HB_STMT_END while (0)
#if defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT)
/* atexit() is only safe to be called from shared libraries on certain
* platforms. Whitelist.
@ -433,16 +436,22 @@ static int HB_UNUSED _hb_errno = 0;
*/
# define HB_USE_ATEXIT 1
# endif
#endif
#endif /* defined(HAVE_ATEXIT) && !defined(HB_USE_ATEXIT) */
#ifdef HB_NO_ATEXIT
# undef HB_USE_ATEXIT
#endif
#ifndef HB_USE_ATEXIT
# define HB_USE_ATEXIT 0
#endif
#define HB_STMT_START do
#define HB_STMT_END while (0)
#if !HB_USE_ATEXIT
# define hb_atexit(_) HB_STMT_START { if (0) (_) (); } HB_STMT_END
#else /* HB_USE_ATEXIT */
# ifdef HAVE_ATEXIT
# define hb_atexit atexit
# else
# error "atexit not found."
# endif
#endif
/* Lets assert int types. Saves trouble down the road. */
static_assert ((sizeof (hb_codepoint_t) == 4), "");