Received: from eggs.gnu.org ([2001:4830:134:3::10]:52899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU94C-0005Wm-Om for qemu-devel@nongnu.org; Tue, 25 Aug 2015 03:54:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZU949-0003xo-BT for qemu-devel@nongnu.org; Tue, 25 Aug 2015 03:54:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35088) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU949-0003xW-63 for qemu-devel@nongnu.org; Tue, 25 Aug 2015 03:54:45 -0400 From: Markus Armbruster References: <20150818235754.GA31625@igalia.com> <87r3mtq9wx.fsf@blackfin.pond.sub.org> <87oahwr4x1.fsf@blackfin.pond.sub.org> <55DB51DC.6070704@redhat.com> Date: Tue, 25 Aug 2015 09:54:42 +0200 In-Reply-To: <55DB51DC.6070704@redhat.com> (Eric Blake's message of "Mon, 24 Aug 2015 11:18:20 -0600") Message-ID: <87d1ybpzul.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] QEMU produces invalid JSON due to locale-dependent code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Alberto Garcia , qemu-devel@nongnu.org, Gerd Hoffmann Eric Blake writes: > On 08/24/2015 11:07 AM, Markus Armbruster wrote: > >>> You can prevent GTK+ from calling setlocale() by using >>> gtk_disable_setlocale() before gtk_init(), but note that setlocale() is >>> needed for gettext. >> >> We can >> >> (A) Internationalize our complete code base >> >> (B) Run in the C locale >> >> Breaks GTK's internationalization. >> >> (C) Run in a mixed locale >> >> Whenever something breaks, we switch another LC_ to the C locale. >> >> Can partially break GTK's internationalization. >> >> I happily concede that (A) would be best. Until the manpower to pull it >> off appears, I recommend (B), because it's safer than (C), and avoids >> inconsistent localization, such as German messages combined with >> non-German number formatting. > > Is it still possible for: > > (D) Run in a controlled mixed locale > GTK runs completely in the locale determined by setlocale() (since it > never has to display raw JSON) > We fix our JSON output code to use thread-specific locale > manipulations to (temporarily) switch to C locale before printing JSON > > that way, GTK still shows full German formatting for any localized > message in the GUI that happens to print numbers, but the JSON output > (which is independent of the GUI) also behaves correctly as a C-only entity. Switching back to C locale whenever some unwanted locale-dependency breaks the code is problematic, because it involves finding all the places that break, iteratively (euphemism for "we debug one breakage after the other, adding temporary locale switches as we go). I'd feel much better about confining GTK in its own thread, and setting only that thread's locale. If that's impractical, perhaps we can switch locale just around GTK code. Thread-locally, of course. > I don't know how well mingw supports thread-specific locales (POSIX > requires it, but we all know that mingw is behind the curve when it > comes to POSIX...); BSD and glibc should be okay, though. I have no idea. We could have configure checking whether we have thread-local locale, and if not, disable internationalization entirely.