Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix build on OS X #159

Merged
merged 4 commits into from

3 participants

Ernesto Rivera Bogdan Poplauschi Nikolay Morev
Ernesto Rivera
Collaborator

#156 and #121 were not tested on OS X.

  • Fix build on OS X
  • Test for OS X 10.9
  • Stop ignoring deprecation warnings.
Ernesto Rivera
Collaborator

Came up with three cases:

a) Newer SDK's (iOS 7+/OS X 10.9+) on newer (iOS 7.0+/OS X 10.9+) runtime
queueLabel = dd_str_copy(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL));

b) Systems where dispatch_get_current_queue is not yet deprecated and won't crash (< iOS 6.0/OS X 10.9)

dispatch_queue_t currentQueue = dispatch_get_current_queue();
queueLabel = dd_str_copy(dispatch_queue_get_label(currentQueue));

c) Give up
queueLabel = dd_str_copy("");

Any comments? @robbiehanson, @bpoplauschi, @kolyuchiy, @sprhawk?

Bogdan Poplauschi
Collaborator

I think DISPATCH_CURRENT_QUEUE_LABEL is not defined for OS X

Ernesto Rivera
Collaborator

From MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/dispatch/queue.h:

/*!
 * @const DISPATCH_CURRENT_QUEUE_LABEL
 * @discussion Constant to pass to the dispatch_queue_get_label() function to
 * retrieve the label of the current queue.
 */
#define DISPATCH_CURRENT_QUEUE_LABEL NULL

/*!
 * @function dispatch_queue_get_label
 *
 * @abstract
 * Returns the label of the given queue, as specified when the queue was
 * created, or the empty string if a NULL label was specified.
 *
 * Passing DISPATCH_CURRENT_QUEUE_LABEL will return the label of the current
 * queue.
 *
 * @param queue
 * The queue to query, or DISPATCH_CURRENT_QUEUE_LABEL.
 *
 * @result
 * The label of the queue.
 */
__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
DISPATCH_EXPORT DISPATCH_PURE DISPATCH_WARN_RESULT DISPATCH_NOTHROW
const char *
dispatch_queue_get_label(dispatch_queue_t queue);
Bogdan Poplauschi
Collaborator

I can't find it. Could you try building Xcode/LumberjackFramework/Desktop just to be sure?

Ernesto Rivera rivera-ernesto commented on the diff
Lumberjack/DDLog.m
@@ -877,41 +878,42 @@ - (instancetype)initWithLogMsg:(NSString *)msg
machThreadID = pthread_mach_thread_np(pthread_self());
- // dispatch_get_current_queue() is deprecated and most importantly it
- // crashes sometimes.
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
- // If compiling with iOS 7.0+ SDK for any deployment target
- if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
- // If runtime environment is iOS 7.0+
+ // Try to get the current queue's label
+
+ // a) Compiling against newer SDK's (iOS 7+/OS X 10.9+) where DISPATCH_CURRENT_QUEUE_LABEL is defined
+ // on a (iOS 7.0+/OS X 10.9+) runtime version
+ BOOL gotLabel = NO;
+ #ifdef DISPATCH_CURRENT_QUEUE_LABEL
Ernesto Rivera Collaborator

It builds, but it would anyway because of this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Bogdan Poplauschi
Collaborator

You're correct. I meant to say that because DISPATCH_CURRENT_QUEUE_LABEL doesn't exist on Mac OS, the Mac path from case a) is never executed. If you see DISPATCH_CURRENT_QUEUE_LABEL defined on Mac, could you tell me in which file?

Bogdan Poplauschi
Collaborator

Disregard my last comment. I just saw your definition of DISPATCH_CURRENT_QUEUE_LABEL. I'm still running Mountain Lion, that's why it's undefined for me.

Ernesto Rivera
Collaborator

I'll have to leave now but you and @kolyuchiy can work directly on this pull request if you feel like (added you as collaborators in the fork).

Bogdan Poplauschi
Collaborator

@rivera-ernesto The pull request sounds right to me. I will go ahead and merge it.

Bogdan Poplauschi bpoplauschi merged commit bf7f218 into from
Bogdan Poplauschi
Collaborator

@robbiehanson @kolyuchiy @sprhawk you guys should still review and comment

Nikolay Morev kolyuchiy commented on the diff
Lumberjack/DDLog.m
((6 lines not shown))
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
- // If compiling with iOS 7.0+ SDK for any deployment target
- if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
- // If runtime environment is iOS 7.0+
+ // Try to get the current queue's label
+
+ // a) Compiling against newer SDK's (iOS 7+/OS X 10.9+) where DISPATCH_CURRENT_QUEUE_LABEL is defined
+ // on a (iOS 7.0+/OS X 10.9+) runtime version
+ BOOL gotLabel = NO;
+ #ifdef DISPATCH_CURRENT_QUEUE_LABEL
+ if (
+ #if TARGET_OS_IPHONE
+ [[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending // 7.0+
+ #else
+ [[NSApplication sharedApplication] respondsToSelector:@selector(occlusionState)] // No nice way to check for OS X 10.9+

Does this bug actually reproduces on Mac OS? Maybe we don't have to check and just use dispatch_queue_get_label(currentQueue)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ernesto Rivera
Collaborator

I think that avoiding deprecated methods is good even if they don't crash on OS X.

Ernesto Rivera rivera-ernesto deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 8, 2013
  1. Ernesto Rivera

    Fix build on OS X

    rivera-ernesto authored
  2. Ernesto Rivera

    Stop ignoring deprecation warnings

    rivera-ernesto authored
    No longer necessary after pull requests #121 and #156, and more importantly, that was ugly.
  3. Ernesto Rivera
  4. Ernesto Rivera
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 33 deletions.
  1. +35 −33 Lumberjack/DDLog.m
68 Lumberjack/DDLog.m
View
@@ -6,8 +6,9 @@
#import <mach/host_info.h>
#import <libkern/OSAtomic.h>
#import <Availability.h>
-#import <UIKit/UIDevice.h>
-
+#if TARGET_OS_IPHONE
+ #import <UIKit/UIDevice.h>
+#endif
/**
* Welcome to Cocoa Lumberjack!
@@ -877,41 +878,42 @@ - (instancetype)initWithLogMsg:(NSString *)msg
machThreadID = pthread_mach_thread_np(pthread_self());
- // dispatch_get_current_queue() is deprecated and most importantly it
- // crashes sometimes.
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
- // If compiling with iOS 7.0+ SDK for any deployment target
- if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
- // If runtime environment is iOS 7.0+
+ // Try to get the current queue's label
+
+ // a) Compiling against newer SDK's (iOS 7+/OS X 10.9+) where DISPATCH_CURRENT_QUEUE_LABEL is defined
+ // on a (iOS 7.0+/OS X 10.9+) runtime version
+ BOOL gotLabel = NO;
+ #ifdef DISPATCH_CURRENT_QUEUE_LABEL
Ernesto Rivera Collaborator

It builds, but it would anyway because of this check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (
+ #if TARGET_OS_IPHONE
+ [[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending // 7.0+
+ #else
+ [[NSApplication sharedApplication] respondsToSelector:@selector(occlusionState)] // No nice way to check for OS X 10.9+

Does this bug actually reproduces on Mac OS? Maybe we don't have to check and just use dispatch_queue_get_label(currentQueue)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ #endif
+ ) {
queueLabel = dd_str_copy(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL));
+ gotLabel = YES;
}
- else {
+ #endif
+
+ // b) Systems where dispatch_get_current_queue is not yet deprecated and won't crash (< iOS 6.0/OS X 10.9)
+ // dispatch_get_current_queue(void); __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6,__MAC_10_9,__IPHONE_4_0,__IPHONE_6_0)
+ if (!gotLabel &&
+ #if TARGET_OS_IPHONE
+ [[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] == NSOrderedAscending // < 6.0
+ #else
+ ![[NSApplication sharedApplication] respondsToSelector:@selector(occlusionState)] // < OS X 10.9
+ #endif
+ ) {
+ dispatch_queue_t currentQueue = dispatch_get_current_queue();
+ queueLabel = dd_str_copy(dispatch_queue_get_label(currentQueue));
+ gotLabel = YES;
+ }
+
+ // c) Give up
+ if (!gotLabel) {
queueLabel = dd_str_copy("");
}
-#elif __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0
- // Else if deployment target is iOS 6.0+
- queueLabel = dd_str_copy("");
-#else
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- // The documentation for dispatch_get_current_queue() states:
- //
- // > [This method is] "recommended for debugging and logging purposes only"...
- //
- // Well that's exactly how we're using it here. Literally for logging purposes only.
- // However, Apple has decided to deprecate this method anyway.
- // However they have not given us an alternate version of dispatch_queue_get_label() that
- // automatically uses the current queue, thus dispatch_get_current_queue() is still required.
- //
- // If dispatch_get_current_queue() disappears, without a dispatch_queue_get_label() alternative,
- // Apple will have effectively taken away our ability to properly log the name of executing dispatch queue.
-
- dispatch_queue_t currentQueue = dispatch_get_current_queue();
- #pragma clang diagnostic pop
-
- queueLabel = dd_str_copy(dispatch_queue_get_label(currentQueue));
-#endif
threadName = [[NSThread currentThread] name];
}
Something went wrong with that request. Please try again.