DHCommon.h 769 B

1234567891011121314151617181920
  1. #import <Foundation/Foundation.h>
  2. #import <objc/runtime.h>
  3. /* Common, useful things.
  4. * A bit has been lifted from rpetrich's Captain Hook macros. Thanks, Ryan!
  5. */
  6. #define _Constructor __attribute__((constructor))
  7. #define DHLateClass(name) @class name; static Class $ ## name = objc_getClass(#name)
  8. #define DHEarlyClass(name) static Class $ ## name = [name class]
  9. #define DHClass(name) $ ## name
  10. static inline void _DHRelease(id object) __attribute__((always_inline));
  11. static inline void _DHRelease(id object) {
  12. [object release];
  13. }
  14. #define DHScopeReleased __attribute__((cleanup(_DHRelease)))
  15. #define DHScopedAutoreleasePool() NSAutoreleasePool *DHScopedAutoreleasePool __attribute__((cleanup(_DHRelease),unused)) = [[NSAutoreleasePool alloc] init]
  16. // vim:ft=objc