diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-04-13 14:09:35 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-04-13 13:18:48 +0000 |
commit | 17ad6e2a93f93aaa948c1286b3cad785e7f38808 (patch) | |
tree | 2acce8af8ad913b2b268543a6ff8799a2afdf861 | |
parent | 96ff51f856c34c7826c13c2d4c376022e6b7d027 (diff) |
Fix build when Qt is used in an automatic reference-counted environment
When automatic reference-counting (ARC) is enabled on Darwin platforms
the NSAutoReleasePool class should not be used directly, which caused a
build error if qglobal.h was included after the Foundation.h in client
code.
The preferred alternative for ARC is the scoped @autoreleasepool
construct, which allows the compiler to reason about needing to
insert _objc_autoreleasePoolPush and _objc_autoreleasePoolPop
calls.
Note that ARC translation units can be combined with non-ARC translation
units, so Qt and the QMacAutoReleasePool class can still be used in
ARC client code even if Qt is not built with ARC.
Task-number: QTBUG-51332
Change-Id: I7ef1c3146aa416a9d6a1dc299ce7b17f22f889e5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com>
-rw-r--r-- | src/corelib/global/qglobal.h | 6 | ||||
-rw-r--r-- | src/corelib/kernel/qcore_mac_objc.mm | 2 |
2 files changed, 2 insertions, 6 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 98c9902674..5bb1ce77bd 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -579,10 +579,6 @@ Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max # define QT_OSX_DEPLOYMENT_TARGET_BELOW(osx) \ QT_MAC_DEPLOYMENT_TARGET_BELOW(osx, __IPHONE_NA) -QT_END_NAMESPACE -Q_FORWARD_DECLARE_OBJC_CLASS(NSAutoreleasePool); -QT_BEGIN_NAMESPACE - // Implemented in qcore_mac_objc.mm class Q_CORE_EXPORT QMacAutoReleasePool { @@ -591,7 +587,7 @@ public: ~QMacAutoReleasePool(); private: Q_DISABLE_COPY(QMacAutoReleasePool) - NSAutoreleasePool *pool; + void *pool; }; #endif // Q_OS_MAC diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 1a2b047041..e1480a36d5 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.mm @@ -150,7 +150,7 @@ QMacAutoReleasePool::~QMacAutoReleasePool() // 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. - [pool drain]; + [static_cast<NSAutoreleasePool*>(pool) drain]; } // ------------------------------------------------------------------------- |