Skip to content

Commit 645a79e

Browse files
committed
Replacing "NEEDS_DISPATCH_RETAIN_RELEASE" with "!OS_OBJECT_USE_OBJC"
1 parent 55e06b3 commit 645a79e

File tree

2 files changed

+32
-84
lines changed

2 files changed

+32
-84
lines changed

GCD/GCDAsyncSocket.m

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@
3232
// For more information see: https://github.com/robbiehanson/CocoaAsyncSocket/wiki/ARC
3333
#endif
3434

35-
/**
36-
* Does ARC support support GCD objects?
37-
* It does if the minimum deployment target is iOS 6+ or Mac OS X 10.8+
38-
**/
39-
#if TARGET_OS_IPHONE
40-
41-
// Compiling for iOS
42-
43-
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
44-
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
45-
#else // iOS 5.X or earlier
46-
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
47-
#endif
48-
49-
#else
50-
51-
// Compiling for Mac OS X
52-
53-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
54-
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
55-
#else
56-
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
57-
#endif
58-
59-
#endif
60-
6135

6236
#if 0
6337

@@ -1051,7 +1025,7 @@ - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQu
10511025
delegate = aDelegate;
10521026
delegateQueue = dq;
10531027

1054-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1028+
#if !OS_OBJECT_USE_OBJC
10551029
if (dq) dispatch_retain(dq);
10561030
#endif
10571031

@@ -1069,7 +1043,7 @@ - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQu
10691043
@"The given socketQueue parameter must not be a concurrent queue.");
10701044

10711045
socketQueue = sq;
1072-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1046+
#if !OS_OBJECT_USE_OBJC
10731047
dispatch_retain(sq);
10741048
#endif
10751049
}
@@ -1128,12 +1102,12 @@ - (void)dealloc
11281102

11291103
delegate = nil;
11301104

1131-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1105+
#if !OS_OBJECT_USE_OBJC
11321106
if (delegateQueue) dispatch_release(delegateQueue);
11331107
#endif
11341108
delegateQueue = NULL;
11351109

1136-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1110+
#if !OS_OBJECT_USE_OBJC
11371111
if (socketQueue) dispatch_release(socketQueue);
11381112
#endif
11391113
socketQueue = NULL;
@@ -1212,7 +1186,7 @@ - (void)setDelegateQueue:(dispatch_queue_t)newDelegateQueue synchronously:(BOOL)
12121186
{
12131187
dispatch_block_t block = ^{
12141188

1215-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1189+
#if !OS_OBJECT_USE_OBJC
12161190
if (delegateQueue) dispatch_release(delegateQueue);
12171191
if (newDelegateQueue) dispatch_retain(newDelegateQueue);
12181192
#endif
@@ -1269,7 +1243,7 @@ - (void)setDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQ
12691243

12701244
delegate = newDelegate;
12711245

1272-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1246+
#if !OS_OBJECT_USE_OBJC
12731247
if (delegateQueue) dispatch_release(delegateQueue);
12741248
if (newDelegateQueue) dispatch_retain(newDelegateQueue);
12751249
#endif
@@ -1675,7 +1649,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
16751649

16761650
dispatch_source_set_cancel_handler(accept4Source, ^{
16771651

1678-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1652+
#if !OS_OBJECT_USE_OBJC
16791653
LogVerbose(@"dispatch_release(accept4Source)");
16801654
dispatch_release(acceptSource);
16811655
#endif
@@ -1709,7 +1683,7 @@ - (BOOL)acceptOnInterface:(NSString *)inInterface port:(uint16_t)port error:(NSE
17091683

17101684
dispatch_source_set_cancel_handler(accept6Source, ^{
17111685

1712-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1686+
#if !OS_OBJECT_USE_OBJC
17131687
LogVerbose(@"dispatch_release(accept6Source)");
17141688
dispatch_release(acceptSource);
17151689
#endif
@@ -1846,7 +1820,7 @@ - (BOOL)doAccept:(int)parentSocketFD
18461820
}
18471821

18481822
// Release the socket queue returned from the delegate (it was retained by acceptedSocket)
1849-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1823+
#if !OS_OBJECT_USE_OBJC
18501824
if (childSocketQueue) dispatch_release(childSocketQueue);
18511825
#endif
18521826

@@ -2601,7 +2575,7 @@ - (void)startConnectTimeout:(NSTimeInterval)timeout
26012575
[self doConnectTimeout];
26022576
}});
26032577

2604-
#if NEEDS_DISPATCH_RETAIN_RELEASE
2578+
#if !OS_OBJECT_USE_OBJC
26052579
dispatch_source_t theConnectTimer = connectTimer;
26062580
dispatch_source_set_cancel_handler(connectTimer, ^{
26072581
LogVerbose(@"dispatch_release(connectTimer)");
@@ -3668,7 +3642,7 @@ - (void)setupReadAndWriteSourcesForNewlyConnectedSocket:(int)socketFD
36683642

36693643
__block int socketFDRefCount = 2;
36703644

3671-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3645+
#if !OS_OBJECT_USE_OBJC
36723646
dispatch_source_t theReadSource = readSource;
36733647
dispatch_source_t theWriteSource = writeSource;
36743648
#endif
@@ -3677,7 +3651,7 @@ - (void)setupReadAndWriteSourcesForNewlyConnectedSocket:(int)socketFD
36773651

36783652
LogVerbose(@"readCancelBlock");
36793653

3680-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3654+
#if !OS_OBJECT_USE_OBJC
36813655
LogVerbose(@"dispatch_release(readSource)");
36823656
dispatch_release(theReadSource);
36833657
#endif
@@ -3693,7 +3667,7 @@ - (void)setupReadAndWriteSourcesForNewlyConnectedSocket:(int)socketFD
36933667

36943668
LogVerbose(@"writeCancelBlock");
36953669

3696-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3670+
#if !OS_OBJECT_USE_OBJC
36973671
LogVerbose(@"dispatch_release(writeSource)");
36983672
dispatch_release(theWriteSource);
36993673
#endif
@@ -5104,7 +5078,7 @@ - (void)setupReadTimerWithTimeout:(NSTimeInterval)timeout
51045078
[self doReadTimeout];
51055079
}});
51065080

5107-
#if NEEDS_DISPATCH_RETAIN_RELEASE
5081+
#if !OS_OBJECT_USE_OBJC
51085082
dispatch_source_t theReadTimer = readTimer;
51095083
dispatch_source_set_cancel_handler(readTimer, ^{
51105084
LogVerbose(@"dispatch_release(readTimer)");
@@ -5734,7 +5708,7 @@ - (void)setupWriteTimerWithTimeout:(NSTimeInterval)timeout
57345708
[self doWriteTimeout];
57355709
}});
57365710

5737-
#if NEEDS_DISPATCH_RETAIN_RELEASE
5711+
#if !OS_OBJECT_USE_OBJC
57385712
dispatch_source_t theWriteTimer = writeTimer;
57395713
dispatch_source_set_cancel_handler(writeTimer, ^{
57405714
LogVerbose(@"dispatch_release(writeTimer)");

GCD/GCDAsyncUdpSocket.m

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,6 @@
1515
// For more information see: https://github.com/robbiehanson/CocoaAsyncSocket/wiki/ARC
1616
#endif
1717

18-
/**
19-
* Does ARC support support GCD objects?
20-
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
21-
**/
22-
#if TARGET_OS_IPHONE
23-
24-
// Compiling for iOS
25-
26-
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
27-
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
28-
#else // iOS 5.X or earlier
29-
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
30-
#endif
31-
32-
#else
33-
34-
// Compiling for Mac OS X
35-
36-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
37-
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
38-
#else
39-
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
40-
#endif
41-
42-
#endif
43-
4418
#if TARGET_OS_IPHONE
4519
#import <CFNetwork/CFNetwork.h>
4620
#import <UIKit/UIKit.h>
@@ -390,7 +364,7 @@ - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQu
390364
if (dq)
391365
{
392366
delegateQueue = dq;
393-
#if NEEDS_DISPATCH_RETAIN_RELEASE
367+
#if !OS_OBJECT_USE_OBJC
394368
dispatch_retain(delegateQueue);
395369
#endif
396370
}
@@ -411,7 +385,7 @@ - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQu
411385
@"The given socketQueue parameter must not be a concurrent queue.");
412386

413387
socketQueue = sq;
414-
#if NEEDS_DISPATCH_RETAIN_RELEASE
388+
#if !OS_OBJECT_USE_OBJC
415389
dispatch_retain(socketQueue);
416390
#endif
417391
}
@@ -475,12 +449,12 @@ - (void)dealloc
475449
}
476450

477451
delegate = nil;
478-
#if NEEDS_DISPATCH_RETAIN_RELEASE
452+
#if !OS_OBJECT_USE_OBJC
479453
if (delegateQueue) dispatch_release(delegateQueue);
480454
#endif
481455
delegateQueue = NULL;
482456

483-
#if NEEDS_DISPATCH_RETAIN_RELEASE
457+
#if !OS_OBJECT_USE_OBJC
484458
if (socketQueue) dispatch_release(socketQueue);
485459
#endif
486460
socketQueue = NULL;
@@ -559,7 +533,7 @@ - (void)setDelegateQueue:(dispatch_queue_t)newDelegateQueue synchronously:(BOOL)
559533
{
560534
dispatch_block_t block = ^{
561535

562-
#if NEEDS_DISPATCH_RETAIN_RELEASE
536+
#if !OS_OBJECT_USE_OBJC
563537
if (delegateQueue) dispatch_release(delegateQueue);
564538
if (newDelegateQueue) dispatch_retain(newDelegateQueue);
565539
#endif
@@ -616,7 +590,7 @@ - (void)setDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQ
616590

617591
delegate = newDelegate;
618592

619-
#if NEEDS_DISPATCH_RETAIN_RELEASE
593+
#if !OS_OBJECT_USE_OBJC
620594
if (delegateQueue) dispatch_release(delegateQueue);
621595
if (newDelegateQueue) dispatch_retain(newDelegateQueue);
622596
#endif
@@ -1787,7 +1761,7 @@ - (void)setupSendAndReceiveSourcesForSocket4
17871761

17881762
int theSocketFD = socket4FD;
17891763

1790-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1764+
#if !OS_OBJECT_USE_OBJC
17911765
dispatch_source_t theSendSource = send4Source;
17921766
dispatch_source_t theReceiveSource = receive4Source;
17931767
#endif
@@ -1796,7 +1770,7 @@ - (void)setupSendAndReceiveSourcesForSocket4
17961770

17971771
LogVerbose(@"send4CancelBlock");
17981772

1799-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1773+
#if !OS_OBJECT_USE_OBJC
18001774
LogVerbose(@"dispatch_release(send4Source)");
18011775
dispatch_release(theSendSource);
18021776
#endif
@@ -1812,7 +1786,7 @@ - (void)setupSendAndReceiveSourcesForSocket4
18121786

18131787
LogVerbose(@"receive4CancelBlock");
18141788

1815-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1789+
#if !OS_OBJECT_USE_OBJC
18161790
LogVerbose(@"dispatch_release(receive4Source)");
18171791
dispatch_release(theReceiveSource);
18181792
#endif
@@ -1898,7 +1872,7 @@ - (void)setupSendAndReceiveSourcesForSocket6
18981872

18991873
int theSocketFD = socket6FD;
19001874

1901-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1875+
#if !OS_OBJECT_USE_OBJC
19021876
dispatch_source_t theSendSource = send6Source;
19031877
dispatch_source_t theReceiveSource = receive6Source;
19041878
#endif
@@ -1907,7 +1881,7 @@ - (void)setupSendAndReceiveSourcesForSocket6
19071881

19081882
LogVerbose(@"send6CancelBlock");
19091883

1910-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1884+
#if !OS_OBJECT_USE_OBJC
19111885
LogVerbose(@"dispatch_release(send6Source)");
19121886
dispatch_release(theSendSource);
19131887
#endif
@@ -1923,7 +1897,7 @@ - (void)setupSendAndReceiveSourcesForSocket6
19231897

19241898
LogVerbose(@"receive6CancelBlock");
19251899

1926-
#if NEEDS_DISPATCH_RETAIN_RELEASE
1900+
#if !OS_OBJECT_USE_OBJC
19271901
LogVerbose(@"dispatch_release(receive6Source)");
19281902
dispatch_release(theReceiveSource);
19291903
#endif
@@ -3641,14 +3615,14 @@ - (void)setSendFilter:(GCDAsyncUdpSocketSendFilterBlock)filterBlock
36413615

36423616
newFilterBlock = [filterBlock copy];
36433617
newFilterQueue = filterQueue;
3644-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3618+
#if !OS_OBJECT_USE_OBJC
36453619
dispatch_retain(newFilterQueue);
36463620
#endif
36473621
}
36483622

36493623
dispatch_block_t block = ^{
36503624

3651-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3625+
#if !OS_OBJECT_USE_OBJC
36523626
if (sendFilterQueue) dispatch_release(sendFilterQueue);
36533627
#endif
36543628

@@ -4014,7 +3988,7 @@ - (void)endCurrentSend
40143988
if (sendTimer)
40153989
{
40163990
dispatch_source_cancel(sendTimer);
4017-
#if NEEDS_DISPATCH_RETAIN_RELEASE
3991+
#if !OS_OBJECT_USE_OBJC
40183992
dispatch_release(sendTimer);
40193993
#endif
40203994
sendTimer = NULL;
@@ -4196,14 +4170,14 @@ - (void)setReceiveFilter:(GCDAsyncUdpSocketReceiveFilterBlock)filterBlock
41964170

41974171
newFilterBlock = [filterBlock copy];
41984172
newFilterQueue = filterQueue;
4199-
#if NEEDS_DISPATCH_RETAIN_RELEASE
4173+
#if !OS_OBJECT_USE_OBJC
42004174
dispatch_retain(newFilterQueue);
42014175
#endif
42024176
}
42034177

42044178
dispatch_block_t block = ^{
42054179

4206-
#if NEEDS_DISPATCH_RETAIN_RELEASE
4180+
#if !OS_OBJECT_USE_OBJC
42074181
if (receiveFilterQueue) dispatch_release(receiveFilterQueue);
42084182
#endif
42094183

0 commit comments

Comments
 (0)