From 19e14a560850689ec453e8bc4098a0144dbdbd7d Mon Sep 17 00:00:00 2001 From: Robert Peralta Date: Thu, 17 Aug 2023 01:01:01 -0400 Subject: [PATCH] Fix macOS compilation errors (#81) * Move #endif to proper location on UICommon.cpp preventing compilation because of syntax error * Add missing include for unordered map and missing CodeTo implementation from Ishiiruka + Adjust code to use string_view * Trick compiler to think var is being used on Semver200_parser.cpp to prevent compilation errors on macos --- Externals/semver/src/Semver200_parser.cpp | 7 +++++-- Source/Core/Common/StringUtil.cpp | 15 ++++++++++++--- Source/Core/UICommon/UICommon.cpp | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Externals/semver/src/Semver200_parser.cpp b/Externals/semver/src/Semver200_parser.cpp index d62846d154..907d97a42a 100644 --- a/Externals/semver/src/Semver200_parser.cpp +++ b/Externals/semver/src/Semver200_parser.cpp @@ -92,8 +92,11 @@ namespace version { for (const auto& r : allowed_prerel_id_chars) { res |= (c >= r.first && c <= r.second); } - //if (!res) - // throw Parse_error("invalid character encountered: " + string(1, c)); + // Trick the compiler that this is being used so it stops crashing on macos + (void)res; + + // if (!res) + // throw Parse_error("invalid character encountered: " + string(1, c)); } inline bool is_identifier_numeric(const string& id) { diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 01ff841cfa..660b963fa0 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -593,7 +594,7 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size) template #ifdef __APPLE__ std::string CodeToWithFallbacks(const char* tocode, const char* fromcode, - const std::basic_string& input, iconv_fallbacks* fallbacks) + const std::basic_string_view input, iconv_fallbacks* fallbacks) #else std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view input) #endif @@ -665,6 +666,14 @@ std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_v return result; } +#ifdef __APPLE__ +template +std::string CodeTo(const char* tocode, const char* fromcode, std::basic_string_view input) +{ + return CodeToWithFallbacks(tocode, fromcode, input, nullptr); +} +#endif + template std::string CodeToUTF8(const char* fromcode, std::basic_string_view input) { @@ -746,10 +755,10 @@ std::string UTF8ToSHIFTJIS(std::string_view input) fallbacks->mb_to_wc_fallback = nullptr; fallbacks->wc_to_mb_fallback = nullptr; fallbacks->data = nullptr; - auto str = CodeToWithFallbacks("SJIS", "UTF-8", input, fallbacks); + auto str = CodeToWithFallbacks("SJIS", "UTF-8", std::string_view(input), fallbacks); free(fallbacks); #else - auto str = CodeTo("SJIS", "UTF-8", input); + auto str = CodeTo("SJIS", "UTF-8", std::string_view(input)); #endif return str; } diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 20cb701946..b566c059a0 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -487,8 +487,8 @@ void SetUserDirectory(std::string custom_path) } } #endif - } #endif + } #endif File::SetUserPath(D_USER_IDX, std::move(user_path)); }