From 7a59dbc9885ea2377858519c3761b21a11f4113e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 26 Mar 2015 12:28:50 +0100 Subject: [PATCH] OS X: Create a help AutoreleasePool class That wraps NSAutoreleasePool and releases it at destruction. Change-Id: Ie7049450da46458f02c02d38439e20e43609ca83 Reviewed-by: Erik Verbruggen --- src/libs/utils/autoreleasepool.h | 51 +++++++++++++++++++ src/libs/utils/fileutils_mac.mm | 6 +-- src/libs/utils/utils-lib.pri | 1 + .../locator/spotlightlocatorfilter.mm | 7 ++- src/plugins/help/macwebkithelpviewer.mm | 22 +------- 5 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 src/libs/utils/autoreleasepool.h diff --git a/src/libs/utils/autoreleasepool.h b/src/libs/utils/autoreleasepool.h new file mode 100644 index 00000000000..e60411443e6 --- /dev/null +++ b/src/libs/utils/autoreleasepool.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#ifndef AUTORELEASEPOOL_H +#define AUTORELEASEPOOL_H + +#import + +namespace Utils { + +class AutoreleasePool +{ +public: + AutoreleasePool() { pool = [[NSAutoreleasePool alloc] init]; } + ~AutoreleasePool() { [pool release]; } +private: + NSAutoreleasePool *pool; +}; + +} // Utils + +#endif // AUTORELEASEPOOL_H + diff --git a/src/libs/utils/fileutils_mac.mm b/src/libs/utils/fileutils_mac.mm index 21a800df4ed..1c149bbf671 100644 --- a/src/libs/utils/fileutils_mac.mm +++ b/src/libs/utils/fileutils_mac.mm @@ -28,9 +28,10 @@ ** ****************************************************************************/ +#include "autoreleasepool.h" + #include -#include #include namespace Utils { @@ -38,12 +39,11 @@ namespace Internal { QUrl filePathUrl(const QUrl &url) { + Utils::AutoreleasePool pool; Q_UNUSED(pool) QUrl ret = url; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSURL *nsurl = url.toNSURL(); if ([nsurl isFileReferenceURL]) ret = QUrl::fromNSURL([nsurl filePathURL]); - [pool release]; return ret; } diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 933217580d2..aa2bbbbb560 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -198,6 +198,7 @@ FORMS += $$PWD/filewizardpage.ui \ RESOURCES += $$PWD/utils.qrc osx { + HEADERS += $$PWD/autoreleasepool.h OBJECTIVE_SOURCES += \ $$PWD/fileutils_mac.mm LIBS += -framework Foundation diff --git a/src/plugins/coreplugin/locator/spotlightlocatorfilter.mm b/src/plugins/coreplugin/locator/spotlightlocatorfilter.mm index 6726bc9405c..4b632745adb 100644 --- a/src/plugins/coreplugin/locator/spotlightlocatorfilter.mm +++ b/src/plugins/coreplugin/locator/spotlightlocatorfilter.mm @@ -30,6 +30,7 @@ #include "spotlightlocatorfilter.h" +#include #include #include @@ -82,7 +83,7 @@ SpotlightIterator::SpotlightIterator(const QString &expression) m_queueIndex(-1), m_finished(false) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + Utils::AutoreleasePool pool; Q_UNUSED(pool) NSPredicate *predicate = [NSPredicate predicateWithFormat:expression.toNSString()]; m_query = [[NSMetadataQuery alloc] init]; m_query.predicate = predicate; @@ -109,7 +110,6 @@ SpotlightIterator::SpotlightIterator(const QString &expression) m_waitForItems.wakeAll(); }] retain]; [m_query startQuery]; - [pool release]; } SpotlightIterator::~SpotlightIterator() @@ -161,7 +161,7 @@ void SpotlightIterator::ensureNext() return; if (m_index >= 10000) // limit the amount of data that is passed on return; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + Utils::AutoreleasePool pool; Q_UNUSED(pool) // check if there are items in the queue, otherwise wait for some m_mutex.lock(); bool itemAvailable = (m_queueIndex + 1 < m_queue.count); @@ -177,7 +177,6 @@ void SpotlightIterator::ensureNext() } m_mutex.unlock(); - [pool release]; } // #pragma mark -- SpotlightLocatorFilter diff --git a/src/plugins/help/macwebkithelpviewer.mm b/src/plugins/help/macwebkithelpviewer.mm index 096d0c34129..b5476d32f73 100644 --- a/src/plugins/help/macwebkithelpviewer.mm +++ b/src/plugins/help/macwebkithelpviewer.mm @@ -34,6 +34,7 @@ #include "openpagesmanager.h" #include +#include #include #include @@ -68,26 +69,7 @@ #import #import -// #pragma mark -- AutoreleasePool - -class AutoreleasePool -{ -public: - AutoreleasePool(); - ~AutoreleasePool(); -private: - NSAutoreleasePool *pool; -}; - -AutoreleasePool::AutoreleasePool() -{ - pool = [[NSAutoreleasePool alloc] init]; -} - -AutoreleasePool::~AutoreleasePool() -{ - [pool release]; -} +using namespace Utils; // #pragma mark -- mac helpers