John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 1 | #if __has_feature(objc_arr) |
| 2 | #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) |
| 3 | #else |
| 4 | #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE |
| 5 | #endif |
| 6 | |
Argyrios Kyrtzidis | d208ef9 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 7 | #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained)) |
Argyrios Kyrtzidis | 41899f3 | 2011-09-14 18:17:09 +0000 | [diff] [blame] | 8 | #define CF_CONSUMED __attribute__((cf_consumed)) |
Argyrios Kyrtzidis | 273c7c4 | 2012-06-01 00:10:47 +0000 | [diff] [blame] | 9 | #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) |
Argyrios Kyrtzidis | 41899f3 | 2011-09-14 18:17:09 +0000 | [diff] [blame] | 10 | |
Argyrios Kyrtzidis | d208ef9 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 11 | #define NS_INLINE static __inline__ __attribute__((always_inline)) |
Argyrios Kyrtzidis | 9390747 | 2011-07-27 05:28:18 +0000 | [diff] [blame] | 12 | #define nil ((void*) 0) |
Argyrios Kyrtzidis | 6ba7afb | 2013-01-03 03:17:17 +0000 | [diff] [blame] | 13 | #define NULL ((void*)0) |
Argyrios Kyrtzidis | 9390747 | 2011-07-27 05:28:18 +0000 | [diff] [blame] | 14 | |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 15 | typedef int BOOL; |
| 16 | typedef unsigned NSUInteger; |
| 17 | typedef int int32_t; |
| 18 | typedef unsigned char uint8_t; |
| 19 | typedef int32_t UChar32; |
| 20 | typedef unsigned char UChar; |
| 21 | |
Argyrios Kyrtzidis | 9390747 | 2011-07-27 05:28:18 +0000 | [diff] [blame] | 22 | typedef struct _NSZone NSZone; |
| 23 | |
| 24 | typedef const void * CFTypeRef; |
| 25 | CFTypeRef CFRetain(CFTypeRef cf); |
Argyrios Kyrtzidis | 273c7c4 | 2012-06-01 00:10:47 +0000 | [diff] [blame] | 26 | CFTypeRef CFMakeCollectable(CFTypeRef cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
Argyrios Kyrtzidis | d208ef9 | 2011-11-04 15:58:08 +0000 | [diff] [blame] | 27 | |
| 28 | NS_INLINE NS_RETURNS_RETAINED id NSMakeCollectable(CFTypeRef CF_CONSUMED cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
Argyrios Kyrtzidis | 9390747 | 2011-07-27 05:28:18 +0000 | [diff] [blame] | 29 | |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 30 | @protocol NSObject |
| 31 | - (BOOL)isEqual:(id)object; |
Argyrios Kyrtzidis | 9390747 | 2011-07-27 05:28:18 +0000 | [diff] [blame] | 32 | - (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 33 | - (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
| 34 | - (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
| 35 | - (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
| 36 | - (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE; |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 37 | @end |
| 38 | |
| 39 | @interface NSObject <NSObject> {} |
| 40 | - (id)init; |
| 41 | |
| 42 | + (id)new; |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 43 | + (id)alloc; |
| 44 | - (void)dealloc; |
| 45 | |
| 46 | - (void)finalize; |
| 47 | |
| 48 | - (id)copy; |
| 49 | - (id)mutableCopy; |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 50 | @end |
| 51 | |
John McCall | d70fb98 | 2011-06-15 23:25:17 +0000 | [diff] [blame] | 52 | NS_AUTOMATED_REFCOUNT_UNAVAILABLE |
| 53 | @interface NSAutoreleasePool : NSObject { |
| 54 | @private |
| 55 | void *_token; |
| 56 | void *_reserved3; |
| 57 | void *_reserved2; |
| 58 | void *_reserved; |
| 59 | } |
| 60 | |
| 61 | + (void)addObject:(id)anObject; |
| 62 | |
| 63 | - (void)addObject:(id)anObject; |
| 64 | |
| 65 | - (void)drain; |
| 66 | |
| 67 | @end |
| 68 | |
| 69 | typedef const void* objc_objectptr_t; |
| 70 | extern __attribute__((ns_returns_retained)) id objc_retainedObject(objc_objectptr_t __attribute__((cf_consumed)) pointer); |
| 71 | extern __attribute__((ns_returns_not_retained)) id objc_unretainedObject(objc_objectptr_t pointer); |
| 72 | extern objc_objectptr_t objc_unretainedPointer(id object); |
Argyrios Kyrtzidis | 0b21d82 | 2012-05-23 21:50:04 +0000 | [diff] [blame] | 73 | |
| 74 | #define dispatch_retain(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); (void)[_o retain]; }) |
| 75 | #define dispatch_release(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); [_o release]; }) |
| 76 | #define xpc_retain(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o retain]; }) |
| 77 | #define xpc_release(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o release]; }) |
| 78 | |
| 79 | typedef id dispatch_object_t; |
| 80 | typedef id xpc_object_t; |
| 81 | |
| 82 | void _dispatch_object_validate(dispatch_object_t object); |
| 83 | void _xpc_object_validate(xpc_object_t object); |
Argyrios Kyrtzidis | 273c7c4 | 2012-06-01 00:10:47 +0000 | [diff] [blame] | 84 | |
| 85 | #if __has_feature(objc_arc) |
| 86 | |
| 87 | NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { |
| 88 | return (__bridge_retained CFTypeRef)X; |
| 89 | } |
| 90 | |
| 91 | NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { |
| 92 | return (__bridge_transfer id)X; |
| 93 | } |
| 94 | |
| 95 | #else |
| 96 | |
| 97 | NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) { |
| 98 | return X ? CFRetain((CFTypeRef)X) : NULL; |
| 99 | } |
| 100 | |
| 101 | NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) { |
| 102 | return [(id)CFMakeCollectable(X) autorelease]; |
| 103 | } |
| 104 | |
| 105 | #endif |
Argyrios Kyrtzidis | 6ba7afb | 2013-01-03 03:17:17 +0000 | [diff] [blame] | 106 | |
| 107 | void *_Block_copy(const void *aBlock); |
| 108 | void _Block_release(const void *aBlock); |
| 109 | #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) |
| 110 | #define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) |