]> git.saurik.com Git - apple/libdispatch.git/blob - src/BlocksRuntime/Block.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / src / BlocksRuntime / Block.h
1 // This source file is part of the Swift.org open source project
2 //
3 // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4 // Licensed under Apache License v2.0 with Runtime Library Exception
5 //
6 // See http://swift.org/LICENSE.txt for license information
7 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8 //
9
10
11 #ifndef _Block_H_
12 #define _Block_H_
13
14 #if !defined(BLOCK_EXPORT)
15 # if defined(__cplusplus)
16 # define BLOCK_EXPORT extern "C" __attribute__((visibility("default")))
17 # else
18 # define BLOCK_EXPORT extern __attribute__((visibility("default")))
19 # endif
20 #endif
21
22 #if __cplusplus
23 extern "C" {
24 #endif
25
26 // Create a heap based copy of a Block or simply add a reference to an existing one.
27 // This must be paired with Block_release to recover memory, even when running
28 // under Objective-C Garbage Collection.
29 BLOCK_EXPORT void *_Block_copy(const void *aBlock);
30
31 // Lose the reference, and if heap based and last reference, recover the memory
32 BLOCK_EXPORT void _Block_release(const void *aBlock);
33
34 // Used by the compiler. Do not call this function yourself.
35 BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int);
36
37 // Used by the compiler. Do not call this function yourself.
38 BLOCK_EXPORT void _Block_object_dispose(const void *, const int);
39
40 // Used by the compiler. Do not use these variables yourself.
41 BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
42 BLOCK_EXPORT void * _NSConcreteStackBlock[32];
43
44 #if __cplusplus
45 }
46 #endif
47
48 // Type correct macros
49
50 #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
51 #define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
52
53
54 #endif