summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-09-02 10:12:07 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-21 05:09:41 +0200
commit2b65bba77d4705d49a01a25350de64d153808504 (patch)
tree02de52c8dc6be51af70221beed24a1819cc0dd62 /src/corelib/global
parentdd7bfffa77c231296ca977d6c7d487962f7ebae9 (diff)
Add Mac type conversion functions to QtCore
New API: static QString QString::fromCFString(CFStringRef string); CFStringRef QString::toCFString() const; static QString QString::fromNSString(const NSString *string); NSString *QString::toNSString() const; static QUrl QUrl::fromCFURL(CFURLRef url); CFURLRef QUrl::toCFURL() const; static QUrl QUrl::fromNSURL(const NSURL *url); NSURL * QUrl::toNSURL() const; Add Q_OS_MAC-protected function declarations to header files, add implementation to _mm files. CF and NS types are forward-declared in the header files to avoid including the CoreFoundation and Foundation headers. This prevents accidental use of native types in application code. Add helper macros for forward- declaration to qglobal.h Add cf_returns_retained/ns_returns_autoreleased attributes to toCFString() and toNSURL(). These attributes assists the clang static analyzer. Add Q_DECL_ helper macros to qcompilerdetection.h. Add test functions (in _mac.mm files) to the QString and QUrl tests. Split out the test class declarations into a separate headers files. Change-Id: I60fd5e93f042316196284c3db0595835fe8c4ad4 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qcompilerdetection.h14
-rw-r--r--src/corelib/global/qglobal.cpp32
-rw-r--r--src/corelib/global/qglobal.h8
3 files changed, 54 insertions, 0 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
index 5306e432fd..a388bdb96f 100644
--- a/src/corelib/global/qcompilerdetection.h
+++ b/src/corelib/global/qcompilerdetection.h
@@ -620,6 +620,14 @@
# endif
#endif // Q_CC_CLANG
+#if defined(Q_CC_CLANG) && defined(__APPLE__)
+/* Apple/clang specific features */
+# define Q_DECL_CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
+# ifdef __OBJC__
+# define Q_DECL_NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
+# endif
+#endif
+
#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 403
@@ -849,6 +857,12 @@
# define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__)
# endif
#endif
+#ifndef Q_DECL_CF_RETURNS_RETAINED
+# define Q_DECL_CF_RETURNS_RETAINED
+#endif
+#ifndef Q_DECL_NS_RETURNS_AUTORELEASED
+# define Q_DECL_NS_RETURNS_AUTORELEASED
+#endif
/*
Workaround for static const members on MSVC++.
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index ce87e4bfd9..59bdecc868 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -3361,4 +3361,36 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
\sa Q_DECL_OVERRIDE
*/
+/*!
+ \macro Q_FORWARD_DECLARE_OBJC_CLASS(classname)
+ \since 5.2
+ \relates <QtGlobal>
+
+ Forward-declares an Objective-C \a classname in a manner such that it can be
+ compiled as either Objective-C or C++.
+
+ This is primarily intended for use in header files that may be included by
+ both Objective-C and C++ source files.
+*/
+
+/*!
+ \macro Q_FORWARD_DECLARE_CF_TYPE(type)
+ \since 5.2
+ \relates <QtGlobal>
+
+ Forward-declares a Core Foundation \a type. This includes the actual
+ type and the ref type. For example, Q_FORWARD_DECLARE_CF_TYPE(CFString)
+ declares __CFString and CFStringRef.
+*/
+
+/*!
+ \macro Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type)
+ \since 5.2
+ \relates <QtGlobal>
+
+ Forward-declares a mutable Core Foundation \a type. This includes the actual
+ type and the ref type. For example, Q_FORWARD_DECLARE_CF_TYPE(CFString)
+ declares __CFMutableString and CFMutableStringRef.
+*/
+
QT_END_NAMESPACE
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index f38672bdc1..b4830bda1f 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -993,6 +993,14 @@ template <bool B, typename T = void> struct QEnableIf;
template <typename T> struct QEnableIf<true, T> { typedef T Type; };
}
+#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
+#define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref
+#define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref
+
QT_END_NAMESPACE
// Q_GLOBAL_STATIC
#include <QtCore/qglobalstatic.h>