From: <sv...@op...> - 2025-01-03 20:58:06
|
Author: manx Date: Fri Jan 3 21:57:54 2025 New Revision: 22759 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22759 Log: Merged revision(s) 22750 from trunk/OpenMPT: [Fix] mpt/string_transcode/transcode.hpp: Try to work-around Cygwin locale handling problems the same way we did in libopenmpt 0.5.x and earlier. See <https://cygwin.com/cgit/cygwin-packages/libopenmpt/tree/libopenmpt-0.7.12-1.src.patch?id=c4baa491e8a0975a1c7e0dfdf5ddf208d5b4ba6b>. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/src/mpt/string_transcode/transcode.hpp Modified: branches/OpenMPT-1.31/src/mpt/string_transcode/transcode.hpp ============================================================================== --- branches/OpenMPT-1.31/src/mpt/string_transcode/transcode.hpp Fri Jan 3 21:57:25 2025 (r22758) +++ branches/OpenMPT-1.31/src/mpt/string_transcode/transcode.hpp Fri Jan 3 21:57:54 2025 (r22759) @@ -11,6 +11,7 @@ #include "mpt/base/namespace.hpp" #include "mpt/base/saturate_cast.hpp" #include "mpt/detect/mfc.hpp" +#include "mpt/out_of_memory/out_of_memory.hpp" #include "mpt/string/types.hpp" #include "mpt/string/utility.hpp" @@ -1664,10 +1665,60 @@ #elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR) switch (encoding) { case logical_encoding::locale: +#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE) + try { + return encode_locale<Tdststring>(std::locale(""), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return encode_locale<Tdststring>(std::locale(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return encode_locale<Tdststring>(std::locale::classic(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + return encode_ascii<Tdststring>(src); +#else return encode_locale<Tdststring>(std::locale(""), src); +#endif break; case logical_encoding::active_locale: +#if defined(MPT_LIBCXX_QUIRK_BROKEN_ACTIVE_LOCALE) + try { + return encode_locale<Tdststring>(std::locale(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return encode_locale<Tdststring>(std::locale(""), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return encode_locale<Tdststring>(std::locale::classic(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + return encode_ascii<Tdststring>(src); +#else return encode_locale<Tdststring>(std::locale(), src); +#endif break; } throw std::domain_error("unsupported encoding"); @@ -1835,10 +1886,60 @@ #elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR) switch (encoding) { case logical_encoding::locale: +#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE) + try { + return decode_locale(std::locale(""), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return decode_locale(std::locale(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return decode_locale(std::locale::classic(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + return decode_ascii(src); +#else return decode_locale(std::locale(""), src); +#endif break; case logical_encoding::active_locale: +#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE) + try { + return decode_locale(std::locale(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return decode_locale(std::locale(""), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + try { + return decode_locale(std::locale::classic(), src); + } catch (mpt::out_of_memory e) { + mpt::rethrow_out_of_memory(e); + } catch (...) { + // nothing + } + return decode_ascii(src); +#else return decode_locale(std::locale(), src); +#endif break; } throw std::domain_error("unsupported encoding"); |