changeset 303:15b47d30c085

* Ensure locale from environment is retained after plugin load, not just C locale
author Chris Cannam
date Fri, 05 Oct 2007 13:26:47 +0000
parents 726b32522e3f
children 4fc6f49436b3
files plugin/RealTimePluginFactory.cpp system/System.cpp system/System.h
diffstat 3 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/RealTimePluginFactory.cpp	Thu Oct 04 16:34:11 2007 +0000
+++ b/plugin/RealTimePluginFactory.cpp	Fri Oct 05 13:26:47 2007 +0000
@@ -25,6 +25,8 @@
 #include "LADSPAPluginFactory.h"
 #include "DSSIPluginFactory.h"
 
+#include "system/System.h"
+
 #include <iostream>
 
 int RealTimePluginFactory::m_sampleRate = 48000;
@@ -98,7 +100,8 @@
     }
 
     // Plugins can change the locale, revert it to default.
-    setlocale(LC_ALL, "C");
+    RestoreStartupLocale();
+
     return rv;
 }
 
--- a/system/System.cpp	Thu Oct 04 16:34:11 2007 +0000
+++ b/system/System.cpp	Fri Oct 05 13:26:47 2007 +0000
@@ -265,7 +265,27 @@
     }
 #endif
 }
-    
+
+static char *startupLocale = 0;
+
+void
+StoreStartupLocale()
+{
+    char *loc = setlocale(LC_ALL, 0);
+    if (!loc) return;
+    if (startupLocale) free(startupLocale);
+    startupLocale = strdup(loc);
+}
+
+void
+RestoreStartupLocale()
+{
+    if (!startupLocale) {
+        setlocale(LC_ALL, "");
+    } else {
+        setlocale(LC_ALL, startupLocale);
+    }
+}
 
 double mod(double x, double y) { return x - (y * floor(x / y)); }
 float modf(float x, float y) { return x - (y * floorf(x / y)); }
--- a/system/System.h	Thu Oct 04 16:34:11 2007 +0000
+++ b/system/System.h	Fri Oct 05 13:26:47 2007 +0000
@@ -105,6 +105,9 @@
 // on the partition containing the given path.  Return -1 if unknown.
 extern int GetDiscSpaceMBAvailable(const char *path);
 
+extern void StoreStartupLocale();
+extern void RestoreStartupLocale();
+
 #include <cmath>
 
 extern double mod(double x, double y);