diff --git a/src/Text.cc b/src/Text.cc index c68a851e..1876aef0 100644 --- a/src/Text.cc +++ b/src/Text.cc @@ -257,16 +257,17 @@ std::string TextTranscoderUTF8ToCustomSJIS::on_untranslatable(const void** src, } } -TextTranscoder tt_8859_to_utf8("UTF-8", "ISO-8859-1"); -TextTranscoder tt_utf8_to_8859("ISO-8859-1", "UTF-8"); -TextTranscoder tt_standard_sjis_to_utf8("UTF-8", "SHIFT_JIS"); -TextTranscoder tt_utf8_to_standard_sjis("SHIFT_JIS", "UTF-8"); -TextTranscoderCustomSJISToUTF8 tt_sega_sjis_to_utf8; -TextTranscoderUTF8ToCustomSJIS tt_utf8_to_sega_sjis; -TextTranscoder tt_utf16_to_utf8("UTF-8", "UTF-16LE"); -TextTranscoder tt_utf8_to_utf16("UTF-16LE", "UTF-8"); -TextTranscoder tt_ascii_to_utf8("UTF-8", "ASCII"); -TextTranscoder tt_utf8_to_ascii("ASCII", "UTF-8"); +// iconv_t is not thread-safe, so we need a separate one of these for each thread +thread_local TextTranscoder tt_8859_to_utf8("UTF-8", "ISO-8859-1"); +thread_local TextTranscoder tt_utf8_to_8859("ISO-8859-1", "UTF-8"); +thread_local TextTranscoder tt_standard_sjis_to_utf8("UTF-8", "SHIFT_JIS"); +thread_local TextTranscoder tt_utf8_to_standard_sjis("SHIFT_JIS", "UTF-8"); +thread_local TextTranscoderCustomSJISToUTF8 tt_sega_sjis_to_utf8; +thread_local TextTranscoderUTF8ToCustomSJIS tt_utf8_to_sega_sjis; +thread_local TextTranscoder tt_utf16_to_utf8("UTF-8", "UTF-16LE"); +thread_local TextTranscoder tt_utf8_to_utf16("UTF-16LE", "UTF-8"); +thread_local TextTranscoder tt_ascii_to_utf8("UTF-8", "ASCII"); +thread_local TextTranscoder tt_utf8_to_ascii("ASCII", "UTF-8"); std::string tt_encode_marked_optional(const std::string& utf8, Language default_language, bool is_utf16) { if (is_utf16) { diff --git a/src/Text.hh b/src/Text.hh index a9707805..52024f67 100644 --- a/src/Text.hh +++ b/src/Text.hh @@ -77,16 +77,16 @@ protected: virtual std::string on_untranslatable(const void** src, size_t* size) const; }; -extern TextTranscoder tt_8859_to_utf8; -extern TextTranscoder tt_utf8_to_8859; -extern TextTranscoder tt_standard_sjis_to_utf8; -extern TextTranscoder tt_utf8_to_standard_sjis; -extern TextTranscoderCustomSJISToUTF8 tt_sega_sjis_to_utf8; -extern TextTranscoderUTF8ToCustomSJIS tt_utf8_to_sega_sjis; -extern TextTranscoder tt_utf16_to_utf8; -extern TextTranscoder tt_utf8_to_utf16; -extern TextTranscoder tt_ascii_to_utf8; -extern TextTranscoder tt_utf8_to_ascii; +extern thread_local TextTranscoder tt_8859_to_utf8; +extern thread_local TextTranscoder tt_utf8_to_8859; +extern thread_local TextTranscoder tt_standard_sjis_to_utf8; +extern thread_local TextTranscoder tt_utf8_to_standard_sjis; +extern thread_local TextTranscoderCustomSJISToUTF8 tt_sega_sjis_to_utf8; +extern thread_local TextTranscoderUTF8ToCustomSJIS tt_utf8_to_sega_sjis; +extern thread_local TextTranscoder tt_utf16_to_utf8; +extern thread_local TextTranscoder tt_utf8_to_utf16; +extern thread_local TextTranscoder tt_ascii_to_utf8; +extern thread_local TextTranscoder tt_utf8_to_ascii; std::string tt_encode_marked_optional(const std::string& utf8, Language default_language, bool is_utf16); std::string tt_encode_marked(const std::string& utf8, Language default_language, bool is_utf16);