diff options
Diffstat (limited to 'src/corelib/kernel/qcore_mac.mm')
-rw-r--r-- | src/corelib/kernel/qcore_mac.mm | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index 2ad835b754..00b0d078d7 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -25,7 +25,6 @@ #include "qendian.h" #include "qhash.h" -#include "qpair.h" #include "qmutex.h" #include "qvarlengtharray.h" #include "private/qlocking_p.h" @@ -53,6 +52,7 @@ QT_BEGIN_NAMESPACE // -------------------------------------------------------------------------- +#if defined(Q_OS_MACOS) static void initializeStandardUserDefaults() { // The standard user defaults are initialized from an ordered list of domains, @@ -65,6 +65,7 @@ static void initializeStandardUserDefaults() Q_UNUSED(NSUserDefaults.standardUserDefaults); } Q_CONSTRUCTOR_FUNCTION(initializeStandardUserDefaults); +#endif // -------------------------------------------------------------------------- @@ -86,17 +87,35 @@ QCFString::operator CFStringRef() const #if defined(QT_USE_APPLE_UNIFIED_LOGGING) -bool AppleUnifiedLogger::willMirrorToStderr() +bool AppleUnifiedLogger::preventsStderrLogging() { - // When running under Xcode or LLDB, one or more of these variables will - // be set, which triggers libsystem_trace.dyld to log messages to stderr - // as well, via_os_log_impl_mirror_to_stderr. Un-setting these variables - // is not an option, as that would silence normal NSLog or os_log calls, - // so instead we skip our own stderr output. See rdar://36919139. + // os_log will mirror to stderr if OS_ACTIVITY_DT_MODE is set, + // regardless of its value. OS_ACTIVITY_MODE then controls whether + // to include info and/or debug messages in this mirroring. + // For some reason, when launched under lldb (via Xcode or not), + // all levels are included. + + // CFLog will normally log to both stderr, and via os_log. + // Setting CFLOG_FORCE_DISABLE_STDERR disables the stderr + // logging. Setting CFLOG_FORCE_STDERR will both duplicate + // CFLog's output to stderr, and trigger OS_ACTIVITY_DT_MODE, + // resulting in os_log calls also being mirrored to stderr. + // Setting ACTIVITY_LOG_STDERR has the same effect. + + // NSLog is plumbed to CFLog, and will respond to the same + // environment variables as CFLog. + + // We want to disable Qt's default stderr log handler when + // os_log has already mirrored to stderr. static bool willMirror = qEnvironmentVariableIsSet("OS_ACTIVITY_DT_MODE") - || qEnvironmentVariableIsSet("ACTIVITY_LOG_STDERR") - || qEnvironmentVariableIsSet("CFLOG_FORCE_STDERR"); - return willMirror; + || qEnvironmentVariableIsSet("ACTIVITY_LOG_STDERR") + || qEnvironmentVariableIsSet("CFLOG_FORCE_STDERR"); + + // As well as when we suspect that Xcode is going to present os_log + // as structured log messages. + static bool disableStderr = qEnvironmentVariableIsSet("CFLOG_FORCE_DISABLE_STDERR"); + + return willMirror || disableStderr; } QT_MAC_WEAK_IMPORT(_os_log_default); @@ -137,7 +156,7 @@ bool AppleUnifiedLogger::messageHandler(QtMsgType msgType, const QMessageLogCont // system from redacting our log message. os_log_with_type(log, logType, "%{public}s", qPrintable(message)); - return willMirrorToStderr(); + return preventsStderrLogging(); } os_log_type_t AppleUnifiedLogger::logTypeForMessageType(QtMsgType msgType) @@ -327,7 +346,7 @@ std::optional<uint32_t> qt_mac_sipConfiguration() return config; #endif - QIOType<io_registry_entry_t> nvram = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); + QIOType<io_registry_entry_t> nvram = IORegistryEntryFromPath(kIOMainPortDefault, "IODeviceTree:/options"); if (!nvram) { qWarning("Failed to locate NVRAM entry in IO registry"); return {}; @@ -487,7 +506,7 @@ bool qt_apple_isSandboxed() } QT_END_NAMESPACE -@implementation NSObject (QtSandboxHelpers) +@implementation NSObject (QtExtras) - (id)qt_valueForPrivateKey:(NSString *)key { if (qt_apple_isSandboxed()) @@ -522,7 +541,7 @@ QMacRootLevelAutoReleasePool::QMacRootLevelAutoReleasePool() if (qEnvironmentVariableIsSet(ROOT_LEVEL_POOL_DISABLE_SWITCH)) return; - pool.reset(new QMacAutoReleasePool); + pool.emplace(); [[[ROOT_LEVEL_POOL_MARKER alloc] init] autorelease]; @@ -548,6 +567,9 @@ void qt_apple_check_os_version() #elif defined(__TV_OS_VERSION_MIN_REQUIRED) const char *os = "tvOS"; const int version = __TV_OS_VERSION_MIN_REQUIRED; +#elif defined(__VISION_OS_VERSION_MIN_REQUIRED) + const char *os = "visionOS"; + const int version = __VISION_OS_VERSION_MIN_REQUIRED; #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) const char *os = "iOS"; const int version = __IPHONE_OS_VERSION_MIN_REQUIRED; @@ -697,7 +719,7 @@ QMacVersion::VersionTuple QMacVersion::versionsForImage(const mach_header *machH }; static auto makeVersionTuple = [](uint32_t dt, uint32_t sdk, QOperatingSystemVersion::OSType osType) { - return qMakePair( + return std::pair( QOperatingSystemVersion(osType, dt >> 16 & 0xffff, dt >> 8 & 0xff, dt & 0xff), QOperatingSystemVersion(osType, sdk >> 16 & 0xffff, sdk >> 8 & 0xff, sdk & 0xff) ); |