Ticket #62964: patch-qoperatingsystemversion-109.diff

File patch-qoperatingsystemversion-109.diff, 3.1 KB (added by Wowfunhappy (Jonathan), 3 years ago)
  • src/corelib/global/qoperatingsystemversion_darwin.mm

    From ab9433d7054e3e599976d1831f9d32469b72965e Mon Sep 17 00:00:00 2001
    From: Wowfunhappy <Wowfunhappy@gmail.com>
    Date: Sun, 30 May 2021 15:28:58 -0400
    Subject: [PATCH] Revert changes to qoperatingsystemversion_darwin.mm
    
    Very fuzzy on whether this is actually necessary! QT builds and seems to work without it, _except_ when I try to add this patch to the MacPorts version of QT 5.9, as I attempted to do. Can't hurt?
    ---
     .../global/qoperatingsystemversion_darwin.mm       | 53 ++++++++++++++++++++--
     1 file changed, 49 insertions(+), 4 deletions(-)
    
    diff --git src/corelib/global/qoperatingsystemversion_darwin.mm src/corelib/global/qoperatingsystemversion_darwin.mm
    index d8b927ff5d..3dd007cbb3 100644
     
    4040#include "qoperatingsystemversion_p.h"
    4141#import <Foundation/Foundation.h>
    4242
     43#ifdef Q_OS_IOS
     44#import <UIKit/UIKit.h>
     45#endif
     46
    4347QT_BEGIN_NAMESPACE
    4448
     49typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response);
     50
    4551QOperatingSystemVersion QOperatingSystemVersion::current()
    4652{
    47     NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
    4853    QOperatingSystemVersion v;
    4954    v.m_os = currentType();
    50     v.m_major = osv.majorVersion;
    51     v.m_minor = osv.minorVersion;
    52     v.m_micro = osv.patchVersion;
     55    v.m_major = -1;
     56    v.m_minor = -1;
     57    v.m_micro = -1;
     58#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0) || defined(Q_OS_TVOS) || defined(Q_OS_WATCHOS)
     59    if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) {
     60        NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;
     61        v.m_major = osv.majorVersion;
     62        v.m_minor = osv.minorVersion;
     63        v.m_micro = osv.patchVersion;
     64        return v;
     65    }
     66#endif
     67    // Use temporary variables so we can return 0.0.0 (unknown version)
     68    // in case of an error partway through determining the OS version
     69    qint32 major = 0, minor = 0, patch = 0;
     70#if QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_10, __IPHONE_8_0)
     71#if defined(Q_OS_IOS)
     72    @autoreleasepool {
     73        NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."];
     74        major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0;
     75        minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0;
     76        patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0;
     77    }
     78#elif defined(Q_OS_MACOS)
     79    static GestaltFunction pGestalt = 0;
     80    if (!pGestalt) {
     81        CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices"));
     82        pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b,
     83                                                     CFSTR("Gestalt")));
     84    }
     85    if (!pGestalt)
     86        return v;
     87    if (pGestalt('sys1', &major) != 0)
     88        return v;
     89    if (pGestalt('sys2', &minor) != 0)
     90        return v;
     91    if (pGestalt('sys3', &patch) != 0)
     92        return v;
     93#endif
     94#endif
     95    v.m_major = major;
     96    v.m_minor = minor;
     97    v.m_micro = patch;
    5398    return v;
    5499}
    55100