From 547141352242f7f4eebc6814af7a5ea0f3dff5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 22 May 2015 14:01:59 +0200 Subject: Add shared implementation of a NSAutoreleasePool wrapper to qglobal We have at least 5 different (but equal) implementations of a wrapper in Qt, and some code uses explicit NSAutoreleasePools. Having a shared implementation lets us clean up things a bit and makes it easier to reason about which pools are actually needed. Change-Id: I2fd8eefc3ae7308595ef9899b7820206268362a5 Reviewed-by: Tim Blechmann Reviewed-by: Simon Hausmann --- src/corelib/global/qglobal.h | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'src/corelib/global/qglobal.h') diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index c4e2f7609c..55aa34223e 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -321,6 +321,15 @@ typedef double qreal; # define Q_NETWORK_EXPORT #endif +/* + Some classes do not permit copies to be made of an object. These + classes contains a private copy constructor and assignment + operator to disable copying (the compiler gives an error message). +*/ +#define Q_DISABLE_COPY(Class) \ + Class(const Class &) Q_DECL_EQ_DELETE;\ + Class &operator=(const Class &) Q_DECL_EQ_DELETE; + /* No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols for Qt's internal unit tests. If you want slower loading times and more @@ -543,7 +552,21 @@ template Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max) { return qMax(min, qMin(max, val)); } -#ifdef Q_OS_DARWIN +#ifndef Q_FORWARD_DECLARE_OBJC_CLASS +# ifdef __OBJC__ +# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname +# else +# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) typedef struct objc_object classname +# endif +#endif +#ifndef Q_FORWARD_DECLARE_CF_TYPE +# define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref +#endif +#ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE +# define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref +#endif + +#ifdef Q_OS_MAC # define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) \ ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && osx != __MAC_NA && __MAC_OS_X_VERSION_MAX_ALLOWED >= osx) || \ (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MAX_ALLOWED >= ios)) @@ -561,7 +584,21 @@ Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max QT_MAC_DEPLOYMENT_TARGET_BELOW(__MAC_NA, ios) # define QT_OSX_DEPLOYMENT_TARGET_BELOW(osx) \ QT_MAC_DEPLOYMENT_TARGET_BELOW(osx, __IPHONE_NA) -#endif + +Q_FORWARD_DECLARE_OBJC_CLASS(NSAutoreleasePool); + +// Implemented in qcore_mac_objc.mm +class Q_CORE_EXPORT QMacAutoReleasePool +{ +public: + QMacAutoReleasePool(); + ~QMacAutoReleasePool(); +private: + Q_DISABLE_COPY(QMacAutoReleasePool); + NSAutoreleasePool *pool; +}; + +#endif // Q_OS_MAC /* Data stream functions are provided by many classes (defined in qdatastream.h) @@ -1033,15 +1070,6 @@ Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1); { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; } #endif -/* - Some classes do not permit copies to be made of an object. These - classes contains a private copy constructor and assignment - operator to disable copying (the compiler gives an error message). -*/ -#define Q_DISABLE_COPY(Class) \ - Class(const Class &) Q_DECL_EQ_DELETE;\ - Class &operator=(const Class &) Q_DECL_EQ_DELETE; - class QByteArray; Q_CORE_EXPORT QByteArray qgetenv(const char *varName); Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value); @@ -1076,20 +1104,6 @@ template struct QConditional { typedef T Type; template struct QConditional { typedef F Type; }; } -#ifndef Q_FORWARD_DECLARE_OBJC_CLASS -# ifdef __OBJC__ -# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname -# else -# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) typedef struct objc_object classname -# endif -#endif -#ifndef Q_FORWARD_DECLARE_CF_TYPE -# define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref -#endif -#ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE -# define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref -#endif - QT_END_NAMESPACE // We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4. -- cgit v1.2.3