1 /* 2 * Block.h 3 * 4 * Copyright (c) 2008-2010 Apple Inc. All rights reserved. 5 * 6 * @APPLE_LLVM_LICENSE_HEADER@ 7 * 8 */ 9 10 #ifndef _Block_H_ 11 #define _Block_H_ 12 13 #if !defined(BLOCK_EXPORT) 14 # if defined(__cplusplus) 15 # define BLOCK_EXPORT extern "C" 16 # else 17 # define BLOCK_EXPORT extern 18 # endif 19 #endif 20 21 #include <Availability.h> 22 #ifndef KERNEL 23 #include <TargetConditionals.h> 24 #endif /* KERNEL */ 25 26 #if __cplusplus 27 extern "C" { 28 #endif 29 30 // Create a heap based copy of a Block or simply add a reference to an existing one. 31 // This must be paired with Block_release to recover memory, even when running 32 // under Objective-C Garbage Collection. 33 BLOCK_EXPORT void *_Block_copy(const void *aBlock) 34 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 35 36 // Lose the reference, and if heap based and last reference, recover the memory 37 BLOCK_EXPORT void _Block_release(const void *aBlock) 38 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 39 40 41 // Used by the compiler. Do not call this function yourself. 42 BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int) 43 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 44 45 // Used by the compiler. Do not call this function yourself. 46 BLOCK_EXPORT void _Block_object_dispose(const void *, const int) 47 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 48 49 // Used by the compiler. Do not use these variables yourself. 50 BLOCK_EXPORT void * _NSConcreteGlobalBlock[32] 51 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 52 BLOCK_EXPORT void * _NSConcreteStackBlock[32] 53 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); 54 55 56 #if __cplusplus 57 } 58 #endif 59 60 // Type correct macros 61 62 #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) 63 #define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) 64 65 66 #endif 67