Skip to content
Snippets Groups Projects
Commit d0eef1ad authored by Jean-Baptiste Mazon's avatar Jean-Baptiste Mazon Committed by Jean-Baptiste Mazon
Browse files

rts: enforce POSIX numeric locale for heap profiles

parent 1b1067d1
No related branches found
No related tags found
No related merge requests found
Pipeline #16246 passed with warnings
......@@ -26,8 +26,15 @@
#include <fs_rts.h>
#include <string.h>
#if defined(darwin_HOST_OS)
#include <xlocale.h>
#else
#include <locale.h>
#endif
FILE *hp_file;
static char *hp_filename; /* heap profile (hp2ps style) log file */
static locale_t prof_locale = 0, saved_locale = 0;
/* -----------------------------------------------------------------------------
* era stores the current time period. It is the same as the
......@@ -344,6 +351,10 @@ printSample(bool beginSample, StgDouble sampleValue)
void freeHeapProfiling (void)
{
if (prof_locale) {
freelocale(prof_locale);
prof_locale = 0;
}
}
/* --------------------------------------------------------------------------
......@@ -356,6 +367,15 @@ initHeapProfiling(void)
return;
}
if (! prof_locale) {
prof_locale = newlocale(LC_NUMERIC_MASK, "POSIX", 0);
if (! prof_locale) {
sysErrorBelch("Couldn't allocate heap profiler locale");
/* non-fatal: risk using an unknown locale, but won't crash */
}
}
saved_locale = uselocale(prof_locale);
char *prog;
prog = stgMallocBytes(strlen(prog_name) + 1, "initHeapProfiling");
......@@ -453,6 +473,8 @@ initHeapProfiling(void)
}
#endif
uselocale(saved_locale);
traceHeapProfBegin(0);
}
......@@ -465,6 +487,8 @@ endHeapProfiling(void)
return;
}
saved_locale = uselocale(prof_locale);
#if defined(PROFILING)
if (doingRetainerProfiling()) {
endRetainerProfiling();
......@@ -505,6 +529,8 @@ endHeapProfiling(void)
printSample(true, seconds);
printSample(false, seconds);
fclose(hp_file);
uselocale(saved_locale);
}
......@@ -759,6 +785,8 @@ dumpCensus( Census *census )
counter *ctr;
ssize_t count;
saved_locale = uselocale(prof_locale);
printSample(true, census->time);
......@@ -887,6 +915,8 @@ dumpCensus( Census *census )
traceHeapProfSampleEnd(era);
printSample(false, census->time);
uselocale(saved_locale);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment