summaryrefslogtreecommitdiff
path: root/rts/ProfHeap.c
diff options
context:
space:
mode:
authorJean-Baptiste Mazon <jmazon+haskell@gmail.com>2020-02-25 12:00:33 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-29 05:10:46 -0500
commit252e51179bd179f52e25dea762ef7b95bc56ce0a (patch)
tree626139a6edb317b62cff48b293446173c181fcbb /rts/ProfHeap.c
parent0f55df7f197b7e30d7c6e39d80deb36b7dc86fb5 (diff)
downloadhaskell-252e51179bd179f52e25dea762ef7b95bc56ce0a.tar.gz
rts: enforce POSIX numeric locale for heap profiles
Diffstat (limited to 'rts/ProfHeap.c')
-rw-r--r--rts/ProfHeap.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index 4f82b0ba83..bc439c1678 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -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);
}