forked from gnustep/libobjc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocks_runtime.h
125 lines (117 loc) · 3.07 KB
/
blocks_runtime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Block descriptor flags.
*/
enum block_flags
{
/**
* The block descriptor contains copy and dispose helpers.
*/
BLOCK_HAS_COPY_DISPOSE = (1 << 25),
/**
* The helpers have C++ code.
*/
BLOCK_HAS_CTOR = (1 << 26),
/**
* Block is stored in global memory and does not need to be copied.
*/
BLOCK_IS_GLOBAL = (1 << 28),
/**
* Block function uses a calling convention that returns a structure via a
* pointer passed in by the caller.
*/
BLOCK_USE_SRET = (1 << 29),
/**
* Block has an Objective-C type encoding.
*/
BLOCK_HAS_SIGNATURE = (1 << 30),
/**
* Mask for the reference count in byref structure's flags field. The low
* 3 bytes are reserved for the reference count, the top byte for the
* flags.
*/
BLOCK_REFCOUNT_MASK = 0x00ffffff
};
/**
* Flags used in the final argument to _Block_object_assign() and
* _Block_object_dispose(). These indicate the type of copy or dispose to
* perform.
*/
enum
{
/**
* The value is of some id-like type, and should be copied as an
* Objective-C object: i.e. by sending -retain or via the GC assign
* functions in GC mode (not yet supported).
*/
BLOCK_FIELD_IS_OBJECT = 3,
/**
* The field is a block. This must be copied by the block copy functions.
*/
BLOCK_FIELD_IS_BLOCK = 7,
/**
* The field is an indirect reference to a variable declared with the
* __block storage qualifier.
*/
BLOCK_FIELD_IS_BYREF = 8, // the on stack structure holding the __block variable
BLOCK_FIELD_IS_WEAK = 16, // declared __weak
BLOCK_BYREF_CALLER = 128, // called from byref copy/dispose helpers
};
#define IS_SET(x, y) ((x & y) == y)
/*
* Include the block_descriptor_copydispose and block_literal definitions that
* are also made public under different names for use in libdispatch.
*/
#include "objc/blocks_private.h"
/**
* Block descriptor that does not contain copy and dispose helper functions.
*/
struct Block_descriptor_basic
{
/**
* Reserved for future use, currently always 0.
*/
unsigned long int reserved;
/** Size of the block. */
unsigned long int size;
/**
* Objective-C type encoding of the block.
*/
const char *encoding;
};
/**
* Structure used for on-stack variables that are referenced by blocks.
*/
struct block_byref_obj
{
/**
* Class pointer. Currently unused and always NULL. Could be used in the
* future to support introspection.
*/
void *isa;
/**
* The pointer to the structure that contains the real version of the data.
* All accesses go via this pointer. If an on-stack byref structure is
* copied to the heap, then its forwarding pointer should point to the heap
* version. Otherwise it should point to itself.
*/
struct block_byref_obj *forwarding;
/**
* Flags and reference count.
*/
int flags; //refcount;
/**
* Size of this structure.
*/
int size;
/**
* Copy function.
*/
void (*byref_keep)(struct block_byref_obj *dst, const struct block_byref_obj *src);
/**
* Dispose function.
*/
void (*byref_dispose)(struct block_byref_obj *);
/**
* __block-qualified variables are copied here.
*/
};