qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] gtk: Hardcode LC_CTYPE as C.utf-8
@ 2017-01-31 10:09 Kevin Wolf
  2017-01-31 11:22 ` Alberto Garcia
  2017-01-31 13:04 ` Gerd Hoffmann
  0 siblings, 2 replies; 7+ messages in thread
From: Kevin Wolf @ 2017-01-31 10:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, armbru, kraxel, berto, mfabian

Commit 2cb5d2a4 removed setlocale() for everything except LC_MESSAGES in
order to avoid unwanted side effects such as using the wrong decimal
separator in generated JSON objects. However, the problem that unsetting
LC_CTYPE caused is that non-ASCII characters are considered
non-printable now and therefore the GTK menus display question marks for
accented letters, Chinese characters etc.

A first attempt to fix this [1] was rejected because even just setting
LC_CTYPE to the user's locale (and thereby modifying the semantics of
the ctype.h functions) could have unwanted effects that we're not aware
of yet.

Recently, however, glibc introduced a new locale "C.utf-8" that just
uses UTF-8 as its charset, but otherwise leaves the semantics alone.
Just setting the right character set is enough for our use case, so we
can just hardcode this one without having to be afraid of nasty side
effects.

Older systems that don't have the new locale will continue displaying
question marks, but this should fix the problem for most users.

[1] https://lists.gnu.org/archive/html/qemu-devel/2015-12/msg03591.html
    ('Re: gtk: use setlocale() for LC_MESSAGES only')

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---

I happened to talk to Mike Fabian of our Internationalization team at
devconf.cz and mentioned our problem, and this is the solution that he
suggested. I hope we can finally get things back into a non-broken state
with this. :-)


 ui/gtk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 86368e3..8330762 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2205,8 +2205,12 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
 
     s->free_scale = FALSE;
 
-    /* LC_MESSAGES only. See early_gtk_display_init() for details */
+    /* Mostly LC_MESSAGES only. See early_gtk_display_init() for details. For
+     * LC_CTYPE, we need to make sure that non-ASCII characters are considered
+     * printable, but without changing any of the character classes to make
+     * sure that we don't accidentally break implicit assumptions.  */
     setlocale(LC_MESSAGES, "");
+    setlocale(LC_CTYPE, "C.utf-8");
     bindtextdomain("qemu", CONFIG_QEMU_LOCALEDIR);
     textdomain("qemu");
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-01-31 16:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-31 10:09 [Qemu-devel] [PATCH] gtk: Hardcode LC_CTYPE as C.utf-8 Kevin Wolf
2017-01-31 11:22 ` Alberto Garcia
2017-01-31 13:11   ` Mike FABIAN
2017-01-31 13:23     ` Alberto Garcia
2017-01-31 13:59   ` Eric Blake
2017-01-31 16:05     ` Mike FABIAN
2017-01-31 13:04 ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).