From 0519f82a378de4792cb7b14a9aab887d2b6cea45 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 22 Jan 2026 20:45:43 +0100 Subject: [PATCH] Fix 317dc71c6a: MacOS version detection was broken, and return a tuple instead of three out-params --- src/os/macosx/macos.h | 2 +- src/os/macosx/macos.mm | 26 +++++--------------------- src/os/macosx/survey_osx.cpp | 5 ++--- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h index 48697e430e..7e0e6cc4a5 100644 --- a/src/os/macosx/macos.h +++ b/src/os/macosx/macos.h @@ -13,7 +13,7 @@ /** Helper function displaying a message the best possible way. */ void ShowMacDialog(std::string_view title, std::string_view message, std::string_view button_label); -void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix); +std::tuple GetMacOSVersion(); bool IsMonospaceFont(CFStringRef name); diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm index 7e025aeb63..3125be98f6 100644 --- a/src/os/macosx/macos.mm +++ b/src/os/macosx/macos.mm @@ -26,29 +26,13 @@ static NSAutoreleasePool *_ottd_autorelease_pool; #endif /** - * Get the version of the MacOS we are running under. Code adopted - * from http://www.cocoadev.com/index.pl?DeterminingOSVersion - * @param return_major major version of the os. This would be 10 in the case of 10.4.11 - * @param return_minor minor version of the os. This would be 4 in the case of 10.4.11 - * @param return_bugfix bugfix version of the os. This would be 11 in the case of 10.4.11 - * A return value of -1 indicates that something went wrong and we don't know. + * Get the version of the MacOS we are running under. + * @return Tuple with major, minor and patch of the MacOS version. */ -void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix) +std::tuple GetMacOSVersion() { - *return_major = -1; - *return_minor = -1; - *return_bugfix = -1; - - if ([[ NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion) ]) { - IMP sel = [ [ NSProcessInfo processInfo] methodForSelector:@selector(operatingSystemVersion) ]; - NSOperatingSystemVersion ver = ((NSOperatingSystemVersion (*)(id, SEL))sel)([ NSProcessInfo processInfo], @selector(operatingSystemVersion)); - - *return_major = (int)ver.majorVersion; - *return_minor = (int)ver.minorVersion; - *return_bugfix = (int)ver.patchVersion; - - return; - } + NSOperatingSystemVersion ver = [ [ NSProcessInfo processInfo ] operatingSystemVersion ]; + return { static_cast(ver.majorVersion), static_cast(ver.minorVersion), static_cast(ver.patchVersion) }; } #ifdef WITH_COCOA diff --git a/src/os/macosx/survey_osx.cpp b/src/os/macosx/survey_osx.cpp index 2050d29f10..f2607fb788 100644 --- a/src/os/macosx/survey_osx.cpp +++ b/src/os/macosx/survey_osx.cpp @@ -20,13 +20,12 @@ void SurveyOS(nlohmann::json &json) { - int ver_maj, ver_min, ver_bug; - GetMacOSVersion(&ver_maj, &ver_min, &ver_bug); + auto [ver_major, ver_minor, ver_patch] = GetMacOSVersion(); const NXArchInfo *arch = NXGetLocalArchInfo(); json["os"] = "MacOS"; - json["release"] = fmt::format("{}.{}.{}", ver_maj, ver_min, ver_bug); + json["release"] = fmt::format("{}.{}.{}", ver_major, ver_minor, ver_patch); json["machine"] = arch != nullptr ? arch->description : "unknown"; json["min_ver"] = MAC_OS_X_VERSION_MIN_REQUIRED; json["max_ver"] = MAC_OS_X_VERSION_MAX_ALLOWED;