Fixed Obj-C GC support; fix pthread name
authorSean McBride <sean@rogue-research.com>
Wed, 14 Sep 2016 16:50:09 +0000 (12:50 -0400)
committerNathan Hjelm <hjelmn@lanl.gov>
Wed, 14 Sep 2016 18:23:55 +0000 (12:23 -0600)
Fixed some recent regressions:
- Always call pthread_setname_np. Recent change removed this if > 10.8.
- Always call objc_registerThreadWithCollector(), except if deploying to 10.12 or later, which GC is removed anyway.

NTH: Note, the header in macOS 10.12 documents that the auto-release
feature was removed and "does nothing" since 10.8. The source code
available from 10.8-10.11 clearly shows that the
objc_registerThreadWithCollector call does something so we will leave
it enabled for this version range. More details are needed from Apple
to interpret the meaning of the deprecation message in 10.12.

Closes #210

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
libusb/os/darwin_usb.c
libusb/version_nano.h

index 25b37e3..b0d8a8a 100644 (file)
@@ -37,7 +37,7 @@
 #include <mach/mach_port.h>
 
 #include <AvailabilityMacros.h>
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 && MAC_OS_X_VERSION_MIN_REQUIRED < 101200
   #include <objc/objc-auto.h>
 #endif
 
@@ -385,15 +385,19 @@ static void *darwin_event_thread_main (void *arg0) {
   struct libusb_context *ctx = (struct libusb_context *)arg0;
   CFRunLoopRef runloop;
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
   /* Set this thread's name, so it can be seen in the debugger
      and crash reports. */
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 && MAC_OS_X_VERSION_MIN_REQUIRED <= 1080
   pthread_setname_np ("org.libusb.device-hotplug");
+#endif
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 && MAC_OS_X_VERSION_MIN_REQUIRED < 101200
   /* Tell the Objective-C garbage collector about this thread.
      This is required because, unlike NSThreads, pthreads are
      not automatically registered. Although we don't use
-     Objective-C, we use CoreFoundation, which does. */
+     Objective-C, we use CoreFoundation, which does.
+     Garbage collection support was entirely removed in 10.12,
+     so don't bother there. */
   objc_registerThreadWithCollector();
 #endif
 
index b2fb216..a438e7c 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11146
+#define LIBUSB_NANO 11147