Permalink
Browse files

Merging latest changes from CocoaLumberjack project

  • Loading branch information...
1 parent 1604d51 commit d90f7bd1a42642e058cbaeca433212c9c357f601 @robbiehanson committed Jul 3, 2012
@@ -15,6 +15,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
+
@interface DDAbstractDatabaseLogger ()
- (void)destroySaveTimer;
- (void)destroyDeleteTimer;
@@ -121,7 +147,9 @@ - (void)destroySaveTimer
dispatch_resume(saveTimer);
saveTimerSuspended = NO;
}
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(saveTimer);
+ #endif
saveTimer = NULL;
}
}
@@ -164,7 +192,9 @@ - (void)destroyDeleteTimer
if (deleteTimer)
{
dispatch_source_cancel(deleteTimer);
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(deleteTimer);
+ #endif
deleteTimer = NULL;
}
}
@@ -19,6 +19,31 @@
#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
+
// We probably shouldn't be using DDLog() statements within the DDLog implementation.
// But we still want to leave our log statements for any future debugging,
// and to allow other developers to trace the implementation (which is a great learning tool).
@@ -485,7 +510,6 @@ - (void)dealloc
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
- dispatch_release(rollingTimer);
rollingTimer = NULL;
}
}
@@ -621,7 +645,6 @@ - (void)scheduleTimerToRollLogFileDueToAge
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
- dispatch_release(rollingTimer);
rollingTimer = NULL;
}
@@ -650,6 +673,13 @@ - (void)scheduleTimerToRollLogFileDueToAge
}});
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
+ dispatch_source_t theRollingTimer = rollingTimer;
+ dispatch_source_set_cancel_handler(rollingTimer, ^{
+ dispatch_release(theRollingTimer);
+ });
+ #endif
+
uint64_t delay = [logFileRollingDate timeIntervalSinceNow] * NSEC_PER_SEC;
dispatch_time_t fireTime = dispatch_time(DISPATCH_TIME_NOW, delay);
@@ -709,7 +739,6 @@ - (void)rollLogFileNow
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
- dispatch_release(rollingTimer);
rollingTimer = NULL;
}
}
@@ -22,6 +22,31 @@
#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
+
// We probably shouldn't be using DDLog() statements within the DDLog implementation.
// But we still want to leave our log statements for any future debugging,
// and to allow other developers to trace the implementation (which is a great learning tool).
@@ -769,7 +794,9 @@ - (id)initWithLogger:(id <DDLogger>)aLogger loggerQueue:(dispatch_queue_t)aLogge
if (aLoggerQueue) {
loggerQueue = aLoggerQueue;
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_retain(loggerQueue);
+ #endif
}
}
return self;
@@ -782,9 +809,9 @@ + (DDLoggerNode *)nodeWithLogger:(id <DDLogger>)logger loggerQueue:(dispatch_que
- (void)dealloc
{
- if (loggerQueue) {
- dispatch_release(loggerQueue);
- }
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
+ if (loggerQueue) dispatch_release(loggerQueue);
+ #endif
}
@end
@@ -903,7 +930,9 @@ - (id)init
- (void)dealloc
{
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
if (loggerQueue) dispatch_release(loggerQueue);
+ #endif
}
- (void)logMessage:(DDLogMessage *)logMessage
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
-
-#if !TARGET_OS_IPHONE
+#if TARGET_OS_IPHONE
+#import <UIKit/UIColor.h>
+#else
#import <AppKit/NSColor.h>
#endif
@@ -1212,7 +1212,7 @@ - (void)logMessage:(DDLogMessage *)logMessage
NSUInteger msgLen = [logMsg lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
const BOOL useStack = msgLen < (1024 * 4);
- char msgStack[useStack ? (msgLen + 1) : 0];
+ char msgStack[useStack ? (msgLen + 1) : 1]; // Analyzer doesn't like zero-size array, hence the 1
char *msg = useStack ? msgStack : (char *)malloc(msgLen + 1);
[logMsg getCString:msg maxLength:(msgLen + 1) encoding:NSUTF8StringEncoding];

0 comments on commit d90f7bd

Please sign in to comment.