SDInternalMacros.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import <Foundation/Foundation.h>
  9. #import "SDmetamacros.h"
  10. #ifndef SD_LOCK
  11. #define SD_LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
  12. #endif
  13. #ifndef SD_UNLOCK
  14. #define SD_UNLOCK(lock) dispatch_semaphore_signal(lock);
  15. #endif
  16. #ifndef SD_OPTIONS_CONTAINS
  17. #define SD_OPTIONS_CONTAINS(options, value) (((options) & (value)) == (value))
  18. #endif
  19. #ifndef SD_CSTRING
  20. #define SD_CSTRING(str) #str
  21. #endif
  22. #ifndef SD_NSSTRING
  23. #define SD_NSSTRING(str) @(SD_CSTRING(str))
  24. #endif
  25. #ifndef SD_SEL_SPI
  26. #define SD_SEL_SPI(name) NSSelectorFromString([NSString stringWithFormat:@"_%@", SD_NSSTRING(name)])
  27. #endif
  28. #ifndef weakify
  29. #define weakify(...) \
  30. sd_keywordify \
  31. metamacro_foreach_cxt(sd_weakify_,, __weak, __VA_ARGS__)
  32. #endif
  33. #ifndef strongify
  34. #define strongify(...) \
  35. sd_keywordify \
  36. _Pragma("clang diagnostic push") \
  37. _Pragma("clang diagnostic ignored \"-Wshadow\"") \
  38. metamacro_foreach(sd_strongify_,, __VA_ARGS__) \
  39. _Pragma("clang diagnostic pop")
  40. #endif
  41. #define sd_weakify_(INDEX, CONTEXT, VAR) \
  42. CONTEXT __typeof__(VAR) metamacro_concat(VAR, _weak_) = (VAR);
  43. #define sd_strongify_(INDEX, VAR) \
  44. __strong __typeof__(VAR) VAR = metamacro_concat(VAR, _weak_);
  45. #if DEBUG
  46. #define sd_keywordify autoreleasepool {}
  47. #else
  48. #define sd_keywordify try {} @catch (...) {}
  49. #endif
  50. #ifndef onExit
  51. #define onExit \
  52. sd_keywordify \
  53. __strong sd_cleanupBlock_t metamacro_concat(sd_exitBlock_, __LINE__) __attribute__((cleanup(sd_executeCleanupBlock), unused)) = ^
  54. #endif
  55. typedef void (^sd_cleanupBlock_t)(void);
  56. #if defined(__cplusplus)
  57. extern "C" {
  58. #endif
  59. void sd_executeCleanupBlock (__strong sd_cleanupBlock_t *block);
  60. #if defined(__cplusplus)
  61. }
  62. #endif