gnu: wesnoth: Update to 1.14.0.
[jackhill/guix/guix.git] / gnu / packages / patches / wesnoth-fix-std-bad-cast.patch
1 From 18e5ea50a7136cb3686c5a7c51c111ccce73dc54 Mon Sep 17 00:00:00 2001
2 From: Iris Morelle <shadowm@wesnoth.org>
3 Date: Sun, 6 May 2018 16:10:42 -0300
4 Subject: [PATCH] i18n: Blind fix attempt for std::bad_cast being thrown on
5 Windows
6
7 Several reports on Steam and our forums point at std::bad_cast being
8 thrown when accessing Preferences and the Multiplayer menu amongst
9 others. It's possible that the locale configuration on those systems is
10 not quite right, and compare() and icompare() are able to throw
11 std::bad_cast when this happens as they both use std::use_facet().
12
13 Note that much like the macOS/iOS version of icompare(), this stopgap
14 patch doesn't attempt to provide any form of case-insensitive fallback
15 and just uses a case-sensitive comparison instead.
16 ---
17 src/gettext_boost.cpp | 29 +++++++++++++++++++++++++++--
18 1 file changed, 27 insertions(+), 2 deletions(-)
19
20 diff --git a/src/gettext_boost.cpp b/src/gettext_boost.cpp
21 index 3cc7690d5ef..fb04ffeea90 100644
22 --- a/src/gettext_boost.cpp
23 +++ b/src/gettext_boost.cpp
24 @@ -423,7 +423,19 @@ void set_language(const std::string& language, const std::vector<std::string>* /
25 int compare(const std::string& s1, const std::string& s2)
26 {
27 std::lock_guard<std::mutex> lock(get_mutex());
28 - return std::use_facet<std::collate<char>>(get_manager().get_locale()).compare(s1.c_str(), s1.c_str() + s1.size(), s2.c_str(), s2.c_str() + s2.size());
29 +
30 + try {
31 + return std::use_facet<std::collate<char>>(get_manager().get_locale()).compare(s1.c_str(), s1.c_str() + s1.size(), s2.c_str(), s2.c_str() + s2.size());
32 + } catch(const std::bad_cast&) {
33 + static bool bad_cast_once = false;
34 +
35 + if(!bad_cast_once) {
36 + ERR_G << "locale set-up for compare() is broken, falling back to std::string::compare()\n";
37 + bad_cast_once = true;
38 + }
39 +
40 + return s1.compare(s2);
41 + }
42 }
43
44 int icompare(const std::string& s1, const std::string& s2)
45 @@ -433,8 +445,21 @@ int icompare(const std::string& s1, const std::string& s2)
46 return compare(s1, s2);
47 #else
48 std::lock_guard<std::mutex> lock(get_mutex());
49 - return std::use_facet<bl::collator<char>>(get_manager().get_locale()).compare(
50 +
51 + try {
52 + return std::use_facet<bl::collator<char>>(get_manager().get_locale()).compare(
53 bl::collator_base::secondary, s1, s2);
54 + } catch(const std::bad_cast&) {
55 + static bool bad_cast_once = false;
56 +
57 + if(!bad_cast_once) {
58 + ERR_G << "locale set-up for icompare() is broken, falling back to std::string::compare()\n";
59 + bad_cast_once = true;
60 + }
61 +
62 + // FIXME: not even lazily case-insensitive
63 + return s1.compare(s2);
64 + }
65 #endif
66 }
67