[Scummvm-git-logs] scummvm master -> 772e7364d19e1b03bab230e04c4d71fe8740c6ef
lephilousophe
noreply at scummvm.org
Fri Mar 3 07:46:21 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
772e7364d1 BACKENDS: DIALOGS: GTK: Set and restore locale when using GTK dialogs
Commit: 772e7364d19e1b03bab230e04c4d71fe8740c6ef
https://github.com/scummvm/scummvm/commit/772e7364d19e1b03bab230e04c4d71fe8740c6ef
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-03-03T08:45:21+01:00
Commit Message:
BACKENDS: DIALOGS: GTK: Set and restore locale when using GTK dialogs
Gtk sets the locale when it's set up to make parts of the UI localized.
We set it properly before displaying the dialog and reset to "C"
afterwards to avoid portability issues in number parsing functions.
Fixes #14196
Thanks to @rootfather and @elasota for the investigation.
Changed paths:
backends/dialogs/gtk/gtk-dialogs.cpp
diff --git a/backends/dialogs/gtk/gtk-dialogs.cpp b/backends/dialogs/gtk/gtk-dialogs.cpp
index 03f0d6c483d..8bbbb13c048 100644
--- a/backends/dialogs/gtk/gtk-dialogs.cpp
+++ b/backends/dialogs/gtk/gtk-dialogs.cpp
@@ -22,6 +22,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_setlocale
#include "common/scummsys.h"
#if defined(POSIX) && defined(USE_SYSDIALOGS) && defined(USE_GTK)
@@ -32,6 +33,7 @@
#include "common/events.h"
#include "common/translation.h"
+#include <locale.h>
#include <gtk/gtk.h>
// TODO: Move this into the class? Probably possible, but I've been told that
@@ -66,6 +68,10 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm
if (isDirBrowser) {
action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
}
+
+ // Set locale to environment one to let user have its localized folders in the browser
+ setlocale(LC_ALL, "");
+
#if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *native = gtk_file_chooser_native_new(utf8Title.c_str(), NULL, action, utf8Choose.c_str(), utf8Cancel.c_str());
GtkFileChooser *chooser = GTK_FILE_CHOOSER(native);
@@ -102,6 +108,11 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm
_inDialog = FALSE;
+ // Restore default C locale to prevent issues with
+ // portability of sscanf(), atof(), etc.
+ // See bugs #6434 and #14196
+ setlocale(LC_ALL, "C");
+
#if GTK_CHECK_VERSION(3,20,0)
g_object_unref(native);
#else
More information about the Scummvm-git-logs
mailing list