From 564255a5397803e31b070c97f01e7e1a34fa7ed6 Mon Sep 17 00:00:00 2001 From: Alban Diquet Date: Wed, 1 Mar 2017 11:53:05 -0800 Subject: [PATCH] Refactor macro --- TrustKit/Dependencies/RSSwizzle/RSSwizzle.m | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/TrustKit/Dependencies/RSSwizzle/RSSwizzle.m b/TrustKit/Dependencies/RSSwizzle/RSSwizzle.m index f40ac5ec..3145daa0 100755 --- a/TrustKit/Dependencies/RSSwizzle/RSSwizzle.m +++ b/TrustKit/Dependencies/RSSwizzle/RSSwizzle.m @@ -25,6 +25,9 @@ #if BASE_SDK_HIGHER_THAN_10 #import #else +// Below iOS 10, OS_UNFAIR_LOCK_INIT will not exist. Note that this type works with OSSpinLock +#define OS_UNFAIR_LOCK_INIT ((os_unfair_lock){0}) + typedef struct _os_unfair_lock_s { uint32_t _os_unfair_lock_opaque; } os_unfair_lock, *os_unfair_lock_t; @@ -272,16 +275,7 @@ static void swizzle(Class classToSwizzle, NSCAssert(blockIsAnImpFactoryBlock(factoryBlock), @"Wrong type of implementation factory block."); - __block os_unfair_lock lock; - if (DEVICE_HIGHER_THAN_10) - { - lock = OS_UNFAIR_LOCK_INIT; - } - else - { - // Below iOS 10, OS_UNFAIR_LOCK_INIT will not exist. Note that this type works with OSSpinLock - lock = ((os_unfair_lock){0}); - } + __block os_unfair_lock lock = OS_UNFAIR_LOCK_INIT; // To keep things thread-safe, we fill in the originalIMP later, // with the result of the class_replaceMethod call below.