xref: /aosp_15_r20/external/compiler-rt/lib/BlocksRuntime/Block.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /*
2*7c3d14c8STreehugger Robot  * Block.h
3*7c3d14c8STreehugger Robot  *
4*7c3d14c8STreehugger Robot  * Copyright 2008-2010 Apple, Inc. Permission is hereby granted, free of charge,
5*7c3d14c8STreehugger Robot  * to any person obtaining a copy of this software and associated documentation
6*7c3d14c8STreehugger Robot  * files (the "Software"), to deal in the Software without restriction,
7*7c3d14c8STreehugger Robot  * including without limitation the rights to use, copy, modify, merge, publish,
8*7c3d14c8STreehugger Robot  * distribute, sublicense, and/or sell copies of the Software, and to permit
9*7c3d14c8STreehugger Robot  * persons to whom the Software is furnished to do so, subject to the following
10*7c3d14c8STreehugger Robot  * conditions:
11*7c3d14c8STreehugger Robot  *
12*7c3d14c8STreehugger Robot  * The above copyright notice and this permission notice shall be included in
13*7c3d14c8STreehugger Robot  * all copies or substantial portions of the Software.
14*7c3d14c8STreehugger Robot  *
15*7c3d14c8STreehugger Robot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*7c3d14c8STreehugger Robot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*7c3d14c8STreehugger Robot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18*7c3d14c8STreehugger Robot  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*7c3d14c8STreehugger Robot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20*7c3d14c8STreehugger Robot  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21*7c3d14c8STreehugger Robot  * SOFTWARE.
22*7c3d14c8STreehugger Robot  *
23*7c3d14c8STreehugger Robot  */
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot #ifndef _BLOCK_H_
26*7c3d14c8STreehugger Robot #define _BLOCK_H_
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot #if !defined(BLOCK_EXPORT)
29*7c3d14c8STreehugger Robot #   if defined(__cplusplus)
30*7c3d14c8STreehugger Robot #       define BLOCK_EXPORT extern "C"
31*7c3d14c8STreehugger Robot #   else
32*7c3d14c8STreehugger Robot #       define BLOCK_EXPORT extern
33*7c3d14c8STreehugger Robot #   endif
34*7c3d14c8STreehugger Robot #endif
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot #if defined(__cplusplus)
37*7c3d14c8STreehugger Robot extern "C" {
38*7c3d14c8STreehugger Robot #endif
39*7c3d14c8STreehugger Robot 
40*7c3d14c8STreehugger Robot /* Create a heap based copy of a Block or simply add a reference to an existing one.
41*7c3d14c8STreehugger Robot  * This must be paired with Block_release to recover memory, even when running
42*7c3d14c8STreehugger Robot  * under Objective-C Garbage Collection.
43*7c3d14c8STreehugger Robot  */
44*7c3d14c8STreehugger Robot BLOCK_EXPORT void *_Block_copy(const void *aBlock);
45*7c3d14c8STreehugger Robot 
46*7c3d14c8STreehugger Robot /* Lose the reference, and if heap based and last reference, recover the memory. */
47*7c3d14c8STreehugger Robot BLOCK_EXPORT void _Block_release(const void *aBlock);
48*7c3d14c8STreehugger Robot 
49*7c3d14c8STreehugger Robot #if defined(__cplusplus)
50*7c3d14c8STreehugger Robot }
51*7c3d14c8STreehugger Robot #endif
52*7c3d14c8STreehugger Robot 
53*7c3d14c8STreehugger Robot /* Type correct macros. */
54*7c3d14c8STreehugger Robot 
55*7c3d14c8STreehugger Robot #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
56*7c3d14c8STreehugger Robot #define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
57*7c3d14c8STreehugger Robot 
58*7c3d14c8STreehugger Robot 
59*7c3d14c8STreehugger Robot #endif
60