diff -r 7fba7ef21117 -r f104ace19a51 src/backend/APT/APTRanges.cpp
--- src/backend/APT/APTRanges.cpp Sat Jan 18 17:45:15 2014 +0100
+++ src/backend/APT/APTRanges.cpp Wed Feb 05 22:08:32 2014 +0100
@@ -26,7 +26,6 @@
#include <map>
#include <fstream>
-#include <clocale>
#include <numeric>
#include <cstring>
@@ -484,15 +483,7 @@
}
- //switch to "C" style decimal notation (English),
- //as needed
- char *oldLocale=setlocale(LC_NUMERIC,NULL);
-
- //setlocale reserves the right to trash the returned pointer
- //on subsequent calls (it totally makes sense, or something..).
- oldLocale=strdup(oldLocale);
- if(strcmp(oldLocale,"C"))
- setlocale(LC_NUMERIC,"C");
+ pushLocale("C",LC_NUMERIC);
size_t errCode;
switch(fileFormat)
@@ -521,31 +512,19 @@
default:
ASSERT(false);
fclose(fpRange);
- if(strcmp(oldLocale,"C"))
- setlocale(LC_NUMERIC,oldLocale);
- free(oldLocale);
+ popLocale();
return RANGE_ERR_FORMAT;
}
+ popLocale();
fclose(fpRange);
if(errCode)
{
errState=errCode;
-
- if(strcmp(oldLocale,"C"))
- setlocale(LC_NUMERIC,oldLocale);
- free(oldLocale);
return errState;
}
- //revert back to user's locale, as needed
- if(strcmp(oldLocale,"C"))
- setlocale(LC_NUMERIC,oldLocale);
-
- free(oldLocale);
-
-
//Run self consistency check on freshly loaded data
if(!isSelfConsistent())
{
diff -r 7fba7ef21117 -r f104ace19a51 src/backend/filters/transform.cpp
--- src/backend/filters/transform.cpp Sat Jan 18 17:45:15 2014 +0100
+++ src/backend/filters/transform.cpp Wed Feb 05 22:08:32 2014 +0100
@@ -1110,7 +1110,15 @@
return ERR_CALLBACK_FAIL;
}
//Shuffle the value data.TODO: callback functor
+
+#ifndef HAVE_CPP1X
+ std::srand(time(0));
std::random_shuffle(massData.begin(),massData.end());
+#else
+ std::mt19937_64 r;
+ r.seed(time(0));
+ std::shuffle(massData.begin(),massData.end(),r);
+#endif
if(!(*callback)(true))
{
delete d;
diff -r 7fba7ef21117 -r f104ace19a51 src/common/basics.cpp
--- src/common/basics.cpp Sat Jan 18 17:45:15 2014 +0100
+++ src/common/basics.cpp Wed Feb 05 22:08:32 2014 +0100
@@ -41,6 +41,9 @@
#include <sys/stat.h>
#endif
+#include <cstring>
+#include <clocale>
+
using std::string;
using std::vector;
using std::list;
@@ -65,6 +68,9 @@
//default font to use.
std::string defaultFontFile;
+static char *oldLocaleStatic;
+static int localeStaticType;
+
unsigned int getBitNum(unsigned int u)
{
ASSERT(u);
@@ -86,6 +92,45 @@
return "0";
}
+void pushLocale(const char *newLocale, int type)
+{
+ ASSERT(!oldLocaleStatic);
+ ASSERT(!localeStaticType);
+
+ ASSERT(type == LC_NUMERIC || type == LC_MONETARY || type == LC_CTYPE
+ || type == LC_COLLATE || type == LC_ALL || type == LC_TIME
+ || type== LC_MESSAGES);
+
+ oldLocaleStatic=setlocale(type,NULL);
+
+ //setlocale reserves the right to trash the returned pointer
+ // on subsequent calls (i.e. use the returned pointer for later)
+ // thus we must duplicate the pointer to own it
+ oldLocaleStatic=strdup(oldLocaleStatic);
+ if(strcmp(oldLocaleStatic,newLocale))
+ {
+ setlocale(type,newLocale);
+ localeStaticType=type;
+ }
+ else
+ {
+ //record that we did not set this
+ localeStaticType=-1;
+ }
+
+}
+
+void popLocale()
+{
+ if(localeStaticType != -1)
+ setlocale(localeStaticType,oldLocaleStatic);
+
+ localeStaticType=0;
+
+ free(oldLocaleStatic);
+ oldLocaleStatic=0;
+}
+
bool dummyCallback(bool)
{
diff -r 7fba7ef21117 -r f104ace19a51 src/common/basics.h
--- src/common/basics.h Sat Jan 18 17:45:15 2014 +0100
+++ src/common/basics.h Wed Feb 05 22:08:32 2014 +0100
@@ -42,6 +42,13 @@
extern const char *FONT_FILE;
+//Set new locale code. Must be followed by a popLocale call before completion
+// Only one locale type can be pushed at a time this way
+void pushLocale(const char *newLocale, int type);
+
+//Restore old locale code
+void popLocale();
+
//C file peek function
diff -r 7fba7ef21117 -r f104ace19a51 src/gui/mathglPane.cpp
--- src/gui/mathglPane.cpp Sat Jan 18 17:45:15 2014 +0100
+++ src/gui/mathglPane.cpp Wed Feb 05 22:08:32 2014 +0100
@@ -27,7 +27,6 @@
#ifdef USE_MGL2
#include <mgl2/canvas_wnd.h>
- #include <mgl2/canvas_wnd.h>
#else
#include <mgl/mgl_eps.h>
#endif
@@ -1091,7 +1090,13 @@
grS->SetWarn(0);
grS->Message=mglWarnMsgBuf;
#endif
+
+ //Mathgl does not set locale prior to writing SVG
+ // do this by hand
+ pushLocale("C",LC_NUMERIC);
grS->WriteSVG(filename.c_str());
+ popLocale();
+
bool doWarn;
#ifdef USE_MGL2