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 #ifndef KERNEL 34 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 35 #endif 36 BLOCK_EXPORT void *_Block_copy(const void *aBlock); 37 38 // Lose the reference, and if heap based and last reference, recover the memory 39 #ifndef KERNEL 40 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 41 #endif 42 BLOCK_EXPORT void _Block_release(const void *aBlock); 43 44 45 // Used by the compiler. Do not call this function yourself. 46 #ifndef KERNEL 47 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 48 #endif 49 BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int); 50 51 // Used by the compiler. Do not call this function yourself. 52 #ifndef KERNEL 53 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 54 #endif 55 BLOCK_EXPORT void _Block_object_dispose(const void *, const int); 56 57 // Used by the compiler. Do not use these variables yourself. 58 #ifndef KERNEL 59 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 60 #endif 61 BLOCK_EXPORT void * _NSConcreteGlobalBlock[32]; 62 63 #ifndef KERNEL 64 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2) 65 #endif 66 BLOCK_EXPORT void * _NSConcreteStackBlock[32]; 67 68 69 #if __cplusplus 70 } 71 #endif 72 73 // Type correct macros 74 75 #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) 76 #define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) 77 78 79 #endif 80