gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Tue Apr 30 19:31:02 EDT 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/bfbb89f6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/529a6cb0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d30cf25c (commit)
	from  https://github.com/Gnucash/gnucash/commit/114efe59 (commit)



commit bfbb89f6e28c3cb904a89201cae234af20184577
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Apr 30 15:00:06 2019 -0700

    Rewire and corrected Doxygen comment for gnc_get_locale() c++ function.
    
    There's no point in going through the cache dance on MinGW, that will
    just throw.

diff --git a/libgnucash/core-utils/gnc-locale-utils.cpp b/libgnucash/core-utils/gnc-locale-utils.cpp
index 28678c4e2..b7928e618 100644
--- a/libgnucash/core-utils/gnc-locale-utils.cpp
+++ b/libgnucash/core-utils/gnc-locale-utils.cpp
@@ -27,51 +27,48 @@ extern "C"
 #include <boost/locale.hpp>
 #include "gnc-locale-utils.hpp"
 
-/* This function addresses two separate problems: First, if we set
- * std::locale::global then all streams automagically imbue
- * themselves with it and we have to re-imbue all of the backends and
- * logging streams with std::locale::classic() so that data and log
- * files aren't localized. Second, calling std::locale("") is slow,
- * so we want to do it only once. Worse, the standard C++ library in
- * Mingw64 chokes on at least some Microsoft-style locale strings
- * (e.g. "Spanish_Spain") but libc's setlocale(LC_ALL, NULL) emits
- * them even if originally fed a Unix-style locale ("es_ES").
+/** Cache the UI locale
  *
- * The solution is this function which caches the setlocale() locale
- * the first time it's called and which uses a boost::locale
- * generator, which does know what to do with (sometimes adjusted)
- * Microsoft locale strings.
+ * We don't want to set the default locale because we need
+ * std::locale::classic for consistency in stored data. We also don't
+ * want to call std::locale("") more than once, it's slow... and we
+ * don't want to call it on MinGW32 at all because that supports only
+ * std::locale::classic and throws if you try to construct anything
+ * else. Boost::locale doesn't support std::locale::facet required by
+ * boost::datetime (go figure).
+ *
+ * @return a copy of std::locale::classic() on MinGW32 and a copy of
+ * the cached result of std::locale("") otherwise.
  */
 const std::locale&
 gnc_get_locale()
 {
-  static std::locale cached;
-  static bool tried_already = false;
-  if (!tried_already)
-  {
-    boost::locale::generator gen;
-    tried_already = true;
-      try
-      {
-	cached = std::locale("");
-      }
-      catch (const std::runtime_error& err)
-      {
 #ifdef __MINGW32__
-	  char* locale = g_win32_getlocale();
+    return std::locale::classic(); // Nothing else supported.
 #else
-	  char* locale = g_strdup(setlocale(LC_ALL, ""));
-#endif
+    static std::locale cached;
+    static bool tried_already = false;
+    if (!tried_already)
+    {
+	tried_already = true;
+	try
+	{
+	    cached = std::locale("");
+	}
+	catch (const std::runtime_error& err)
+	{
+	    char* locale = g_strdup(setlocale(LC_ALL, ""));
 
-	  g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
-		"Failed to create C++ default locale from"
-		"%s because %s. Using the 'C' locale for C++.",
-		locale, err.what());
-	  g_free(locale);
-	  cached = std::locale::classic();
-      }
-  }
-  return cached;
+	    g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+		  "Failed to create C++ default locale from"
+		  "%s because %s. Using the 'C' locale for C++.",
+		  locale, err.what());
+	    g_free(locale);
+	    cached = std::locale::classic();
+	}
+    }
+    return cached;
+#endif
 }
 
 

commit 529a6cb06735b21528c8cee0a76f7d396c678078
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Apr 30 14:56:43 2019 -0700

    Call setlocale(LC_ALL, "") exactly once.
    
    And in Windows only with the value from the environment if there is one.
    Calling it with "" in Windows ignores the environment and sets it to the
    system settings.

diff --git a/gnucash/gnucash-bin.c b/gnucash/gnucash-bin.c
index a0df6f675..757c24f86 100644
--- a/gnucash/gnucash-bin.c
+++ b/gnucash/gnucash-bin.c
@@ -102,7 +102,7 @@ static const char  *add_quotes_file  = NULL;
 static char        *namespace_regexp = NULL;
 static const char  *file_to_load     = NULL;
 static gchar      **args_remaining   = NULL;
-static     gchar *sys_locale = NULL;
+static gchar       *sys_locale       = NULL;
 
 static GOptionEntry options[] =
 {
@@ -617,23 +617,7 @@ inner_main (void *closure, int argc, char **argv)
 
     main_mod = scm_c_resolve_module("gnucash utilities");
     scm_set_current_module(main_mod);
-#ifdef __MINGW32__
-    /* Guile initialization calls setlocale(LC_ALL, "") which on
-     * windows resets the locale to what the user has set in the
-     * registry. Put it back to what we set from the environment or
-     * environment file.
-     */
-    if (sys_locale)
-    {
-	setlocale (LC_ALL, sys_locale);
-	g_free (sys_locale);
-	sys_locale = NULL;
-    }
-    else
-    {
-	setlocale (LC_ALL, "C");
-    }
-#endif
+
     /* Check whether the settings need a version update */
     gnc_gsettings_version_upgrade ();
 
@@ -927,12 +911,9 @@ main(int argc, char ** argv)
      * To be on the safe side, only do this if not on OS X,
      * to avoid unintentionally messing up the locale settings */
     PINFO ("System locale returned %s", sys_locale ? sys_locale : "(null)");
-    PINFO ("Effective locale set to %s.", setlocale (LC_ALL, ""));
-#ifndef __MINGW32__
-    /* We need it for later on Windows, see inner_main(). */
+    PINFO ("Effective locale set to %s.", setlocale (LC_ALL, NULL));
     g_free (sys_locale);
     sys_locale = NULL;
-#endif
 #endif
 
     /* If asked via a command line parameter, fetch quotes only */
diff --git a/libgnucash/scm/utilities.scm b/libgnucash/scm/utilities.scm
index 76b09ba51..99e561c8a 100644
--- a/libgnucash/scm/utilities.scm
+++ b/libgnucash/scm/utilities.scm
@@ -50,12 +50,6 @@
 (read-enable 'positions)
 (debug-set! stack    200000)
 
-;; Initalialize localization, otherwise reports may output
-;; invalid characters
-(setlocale LC_ALL "")
-
-;;;; Status output functions.
-
 (define (strify items)
   (string-join (map (lambda (x) (format #f "~A" x)) items) ""))
 

commit d30cf25c456beefb2dd735958cf47da35dd9d237
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Apr 30 14:53:46 2019 -0700

    Call setlocale() with the right form of locale code on Windows.
    
    Perversely Windows uses the form xx-YY for its own localization
    functions but xx_YY for the posix ones including setlocale().

diff --git a/gnucash/gnucash-bin.c b/gnucash/gnucash-bin.c
index ed1261e4c..a0df6f675 100644
--- a/gnucash/gnucash-bin.c
+++ b/gnucash/gnucash-bin.c
@@ -792,12 +792,10 @@ set_win32_thread_locale()
 	if (IsValidLocaleName(wlocale))
 	{
 	    LCID lcid = LocaleNameToLCID(wlocale, LOCALE_ALLOW_NEUTRAL_NAMES);
-	    printf ("win32_thread_locale setting %s from unix environment.\n",
-		    locale);
 	    SetThreadLocale(lcid);
+	    locale[2] = '_';
 	    setlocale (LC_ALL, locale);
 	    sys_locale = locale;
-	    g_free(locale);
 	    g_free(wlocale);
 	    return;
 	}
@@ -900,8 +898,6 @@ main(int argc, char ** argv)
         g_setenv ("LC_ALL", "C", TRUE);
         setlocale (LC_ALL, "C");
       }
-    else
-      printf ("Locale set to %s\n", sys_locale);
 #ifdef HAVE_GETTEXT
     {
         gchar *localedir = gnc_path_get_localedir();



Summary of changes:
 gnucash/gnucash-bin.c                      | 31 ++-----------
 libgnucash/core-utils/gnc-locale-utils.cpp | 71 ++++++++++++++----------------
 libgnucash/scm/utilities.scm               |  6 ---
 3 files changed, 38 insertions(+), 70 deletions(-)



More information about the gnucash-changes mailing list