diff --git a/src/hb-common.cc b/src/hb-common.cc index a089e52cd..a6a514479 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -234,7 +234,7 @@ struct hb_language_item_t { static hb_language_item_t *langs; -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT static inline void free_langs (void) { @@ -269,7 +269,7 @@ retry: goto retry; } -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT if (!first_lang) atexit (free_langs); /* First person registers atexit() callback. */ #endif diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 44e0b0bc2..16bf51f56 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -455,7 +455,7 @@ retry: goto retry; } -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT atexit (free_ft_library); /* First person registers atexit() callback. */ #endif } diff --git a/src/hb-private.hh b/src/hb-private.hh index 5a4ca6991..1b39e5731 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -130,6 +130,31 @@ # define STRICT #endif +#if HAVE_ATEXIT +/* atexit() is only safe to be called from shared libraries on certain + * platforms. Whitelist. + * https://bugs.freedesktop.org/show_bug.cgi?id=82246 */ +# if defined(__linux) && defined(__GLIBC_PREREQ) +# if __GLIBC_PREREQ(2,3) +/* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */ +# define HB_USE_ATEXIT 1 +# endif +# elif defined(_MSC_VER) || defined(__MINGW32__) +/* For MSVC: + * http://msdn.microsoft.com/en-ca/library/tze57ck3.aspx + * http://msdn.microsoft.com/en-ca/library/zk17ww08.aspx + * mingw32 headers say atexit is safe to use in shared libraries. + */ +# define HB_USE_ATEXIT 1 +# elif defined(__ANDROID__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +/* This was fixed in Android NKD r8 or r8b: + * https://code.google.com/p/android/issues/detail?id=6455 + * which introduced GCC 4.6: + * https://developer.android.com/tools/sdk/ndk/index.html + */ +# define HB_USE_ATEXIT 1 +# endif +#endif /* Basics */ diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 812cf5919..74747f88b 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -320,7 +320,7 @@ retry: goto retry; } -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT atexit (free_static_shaper_list); /* First person registers atexit() callback. */ #endif } diff --git a/src/hb-shaper.cc b/src/hb-shaper.cc index 44f718aa7..6ae260138 100644 --- a/src/hb-shaper.cc +++ b/src/hb-shaper.cc @@ -100,7 +100,7 @@ retry: goto retry; } -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT atexit (free_static_shapers); /* First person registers atexit() callback. */ #endif } diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc index 6bf87a5f4..0a2b48163 100644 --- a/src/hb-uniscribe.cc +++ b/src/hb-uniscribe.cc @@ -245,7 +245,7 @@ retry: goto retry; } -#ifdef HAVE_ATEXIT +#ifdef HB_USE_ATEXIT atexit (free_uniscribe_funcs); /* First person registers atexit() callback. */ #endif }