diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-01-18 16:26:51 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-02-01 16:56:02 +0100 |
commit | e05300163ea865f8233e61f8f6a2b341197203e4 (patch) | |
tree | 928dac9789414598f02ab1929fd93f9555e08676 | |
parent | 7d19efa7bb837f45812b13b24891bb718e874012 (diff) |
Move QIOType wrapper for io_object_t to QtCore
Since we require C++17 now we can use auto for the retain and release
template arguments, which allows us to get rid of the wrapper functions
for IOObjectRetain and IOObjectRelease.
Pick-to: 6.2 6.3
Change-Id: Ifc4bf0fe50dfd0eaf6bb2e143acce6df7df17bdc
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r-- | src/corelib/kernel/qcore_mac_p.h | 19 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.h | 13 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 15 |
3 files changed, 18 insertions, 29 deletions
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index 7b503d10cc..30e5238cd0 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -54,7 +54,16 @@ #include "private/qglobal_p.h" #include <QtCore/qoperatingsystemversion.h> + +#ifdef Q_OS_MACOS struct mach_header; +typedef int kern_return_t; +typedef mach_port_t io_object_t; +extern "C" { +kern_return_t IOObjectRetain(io_object_t object); +kern_return_t IOObjectRelease(io_object_t object); +} +#endif #ifndef __IMAGECAPTURE__ # define __IMAGECAPTURE__ @@ -104,7 +113,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSObject); Q_FORWARD_DECLARE_OBJC_CLASS(NSString); QT_BEGIN_NAMESPACE -template <typename T, typename U, U (*RetainFunction)(U), void (*ReleaseFunction)(U)> +template <typename T, typename U, auto RetainFunction, auto ReleaseFunction> class QAppleRefCounted { public: @@ -172,6 +181,14 @@ public: } }; +#ifdef Q_OS_MACOS +template <typename T> +class QIOType : public QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease> +{ + using QAppleRefCounted<T, io_object_t, IOObjectRetain, IOObjectRelease>::QAppleRefCounted; +}; +#endif + class Q_CORE_EXPORT QCFString : public QCFType<CFStringRef> { public: diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 0fa868c73f..7a3ab5fd6f 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -226,19 +226,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSPanelContentsWrapper); // ------------------------------------------------------------------------- -// QAppleRefCounted expects the retain function to return the object -io_object_t q_IOObjectRetain(io_object_t obj); -// QAppleRefCounted expects the release function to return void -void q_IOObjectRelease(io_object_t obj); - -template <typename T> -class QIOType : public QAppleRefCounted<T, io_object_t, q_IOObjectRetain, q_IOObjectRelease> -{ - using QAppleRefCounted<T, io_object_t, q_IOObjectRetain, q_IOObjectRelease>::QAppleRefCounted; -}; - -// ------------------------------------------------------------------------- - // Depending on the ABI of the platform, we may need to use objc_msgSendSuper_stret: // - http://www.sealiesoftware.com/blog/archive/2008/10/30/objc_explain_objc_msgSend_stret.html // - https://lists.apple.com/archives/cocoa-dev/2008/Feb/msg02338.html diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 2578fb2140..e4c6d415c0 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -499,21 +499,6 @@ QT_END_NAMESPACE // ------------------------------------------------------------------------- -io_object_t q_IOObjectRetain(io_object_t obj) -{ - kern_return_t ret = IOObjectRetain(obj); - Q_ASSERT(!ret); - return obj; -} - -void q_IOObjectRelease(io_object_t obj) -{ - kern_return_t ret = IOObjectRelease(obj); - Q_ASSERT(!ret); -} - -// ------------------------------------------------------------------------- - InputMethodQueryResult queryInputMethod(QObject *object, Qt::InputMethodQueries queries) { if (object) { |