diff options
author | Jean-Baptiste Mazon <jmazon+haskell@gmail.com> | 2020-02-25 12:00:33 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-09 16:33:37 -0400 |
commit | b8dab057f0730a324b7cb7b74a11152f6b96a889 (patch) | |
tree | caac3b03313b2fa3c3f6f6b7cb8264d1ca7bd13e /rts/ProfHeap.c | |
parent | 8eb2c2639494bed3326163df52fa13de941cd047 (diff) | |
download | haskell-b8dab057f0730a324b7cb7b74a11152f6b96a889.tar.gz |
rts: ensure C numerics in heap profiles using Windows locales if needed
Diffstat (limited to 'rts/ProfHeap.c')
-rw-r--r-- | rts/ProfHeap.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c index 38d6b7d433..fd2b32f6d5 100644 --- a/rts/ProfHeap.c +++ b/rts/ProfHeap.c @@ -26,21 +26,44 @@ #include <fs_rts.h> #include <string.h> -#if !defined(mingw32_HOST_OS) #if defined(darwin_HOST_OS) #include <xlocale.h> #else #include <locale.h> #endif -#endif FILE *hp_file; static char *hp_filename; /* heap profile (hp2ps style) log file */ -#if !defined(mingw32_HOST_OS) +#if defined(mingw32_HOST_OS) +static int prof_locale_per_thread = -1; +static const char *saved_locale = NULL; +#else static locale_t prof_locale = 0, saved_locale = 0; #endif +STATIC_INLINE void +set_prof_locale( void ) +{ +#if defined(mingw32_HOST_OS) + prof_locale_per_thread = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + saved_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); +#else + saved_locale = uselocale(prof_locale); +#endif +} + +STATIC_INLINE void +restore_locale( void ) +{ +#if defined(mingw32_HOST_OS) + _configthreadlocale(prof_locale_per_thread); + setlocale(LC_NUMERIC, saved_locale); +#else + uselocale(saved_locale); +#endif +} /* ----------------------------------------------------------------------------- * era stores the current time period. It is the same as the * number of censuses that have been performed. @@ -382,8 +405,8 @@ initHeapProfiling(void) /* non-fatal: risk using an unknown locale, but won't crash */ } } - saved_locale = uselocale(prof_locale); #endif + set_prof_locale(); char *prog; @@ -482,9 +505,7 @@ initHeapProfiling(void) } #endif -#if !defined(mingw32_HOST_OS) - uselocale(saved_locale); -#endif + restore_locale(); traceHeapProfBegin(0); } @@ -498,9 +519,7 @@ endHeapProfiling(void) return; } -#if !defined(mingw32_HOST_OS) - saved_locale = uselocale(prof_locale); -#endif + set_prof_locale(); #if defined(PROFILING) if (doingRetainerProfiling()) { @@ -543,9 +562,7 @@ endHeapProfiling(void) printSample(false, seconds); fclose(hp_file); -#if !defined(mingw32_HOST_OS) - uselocale(saved_locale); -#endif + restore_locale(); } @@ -800,9 +817,7 @@ dumpCensus( Census *census ) counter *ctr; ssize_t count; -#if !defined(mingw32_HOST_OS) - saved_locale = uselocale(prof_locale); -#endif + set_prof_locale(); printSample(true, census->time); @@ -933,9 +948,7 @@ dumpCensus( Census *census ) traceHeapProfSampleEnd(era); printSample(false, census->time); -#if !defined(mingw32_HOST_OS) - uselocale(saved_locale); -#endif + restore_locale(); } |