diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-05-09 16:17:34 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-05-15 13:51:00 +0000 |
commit | e95f03f989b73bddb52a54fed6a89428de151b09 (patch) | |
tree | a04f5ae786ad7d2c80428fcd8863359639386787 /src/corelib | |
parent | f4b338833e0222db68f37914ecfa21ff11fd718a (diff) | |
download | qtbase-e95f03f989b73bddb52a54fed6a89428de151b09.tar.gz |
Darwin: Remove QMacAutoReleasePool heap allocation detection
This is handled by the Objective-C runtime nowadays, where it will
abort if the situation is detected, with the option to break on
objc_autoreleasePoolInvalid to debug the situation.
Pick-to: 6.5
Change-Id: Idf2c4aacc77e41a3deebf270303f4f13cfb0819b
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qcore_mac.mm | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/src/corelib/kernel/qcore_mac.mm b/src/corelib/kernel/qcore_mac.mm index 989e7d03a6..ab7a711516 100644 --- a/src/corelib/kernel/qcore_mac.mm +++ b/src/corelib/kernel/qcore_mac.mm @@ -217,38 +217,7 @@ QT_USE_NAMESPACE @interface QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) : NSObject @end -@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) { - NSAutoreleasePool **m_pool; -} - -- (instancetype)initWithPool:(NSAutoreleasePool **)pool -{ - if ((self = [self init])) - m_pool = pool; - return self; -} - -- (void)dealloc -{ - if (*m_pool) { - // The pool is still valid, which means we're not being drained from - // the corresponding QMacAutoReleasePool (see below). - - // QMacAutoReleasePool has only a single member, the NSAutoreleasePool* - // so the address of that member is also the QMacAutoReleasePool itself. - QMacAutoReleasePool *pool = reinterpret_cast<QMacAutoReleasePool *>(m_pool); - qWarning() << "Premature drain of" << pool << "This can happen if you've allocated" - << "the pool on the heap, or as a member of a heap-allocated object. This is not a" - << "supported use of QMacAutoReleasePool, and might result in crashes when objects" - << "in the pool are deallocated and then used later on under the assumption they" - << "will be valid until" << pool << "has been drained."; - - // Reset the pool so that it's not drained again later on - *m_pool = nullptr; - } - - [super dealloc]; -} +@implementation QT_MANGLE_NAMESPACE(QMacAutoReleasePoolTracker) @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QMacAutoReleasePoolTracker); @@ -291,28 +260,15 @@ QMacAutoReleasePool::QMacAutoReleasePool() } #endif - [[[trackerClass alloc] initWithPool: - reinterpret_cast<NSAutoreleasePool **>(&pool)] autorelease]; + [[trackerClass new] autorelease]; } QMacAutoReleasePool::~QMacAutoReleasePool() { - if (!pool) { - qWarning() << "Prematurely drained pool" << this << "finally drained. Any objects belonging" - << "to this pool have already been released, and have potentially been invalid since the" - << "premature drain earlier on."; - return; - } - - // Save and reset pool before draining, so that the pool tracker can know - // that it's being drained by its owning pool. - NSAutoreleasePool *savedPool = static_cast<NSAutoreleasePool*>(pool); - pool = nullptr; - // Drain behaves the same as release, with the advantage that // if we're ever used in a garbage-collected environment, the // drain acts as a hint to the garbage collector to collect. - [savedPool drain]; + [static_cast<NSAutoreleasePool*>(pool) drain]; } #ifndef QT_NO_DEBUG_STREAM |