Skip to content

Commit

Permalink
Bug fixes for the big cat and her little sister's 6th birthday (dispa…
Browse files Browse the repository at this point in the history
…tch_retain & dispatch_release no longer needed with latest ARC) Fixes issue CocoaLumberjack#42
  • Loading branch information
robbiehanson committed Jun 17, 2012
1 parent a23bf69 commit b21761e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
30 changes: 30 additions & 0 deletions Lumberjack/DDAbstractDatabaseLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +147,9 @@ - (void)destroySaveTimer
dispatch_resume(saveTimer);
saveTimerSuspended = NO;
}
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(saveTimer);
#endif
saveTimer = NULL;
}
}
Expand Down Expand Up @@ -164,7 +192,9 @@ - (void)destroyDeleteTimer
if (deleteTimer)
{
dispatch_source_cancel(deleteTimer);
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(deleteTimer);
#endif
deleteTimer = NULL;
}
}
Expand Down
35 changes: 32 additions & 3 deletions Lumberjack/DDFileLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -485,7 +510,6 @@ - (void)dealloc
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
dispatch_release(rollingTimer);
rollingTimer = NULL;
}
}
Expand Down Expand Up @@ -621,7 +645,6 @@ - (void)scheduleTimerToRollLogFileDueToAge
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
dispatch_release(rollingTimer);
rollingTimer = NULL;
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -709,7 +739,6 @@ - (void)rollLogFileNow
if (rollingTimer)
{
dispatch_source_cancel(rollingTimer);
dispatch_release(rollingTimer);
rollingTimer = NULL;
}
}
Expand Down
35 changes: 32 additions & 3 deletions Lumberjack/DDLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -903,7 +930,9 @@ - (id)init

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

- (void)logMessage:(DDLogMessage *)logMessage
Expand Down

0 comments on commit b21761e

Please sign in to comment.