summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2019-10-15 12:30:24 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2019-10-23 16:18:11 +0200
commit6b40affc36fa2882a1b9148e6fa58decff5d5d91 (patch)
treecc163b806f5e6b1ab542f20fcbd78f39f7f6225a /src
parent9188076ae9c7beff8e693d953c1e26f413680951 (diff)
ObjCStrongReference - re-implement via DarwinBluetooth::StrongReference
Change-Id: I99bc8761c648363cca89c74ecc587987e5e7cf01 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/darwin/btcentralmanager.mm37
-rw-r--r--src/bluetooth/darwin/btdevicepair.mm4
-rw-r--r--src/bluetooth/darwin/btledeviceinquiry.mm4
-rw-r--r--src/bluetooth/darwin/btobexsession.mm12
-rw-r--r--src/bluetooth/darwin/btperipheralmanager.mm19
-rw-r--r--src/bluetooth/darwin/btservicerecord.mm14
-rw-r--r--src/bluetooth/darwin/btutility.mm12
-rw-r--r--src/bluetooth/darwin/btutility_p.h77
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_macos.mm4
-rw-r--r--src/bluetooth/qlowenergycontroller_darwin.mm10
10 files changed, 67 insertions, 126 deletions
diff --git a/src/bluetooth/darwin/btcentralmanager.mm b/src/bluetooth/darwin/btcentralmanager.mm
index 7e0bdda7..86950302 100644
--- a/src/bluetooth/darwin/btcentralmanager.mm
+++ b/src/bluetooth/darwin/btcentralmanager.mm
@@ -91,7 +91,7 @@ ObjCStrongReference<NSError> qt_timeoutNSError(OperationTimeout type)
NSError *nsError = [[NSError alloc] initWithDomain:CBErrorDomain
code:CBErrorOperationCancelled
userInfo:nil];
- return ObjCStrongReference<NSError>(nsError, false /*do not retain, done already*/);
+ return ObjCStrongReference<NSError>(nsError, RetainPolicy::noInitialRetain);
}
auto qt_find_watchdog(const std::vector<GCDTimer> &watchdogs, id object, OperationTimeout type)
@@ -215,9 +215,9 @@ QT_USE_NAMESPACE
// Strangely enough, I can not reproduce this anymore, so this
// part is simplified now. To be investigated though.
- visitedServices.reset(nil);
- servicesToVisit.reset(nil);
- servicesToVisitNext.reset(nil);
+ visitedServices.reset();
+ servicesToVisit.reset();
+ servicesToVisitNext.reset();
[manager setDelegate:nil];
[manager release];
@@ -241,7 +241,7 @@ QT_USE_NAMESPACE
{
using namespace DarwinBluetooth;
- GCDTimer newWatcher([[GCDTimerObjC alloc] initWithDelegate:self], false /*do not retain*/);
+ GCDTimer newWatcher([[GCDTimerObjC alloc] initWithDelegate:self], RetainPolicy::noInitialRetain);
[newWatcher watchAfter:object withTimeoutType:type];
timeoutWatchdogs.push_back(newWatcher);
[newWatcher startWithTimeout:timeoutMS step:200];
@@ -492,10 +492,10 @@ QT_USE_NAMESPACE
emit notifier->serviceDiscoveryFinished();
} else {
// 'reset' also calls retain on a parameter.
- servicesToVisitNext.reset(nil);
- servicesToVisit.reset([NSMutableArray arrayWithArray:services]);
+ servicesToVisitNext.reset();
+ servicesToVisit.reset([NSMutableArray arrayWithArray:services], RetainPolicy::doInitialRetain);
currentService = 0;
- visitedServices.reset([NSMutableSet setWithCapacity:peripheral.services.count]);
+ visitedServices.reset([NSMutableSet setWithCapacity:peripheral.services.count], RetainPolicy::doInitialRetain);
CBService *const s = [services objectAtIndex:currentService];
[visitedServices addObject:s];
@@ -1003,9 +1003,9 @@ QT_USE_NAMESPACE
Q_ASSERT_X(!qtUuid.isNull(), Q_FUNC_INFO, "invalid uuid");
Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
- ObjCStrongReference<NSMutableArray> toVisit([NSMutableArray arrayWithArray:peripheral.services], true);
- ObjCStrongReference<NSMutableArray> toVisitNext([[NSMutableArray alloc] init], false);
- ObjCStrongReference<NSMutableSet> visitedNodes([[NSMutableSet alloc] init], false);
+ ObjCStrongReference<NSMutableArray> toVisit([NSMutableArray arrayWithArray:peripheral.services], RetainPolicy::doInitialRetain);
+ ObjCStrongReference<NSMutableArray> toVisitNext([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
+ ObjCStrongReference<NSMutableSet> visitedNodes([[NSMutableSet alloc] init], RetainPolicy::noInitialRetain);
while (true) {
for (NSUInteger i = 0, e = [toVisit count]; i < e; ++i) {
@@ -1021,8 +1021,8 @@ QT_USE_NAMESPACE
if (![toVisitNext count])
return nil;
- toVisit.resetWithoutRetain(toVisitNext.take());
- toVisitNext.resetWithoutRetain([[NSMutableArray alloc] init]);
+ toVisit.swap(toVisitNext);
+ toVisitNext.reset([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
}
return nil;
@@ -1425,7 +1425,7 @@ QT_USE_NAMESPACE
} else if (service.includedServices && service.includedServices.count) {
// Now we have even more services to do included services discovery ...
if (!servicesToVisitNext)
- servicesToVisitNext.reset([NSMutableArray arrayWithArray:service.includedServices]);
+ servicesToVisitNext.reset([NSMutableArray arrayWithArray:service.includedServices], RetainPolicy::doInitialRetain);
else
[servicesToVisitNext addObjectsFromArray:service.includedServices];
}
@@ -1447,7 +1447,8 @@ QT_USE_NAMESPACE
// No services to visit more on this 'level'.
if (servicesToVisitNext && [servicesToVisitNext count]) {
- servicesToVisit.resetWithoutRetain(servicesToVisitNext.take());
+ servicesToVisit.swap(servicesToVisitNext);
+ servicesToVisitNext.reset();
currentService = 0;
for (const NSUInteger e = [servicesToVisit count]; currentService < e; ++currentService) {
@@ -1464,9 +1465,9 @@ QT_USE_NAMESPACE
// Finally, if we're here, the service discovery is done!
// Release all these things now, no need to prolong their lifetime.
- visitedServices.reset(nil);
- servicesToVisit.reset(nil);
- servicesToVisitNext.reset(nil);
+ visitedServices.reset();
+ servicesToVisit.reset();
+ servicesToVisitNext.reset();
if (notifier)
emit notifier->serviceDiscoveryFinished();
diff --git a/src/bluetooth/darwin/btdevicepair.mm b/src/bluetooth/darwin/btdevicepair.mm
index 2c212c2d..947385f2 100644
--- a/src/bluetooth/darwin/btdevicepair.mm
+++ b/src/bluetooth/darwin/btdevicepair.mm
@@ -50,10 +50,10 @@ namespace DarwinBluetooth {
ObjCStrongReference<IOBluetoothDevice> device_with_address(const QBluetoothAddress &address)
{
if (address.isNull())
- return ObjCStrongReference<IOBluetoothDevice>(nil, false);
+ return {};
const BluetoothDeviceAddress &iobtAddress = iobluetooth_address(address);
- ObjCStrongReference<IOBluetoothDevice> res([[IOBluetoothDevice deviceWithAddress:&iobtAddress] retain], false);
+ ObjCStrongReference<IOBluetoothDevice> res([IOBluetoothDevice deviceWithAddress:&iobtAddress], RetainPolicy::doInitialRetain);
return res;
}
diff --git a/src/bluetooth/darwin/btledeviceinquiry.mm b/src/bluetooth/darwin/btledeviceinquiry.mm
index 4ac8f0fb..107ffc5b 100644
--- a/src/bluetooth/darwin/btledeviceinquiry.mm
+++ b/src/bluetooth/darwin/btledeviceinquiry.mm
@@ -211,7 +211,7 @@ QT_USE_NAMESPACE
if (inquiryTimeoutMS > 0) {
[elapsedTimer cancelTimer];
- elapsedTimer.resetWithoutRetain([[GCDTimerObjC alloc] initWithDelegate:self]);
+ elapsedTimer.reset([[GCDTimerObjC alloc] initWithDelegate:self], RetainPolicy::noInitialRetain);
[elapsedTimer startWithTimeout:inquiryTimeoutMS step:timeStepMS];
}
@@ -239,7 +239,7 @@ QT_USE_NAMESPACE
// we'll receive 'PoweredOn' state update later.
// No change in internalState. Wait for 30 seconds.
[elapsedTimer cancelTimer];
- elapsedTimer.resetWithoutRetain([[GCDTimerObjC alloc] initWithDelegate:self]);
+ elapsedTimer.reset([[GCDTimerObjC alloc] initWithDelegate:self], RetainPolicy::noInitialRetain);
[elapsedTimer startWithTimeout:powerOffTimeoutMS step:300];
return;
}
diff --git a/src/bluetooth/darwin/btobexsession.mm b/src/bluetooth/darwin/btobexsession.mm
index ba48aab0..ecf010ba 100644
--- a/src/bluetooth/darwin/btobexsession.mm
+++ b/src/bluetooth/darwin/btobexsession.mm
@@ -61,6 +61,8 @@ OBEXSessionDelegate::~OBEXSessionDelegate()
namespace {
+using NSDataPtr = NSMutableData *;
+
struct OBEXHeader
{
OBEXHeader() : headerID(0)
@@ -326,7 +328,7 @@ ObjCStrongReference<NSMutableData> next_data_chunk(QIODevice &inputStream, IOBlu
}
ObjCStrongReference<NSMutableData> chunk([NSMutableData dataWithBytes:block.data()
- length:realSize], true);
+ length:realSize], RetainPolicy::doInitialRetain);
if (chunk && [chunk length]) {
// If it actually was the last chunk
// of a length == maxBodySize, we'll
@@ -653,7 +655,7 @@ QT_USE_NAMESPACE
return kOBEXBadArgumentError;
}
- ObjCStrongReference<NSMutableData> headers([[NSMutableData alloc] init], false);
+ ObjCStrongReference<NSMutableData> headers([[NSMutableData alloc] init], RetainPolicy::noInitialRetain);
if (!headers) {
qCWarning(QT_BT_DARWIN) << "failed to allocate headers";
return kOBEXNoResourcesError;
@@ -705,8 +707,8 @@ QT_USE_NAMESPACE
delegate->OBEXPutDataSent([chunk length], fileSize);
bytesSent = [chunk length];
- headersData = headers.take();
- bodyData = chunk.take();
+ headersData = NSDataPtr(headers.release());
+ bodyData = NSDataPtr(chunk.release());
inputStream = input;
} else {
// PUT request failed and we now
@@ -779,7 +781,7 @@ QT_USE_NAMESPACE
} else {
[bodyData release];
bytesSent += [chunk length];
- bodyData = chunk.take();//retained already.
+ bodyData = NSDataPtr(chunk.release());
if (delegate && !inputStream->isSequential())
delegate->OBEXPutDataSent(bytesSent, inputStream->size());
diff --git a/src/bluetooth/darwin/btperipheralmanager.mm b/src/bluetooth/darwin/btperipheralmanager.mm
index f282b0f7..3336d8c5 100644
--- a/src/bluetooth/darwin/btperipheralmanager.mm
+++ b/src/bluetooth/darwin/btperipheralmanager.mm
@@ -91,7 +91,7 @@ ObjCStrongReference<CBMutableCharacteristic> create_characteristic(const QLowEne
properties:cb_properties(data)
value:nil
permissions:cb_permissions(data)],
- false /*do not retain*/);
+ RetainPolicy::noInitialRetain);
return ch;
}
@@ -118,15 +118,15 @@ ObjCStrongReference<CBMutableDescriptor> create_descriptor(const QLowEnergyDescr
ObjCStrongReference<NSObject> value;
if (data.uuid() == QBluetoothUuid::CharacteristicUserDescription) {
const QString asQString(QString::fromUtf8(data.value()));
- value.reset(asQString.toNSString());
+ value.reset(asQString.toNSString(), RetainPolicy::doInitialRetain); // toNSString is auto-released, we have to retain.
} else {
const auto nsData = data_from_bytearray(data.value());
- value.reset(nsData.data());
+ value.reset(nsData.data(), RetainPolicy::doInitialRetain);
}
const ObjCStrongReference<CBMutableDescriptor> d([[CBMutableDescriptor alloc]
initWithType:cb_uuid(data.uuid())
- value:value], false /*do not retain*/);
+ value:value], RetainPolicy::noInitialRetain);
return d;
}
@@ -230,6 +230,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
- (QSharedPointer<QLowEnergyServicePrivate>)addService:(const QLowEnergyServiceData &)data
{
using QLES = QLowEnergyService;
+ using namespace DarwinBluetooth;
const auto nEntries = qt_countGATTEntries(data);
if (!nEntries || nEntries > std::numeric_limits<QLowEnergyHandle>::max() - lastHandle) {
@@ -244,7 +245,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
const ObjCStrongReference<CBMutableService>
newCBService([[CBMutableService alloc] initWithType:cbUUID primary:primary],
- false /*do not retain*/);
+ RetainPolicy::noInitialRetain);
if (!newCBService) {
qCCritical(QT_BT_DARWIN) << "addService: failed to create CBMutableService";
@@ -374,6 +375,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
- (void)write:(const QByteArray &)value
charHandle:(QLowEnergyHandle)charHandle
{
+ using namespace DarwinBluetooth;
+
if (!notifier)
return;
@@ -402,7 +405,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
// We copy data here: sending update requests is async (see sendUpdateRequests),
// by the time we're allowed to actually send them, the data can change again
// and we'll send an 'out of order' value.
- const ObjCStrongReference<NSData> copy([NSData dataWithData:nsData], true);
+ const ObjCStrongReference<NSData> copy([NSData dataWithData:nsData], RetainPolicy::doInitialRetain);
updateQueue.push_back(UpdateRequest{charHandle, copy});
[self sendUpdateRequests];
}
@@ -596,6 +599,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
- (void)peripheralManager:(CBPeripheralManager *)peripheral
didReceiveWriteRequests:(NSArray *)requests
{
+ using namespace DarwinBluetooth;
+
QT_BT_MAC_AUTORELEASEPOOL
if (peripheral != manager || !notifier) {
@@ -633,7 +638,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
value.length = pair.second;
emit notifier->characteristicUpdated(handle, qt_bytearray(value));
const ObjCStrongReference<NSData> copy([NSData dataWithData:value],
- true);
+ RetainPolicy::doInitialRetain);
updateQueue.push_back(UpdateRequest{handle, copy});
}
diff --git a/src/bluetooth/darwin/btservicerecord.mm b/src/bluetooth/darwin/btservicerecord.mm
index 82067558..dd711504 100644
--- a/src/bluetooth/darwin/btservicerecord.mm
+++ b/src/bluetooth/darwin/btservicerecord.mm
@@ -105,37 +105,37 @@ Number variant_to_nsnumber(const QVariant &);
template<>
Number variant_to_nsnumber<unsigned char>(const QVariant &var)
{
- return Number([NSNumber numberWithUnsignedChar:var.value<unsigned char>()], true);
+ return Number([NSNumber numberWithUnsignedChar:var.value<unsigned char>()], RetainPolicy::doInitialRetain);
}
template<>
Number variant_to_nsnumber<unsigned short>(const QVariant &var)
{
- return Number([NSNumber numberWithUnsignedShort:var.value<unsigned short>()], true);
+ return Number([NSNumber numberWithUnsignedShort:var.value<unsigned short>()], RetainPolicy::doInitialRetain);
}
template<>
Number variant_to_nsnumber<unsigned>(const QVariant &var)
{
- return Number([NSNumber numberWithUnsignedInt:var.value<unsigned>()], true);
+ return Number([NSNumber numberWithUnsignedInt:var.value<unsigned>()], RetainPolicy::doInitialRetain);
}
template<>
Number variant_to_nsnumber<char>(const QVariant &var)
{
- return Number([NSNumber numberWithChar:var.value<char>()], true);
+ return Number([NSNumber numberWithChar:var.value<char>()], RetainPolicy::doInitialRetain);
}
template<>
Number variant_to_nsnumber<short>(const QVariant &var)
{
- return Number([NSNumber numberWithShort:var.value<short>()], true);
+ return Number([NSNumber numberWithShort:var.value<short>()], RetainPolicy::doInitialRetain);
}
template<>
Number variant_to_nsnumber<int>(const QVariant &var)
{
- return Number([NSNumber numberWithInt:var.value<int>()], true);
+ return Number([NSNumber numberWithInt:var.value<int>()], RetainPolicy::doInitialRetain);
}
template<class ValueType>
@@ -432,7 +432,7 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn
if (!attributeIds.size())
return dict;
- dict.reset([[NSMutableDictionary alloc] init]);
+ dict.reset([[NSMutableDictionary alloc] init], RetainPolicy::noInitialRetain);
for (quint16 key : attributeIds) {
if (key == QSInfo::ProtocolDescriptorList) // We handle it in a special way.
diff --git a/src/bluetooth/darwin/btutility.mm b/src/bluetooth/darwin/btutility.mm
index d04a7454..07c22c1c 100644
--- a/src/bluetooth/darwin/btutility.mm
+++ b/src/bluetooth/darwin/btutility.mm
@@ -117,7 +117,7 @@ ObjCStrongReference<IOBluetoothSDPUUID> iobluetooth_uuid(const QBluetoothUuid &u
const quint128 intVal(uuid.toUInt128());
const ObjCStrongReference<IOBluetoothSDPUUID> iobtUUID([IOBluetoothSDPUUID uuidWithBytes:intVal.data
- length:nBytes], true);
+ length:nBytes], RetainPolicy::doInitialRetain);
return iobtUUID;
}
@@ -223,7 +223,7 @@ ObjCStrongReference<CBUUID> cb_uuid(const QBluetoothUuid &qtUuid)
if (!cfUuid)
return ObjCStrongReference<CBUUID>();
- ObjCStrongReference<CBUUID> cbUuid([CBUUID UUIDWithCFUUID:cfUuid], true); //true == retain.
+ ObjCStrongReference<CBUUID> cbUuid([CBUUID UUIDWithCFUUID:cfUuid], RetainPolicy::doInitialRetain);
return cbUuid;
}
@@ -312,9 +312,9 @@ QByteArray qt_bytearray(NSObject *obj)
ObjCStrongReference<NSData> data_from_bytearray(const QByteArray & qtData)
{
if (!qtData.size())
- return ObjCStrongReference<NSData>([[NSData alloc] init], false);
+ return ObjCStrongReference<NSData>([[NSData alloc] init], RetainPolicy::noInitialRetain);
- ObjCStrongReference<NSData> result([NSData dataWithBytes:qtData.constData() length:qtData.size()], true);
+ ObjCStrongReference<NSData> result([NSData dataWithBytes:qtData.constData() length:qtData.size()], RetainPolicy::doInitialRetain);
return result;
}
@@ -323,9 +323,9 @@ ObjCStrongReference<NSMutableData> mutable_data_from_bytearray(const QByteArray
using MutableData = ObjCStrongReference<NSMutableData>;
if (!qtData.size())
- return MutableData([[NSMutableData alloc] init], false);
+ return MutableData([[NSMutableData alloc] init], RetainPolicy::noInitialRetain);
- MutableData result([[NSMutableData alloc] initWithLength:qtData.size()], false);
+ MutableData result([[NSMutableData alloc] initWithLength:qtData.size()], RetainPolicy::noInitialRetain);
[result replaceBytesInRange:NSMakeRange(0, qtData.size())
withBytes:qtData.constData()];
return result;
diff --git a/src/bluetooth/darwin/btutility_p.h b/src/bluetooth/darwin/btutility_p.h
index 6854522f..b65544e2 100644
--- a/src/bluetooth/darwin/btutility_p.h
+++ b/src/bluetooth/darwin/btutility_p.h
@@ -113,88 +113,19 @@ private:
#define QT_BT_MAC_AUTORELEASEPOOL const QMacAutoReleasePool pool;
template<class T>
-class ObjCStrongReference {
+class ObjCStrongReference final : public StrongReference {
public:
- ObjCStrongReference()
- : m_ptr(nil)
- {
- }
- ObjCStrongReference(T *obj, bool retain)
- {
- if (retain)
- m_ptr = [obj retain];
- else
- m_ptr = obj; // For example, created with initWithXXXX.
- }
- ObjCStrongReference(const ObjCStrongReference &rhs)
- {
- m_ptr = [rhs.m_ptr retain];
- }
- ObjCStrongReference &operator = (const ObjCStrongReference &rhs)
- {
- // "Old-style" implementation:
- if (this != &rhs && m_ptr != rhs.m_ptr) {
- [m_ptr release];
- m_ptr = [rhs.m_ptr retain];
- }
-
- return *this;
- }
-
-#ifdef Q_COMPILER_RVALUE_REFS
- ObjCStrongReference(ObjCStrongReference &&xval)
- {
- m_ptr = xval.m_ptr;
- xval.m_ptr = nil;
- }
-
- ObjCStrongReference &operator = (ObjCStrongReference &&xval)
- {
- m_ptr = xval.m_ptr;
- xval.m_ptr = nil;
- return *this;
- }
-#endif
-
- ~ObjCStrongReference()
- {
- [m_ptr release];
- }
-
- void reset(T *newVal)
- {
- if (m_ptr != newVal) {
- [m_ptr release];
- m_ptr = [newVal retain];
- }
- }
-
- void resetWithoutRetain(T *newVal)
- {
- if (m_ptr != newVal) {
- [m_ptr release];
- m_ptr = newVal;
- }
- }
+ using StrongReference::StrongReference;
operator T *() const
{
- return m_ptr;
+ return this->getAs<T>();
}
T *data() const
{
- return m_ptr;
+ return this->getAs<T>();
}
-
- T *take()
- {
- T * p = m_ptr;
- m_ptr = nil;
- return p;
- }
-private:
- T *m_ptr;
};
QString qt_address(NSString *address);
diff --git a/src/bluetooth/qbluetoothlocaldevice_macos.mm b/src/bluetooth/qbluetoothlocaldevice_macos.mm
index 462453ac..ec2accce 100644
--- a/src/bluetooth/qbluetoothlocaldevice_macos.mm
+++ b/src/bluetooth/qbluetoothlocaldevice_macos.mm
@@ -165,6 +165,7 @@ void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &addre
using DarwinBluetooth::device_with_address;
using DarwinBluetooth::ObjCStrongReference;
+ using DarwinBluetooth::RetainPolicy;
// That's a really special case on OS X.
if (pairing == QBluetoothLocalDevice::Unpaired)
@@ -194,7 +195,8 @@ void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &addre
// That's a totally new request ('Paired', since we are here).
// Even if this device is paired (not by our local device), I still create a pairing request,
// it'll just finish with success (skipping any intermediate steps).
- PairingRequest newRequest([[ObjCPairingRequest alloc] initWithTarget:address delegate:this], false);
+ PairingRequest newRequest([[ObjCPairingRequest alloc] initWithTarget:address delegate:this],
+ RetainPolicy::noInitialRetain);
if (!newRequest) {
qCCritical(QT_BT_DARWIN) << "failed to allocate a new pairing request";
emitError(QBluetoothLocalDevice::PairingError, true);
diff --git a/src/bluetooth/qlowenergycontroller_darwin.mm b/src/bluetooth/qlowenergycontroller_darwin.mm
index 34e6cab4..bbe7a4a6 100644
--- a/src/bluetooth/qlowenergycontroller_darwin.mm
+++ b/src/bluetooth/qlowenergycontroller_darwin.mm
@@ -413,9 +413,9 @@ void QLowEnergyControllerPrivateDarwin::_q_serviceDiscoveryFinished()
discoveredCBServices.insert(newService->uuid, cbService);
}
- ObjCStrongReference<NSMutableArray> toVisit([[NSMutableArray alloc] initWithArray:services], false);
- ObjCStrongReference<NSMutableArray> toVisitNext([[NSMutableArray alloc] init], false);
- ObjCStrongReference<NSMutableSet> visited([[NSMutableSet alloc] init], false);
+ ObjCStrongReference<NSMutableArray> toVisit([[NSMutableArray alloc] initWithArray:services], RetainPolicy::noInitialRetain);
+ ObjCStrongReference<NSMutableArray> toVisitNext([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
+ ObjCStrongReference<NSMutableSet> visited([[NSMutableSet alloc] init], RetainPolicy::noInitialRetain);
while (true) {
for (NSUInteger i = 0, e = [toVisit count]; i < e; ++i) {
@@ -453,8 +453,8 @@ void QLowEnergyControllerPrivateDarwin::_q_serviceDiscoveryFinished()
}
}
- toVisit.resetWithoutRetain(toVisitNext.take());
- toVisitNext.resetWithoutRetain([[NSMutableArray alloc] init]);
+ toVisit.swap(toVisitNext);
+ toVisitNext.reset([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
}
} else {
qCDebug(QT_BT_DARWIN) << "no services found";