Commit b8dab057 authored by Jean-Baptiste Mazon's avatar Jean-Baptiste Mazon Committed by Marge Bot
Browse files

rts: ensure C numerics in heap profiles using Windows locales if needed

parent 8eb2c263
......@@ -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();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment