diff options
author | PHO <pho@cielonegro.org> | 2021-05-05 15:29:36 +0900 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-12-01 03:07:32 -0500 |
commit | c7613493e637718492f03c2f9a020198244a7b18 (patch) | |
tree | 3ef38e0d76fefa6c8e199cc916a74f8d86ac4271 /rts/ProfHeap.c | |
parent | 9345bfeda8f463d3fc79054166cb90fe89ea3469 (diff) | |
download | haskell-c7613493e637718492f03c2f9a020198244a7b18.tar.gz |
rts/ProfHeap.c: Use setlocale() on platforms where uselocale() is not available
Not all platforms have per-thread locales. NetBSD doesn't have uselocale() in particular. Using setlocale() is of course not a safe thing to do, but it would be better than no GHC at all.
Diffstat (limited to 'rts/ProfHeap.c')
-rw-r--r-- | rts/ProfHeap.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index e9d9dd364e..82d9059f24 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -52,6 +52,10 @@ static char *hp_filename; /* heap profile (hp2ps style) log file */ * As an exception for Darwin, this comes through the <xlocale.h> header instead * of <locale.h>. * + * On platforms which don't have uselocale(3), we fall back to setlocale() which + * mutates the global state. This is of course not thread-safe but is better + * than nothing. + * * On Windows, a different _locale_t opaque type does exist, but isn't directly * usable without special-casing all printf() and related calls, which I'm not * motivated to trawl through as I don't even have a Windows box to test on. @@ -63,14 +67,16 @@ static char *hp_filename; /* heap profile (hp2ps style) log file */ #if defined(mingw32_HOST_OS) static int prof_locale_per_thread = -1; static const char *saved_locale = NULL; -#else +#elif defined(HAVE_USELOCALE) static locale_t prof_locale = 0, saved_locale = 0; +#else +static char *saved_locale = NULL; #endif STATIC_INLINE void init_prof_locale( void ) { -#if !defined(mingw32_HOST_OS) +#if defined(HAVE_USELOCALE) if (! prof_locale) { prof_locale = newlocale(LC_NUMERIC_MASK, "POSIX", 0); if (! prof_locale) { @@ -84,7 +90,7 @@ init_prof_locale( void ) STATIC_INLINE void free_prof_locale( void ) { -#if !defined(mingw32_HOST_OS) +#if defined(HAVE_USELOCALE) if (prof_locale) { freelocale(prof_locale); prof_locale = 0; @@ -99,8 +105,11 @@ set_prof_locale( void ) prof_locale_per_thread = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); saved_locale = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); -#else +#elif defined(HAVE_USELOCALE) saved_locale = uselocale(prof_locale); +#else + saved_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); #endif } @@ -110,8 +119,10 @@ restore_locale( void ) #if defined(mingw32_HOST_OS) _configthreadlocale(prof_locale_per_thread); setlocale(LC_NUMERIC, saved_locale); -#else +#elif defined(HAVE_USELOCALE) uselocale(saved_locale); +#else + setlocale(LC_NUMERIC, saved_locale); #endif } |