From b8dab057f0730a324b7cb7b74a11152f6b96a889 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mazon Date: Tue, 25 Feb 2020 12:00:33 +0100 Subject: rts: ensure C numerics in heap profiles using Windows locales if needed --- rts/ProfHeap.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'rts/ProfHeap.c') 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 #include -#if !defined(mingw32_HOST_OS) #if defined(darwin_HOST_OS) #include #else #include #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(); } -- cgit v1.2.1