Skip to content

Commit

Permalink
Updates for Xcode 4.5+ (dispatch_retain & dispatch_release no longer …
Browse files Browse the repository at this point in the history
…needed under latest ARC)
  • Loading branch information
robbiehanson committed Jul 3, 2012
1 parent d90f7bd commit fa46160
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 23 deletions.
30 changes: 30 additions & 0 deletions Core/XMPPModule.m
Expand Up @@ -6,6 +6,32 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN;
Expand Down Expand Up @@ -34,7 +60,9 @@ - (id)initWithDispatchQueue:(dispatch_queue_t)queue
if (queue)
{
moduleQueue = queue;
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_retain(moduleQueue);
#endif
}
else
{
Expand All @@ -49,7 +77,9 @@ - (id)initWithDispatchQueue:(dispatch_queue_t)queue

- (void)dealloc
{
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(moduleQueue);
#endif
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Core/XMPPParser.m
Expand Up @@ -572,7 +572,8 @@ static void xmpp_xmlStartElement(void *ctx, const xmlChar *nodeName,

if (newNode->nsDef == NULL)
{
newNode->nsDef = lastAddedNs = newNs;
newNode->nsDef = newNs;
lastAddedNs = newNs;
}
else
{
Expand Down Expand Up @@ -608,12 +609,11 @@ static void xmpp_xmlStartElement(void *ctx, const xmlChar *nodeName,

if (newNode->nsDef == NULL)
{
newNode->nsDef = lastAddedNs = newNs;
newNode->nsDef = newNs;
}
else
{
lastAddedNs->next = newNs;
lastAddedNs = newNs;
}

newNode->ns = newNs;
Expand Down
34 changes: 34 additions & 0 deletions Core/XMPPStream.m
Expand Up @@ -17,6 +17,32 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_INFO | XMPP_LOG_FLAG_SEND_RECV; // | XMPP_LOG_FLAG_TRACE;
Expand Down Expand Up @@ -177,8 +203,10 @@ - (id)initP2PFrom:(XMPPJID *)jid
**/
- (void)dealloc
{
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(xmppQueue);
dispatch_release(parserQueue);
#endif

[asyncSocket setDelegate:nil delegateQueue:NULL];
[asyncSocket disconnect];
Expand Down Expand Up @@ -3318,8 +3346,10 @@ - (void)xmppParser:(XMPPParser *)sender didReadElement:(NSXMLElement *)element
[self sendElement:iqResponse];
}

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(delSemaphore);
dispatch_release(delGroup);
#endif

}});

Expand Down Expand Up @@ -3405,12 +3435,14 @@ - (void)setupKeepAliveTimer
[self keepAlive];
}});

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_source_t theKeepAliveTimer = keepAliveTimer;

dispatch_source_set_cancel_handler(keepAliveTimer, ^{
XMPPLogVerbose(@"dispatch_release(keepAliveTimer)");
dispatch_release(theKeepAliveTimer);
});
#endif

// Everytime we send or receive data, we update our lastSendReceiveTime.
// We set our timer to fire several times per keepAliveInterval.
Expand Down Expand Up @@ -3862,7 +3894,9 @@ - (BOOL)wait:(NSTimeInterval)timeout_seconds

- (void)dealloc
{
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(semaphore);
#endif
}

@end
30 changes: 28 additions & 2 deletions Extensions/CoreDataStorage/XMPPCoreDataStorage.m
Expand Up @@ -12,6 +12,32 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN;
Expand Down Expand Up @@ -819,10 +845,10 @@ - (void)dealloc
[[self class] unregisterDatabaseFileName:databaseFileName];
}

#if NEEDS_DISPATCH_RETAIN_RELEASE
if (storageQueue)
{
dispatch_release(storageQueue);
}
#endif
}

@end
31 changes: 30 additions & 1 deletion Extensions/Reconnect/XMPPReconnect.m
Expand Up @@ -7,6 +7,32 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

#define IMPOSSIBLE_REACHABILITY_FLAGS 0xFFFFFFFF

// Log levels: off, error, warn, info, verbose
Expand Down Expand Up @@ -386,12 +412,14 @@ - (void)setupReconnectTimer

}});

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_source_t theReconnectTimer = reconnectTimer;

dispatch_source_set_cancel_handler(reconnectTimer, ^{
XMPPLogVerbose(@"dispatch_release(reconnectTimer)");
dispatch_release(theReconnectTimer);
});
#endif

dispatch_time_t startTime;
if (reconnectDelay > 0.0)
Expand Down Expand Up @@ -613,9 +641,10 @@ - (void)maybeAttemptReconnectWithReachabilityFlags:(SCNetworkReachabilityFlags)r

}});

#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(delSemaphore);
dispatch_release(delGroup);

#endif
}});

}
Expand Down
30 changes: 29 additions & 1 deletion Extensions/XEP-0045/CoreDataStorage/XMPPRoomCoreDataStorage.m
Expand Up @@ -7,9 +7,35 @@
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

/**
* Does ARC support support GCD objects?
* It does if the minimum deployment target is iOS 6+ or Mac OS X 8+
**/
#if TARGET_OS_IPHONE

// Compiling for iOS

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else // iOS 5.X or earlier
#define NEEDS_DISPATCH_RETAIN_RELEASE 1
#endif

#else

// Compiling for Mac OS X

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later
#define NEEDS_DISPATCH_RETAIN_RELEASE 0
#else
#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier
#endif

#endif

// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_VERBOSE | XMPP_LOG_FLAG_TRACE;
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN; // | XMPP_LOG_FLAG_TRACE;
#else
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN;
#endif
Expand Down Expand Up @@ -401,7 +427,9 @@ - (void)destroyDeleteTimer
if (deleteTimer)
{
dispatch_source_cancel(deleteTimer);
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(deleteTimer);
#endif
deleteTimer = NULL;
}
}
Expand Down

0 comments on commit fa46160

Please sign in to comment.