-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock_private.h
More file actions
221 lines (184 loc) · 5.43 KB
/
Copy pathBlock_private.h
File metadata and controls
221 lines (184 loc) · 5.43 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Copyright (c) 2025-2026 Paul Olteanu
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#if __cplusplus
extern "C" {
#endif
enum BlockRefcountFlags : unsigned short {
BLOCK_DEALLOCATING = 0x1,
BLOCK_REFCOUNT_MASK = 0xFFFE
};
enum BlockLiteralFlags : int {
BLOCK_NEEDS_FREE = 1 << 24,
BLOCK_HAS_COPY_DISPOSE = 1 << 25,
BLOCK_IS_GLOBAL = 1 << 28,
BLOCK_USE_STRET = 1 << 29,
BLOCK_HAS_SIGNATURE = 1 << 30
};
enum BlockByrefFlags : int {
BLOCK_BYREF_NEEDS_FREE = 1 << 24,
BLOCK_BYREF_HAS_COPY_DISPOSE = 1 << 25
};
/*
* Modifiers for objects, Blocks, and Byrefs do not belong in the enumeration,
* as they are not standalone values affecting control flow in
* _Block_object_{assign,dispose}().
*/
static constexpr int BLOCK_FIELD_IS_WEAK = 16;
static constexpr int BLOCK_BYREF_CALLER = 128;
typedef enum BlockCaptureFlags : int {
BLOCK_FIELD_IS_OBJECT = 3,
BLOCK_FIELD_IS_BLOCK = 7,
BLOCK_FIELD_IS_BYREF = 8,
BLOCK_FIELD_IS_WEAK_BYREF = BLOCK_FIELD_IS_BYREF | BLOCK_FIELD_IS_WEAK,
BLOCK_BYREF_CALLER_FIELD_IS_BLOCK = BLOCK_BYREF_CALLER |
BLOCK_FIELD_IS_BLOCK,
BLOCK_BYREF_CALLER_FIELD_IS_OBJECT = BLOCK_BYREF_CALLER |
BLOCK_FIELD_IS_OBJECT,
BLOCK_BYREF_CALLER_FIELD_IS_WEAK_BLOCK = BLOCK_BYREF_CALLER |
BLOCK_FIELD_IS_BLOCK |
BLOCK_FIELD_IS_WEAK,
BLOCK_BYREF_CALLER_FIELD_IS_WEAK_OBJECT = BLOCK_BYREF_CALLER |
BLOCK_FIELD_IS_OBJECT |
BLOCK_FIELD_IS_WEAK
} BlockCaptureFlags;
static_assert(sizeof(int _Atomic) == sizeof(int) && _Alignof(int _Atomic) == _Alignof(int));
typedef struct BlockLiteral {
void *isa;
int _Atomic flags;
int reserved;
void (*BlockInvoke)(struct BlockLiteral *, ...);
union {
struct BlockDescriptor *descriptor;
struct BlockCopyDisposeDescriptor *copyDisposeDescriptor;
};
} BlockLiteral;
typedef struct BlockDescriptor {
unsigned long reserved;
unsigned long blockSize;
char *typeEncoding;
char *extendedLayout;
} BlockDescriptor;
typedef struct BlockCopyDisposeDescriptor {
unsigned long reserved;
unsigned long blockSize;
void (*BlockCopyHelper)(BlockLiteral *, const BlockLiteral *);
void (*BlockDisposeHelper)(BlockLiteral *);
char *typeEncoding;
char *extendedLayout;
} BlockCopyDisposeDescriptor;
typedef struct BlockByref {
void *isa;
struct BlockByref *forwarding;
int _Atomic flags;
unsigned int size;
} BlockByref;
typedef struct BlockExtendedByref {
void *isa;
struct BlockExtendedByref *forwarding;
int _Atomic flags;
unsigned int size;
char const *extendedLayout;
} BlockExtendedByref;
typedef struct BlockCopyDisposeByref {
void *reserved;
struct BlockCopyDisposeByref *forwarding;
int _Atomic flags;
unsigned int size;
void (*ByrefCopyHelper)(struct BlockCopyDisposeByref *,
const struct BlockCopyDisposeByref *);
void (*ByrefDisposeHelper)(struct BlockCopyDisposeByref *);
} BlockCopyDisposeByref;
typedef struct BlockCopyDisposeExtendedByref {
void *reserved;
struct BlockCopyDisposeExtendedByref *forwarding;
int _Atomic flags;
unsigned int size;
void (*ByrefCopyHelper)(struct BlockCopyDisposeExtendedByref *,
const struct BlockCopyDisposeExtendedByref *);
void (*ByrefDisposeHelper)(struct BlockCopyDisposeExtendedByref *);
char const *extendedLayout;
} BlockCopyDisposeExtendedByref;
/*
* Compatibility structures.
*/
struct Block_descriptor_1 {
unsigned long reserved;
unsigned long size;
};
struct Block_descriptor_2 {
void (*copy)(void *, void const *);
void (*dispose)(void const *);
};
struct Block_descriptor_3 {
char const *signature;
char const *layout;
};
struct Block_layout {
void *isa;
volatile int flags;
int reserved;
void (*invoke)(void *, ...);
struct Block_descriptor_1 *descriptor;
};
struct Block_byref {
void *isa;
struct Block_byref *forwarding;
volatile int flags;
unsigned int size;
};
struct Block_byref_2 {
void (*byref_keep)(struct Block_byref *, struct Block_byref *);
void (*byref_destroy)(struct Block_byref *);
};
struct Block_byref_3 {
char const *layout;
};
typedef struct Block_callbacks_RR {
unsigned long size;
void (*retain)(void const *);
void (*release)(void const *);
void (*destructInstance)(void const *);
} Block_callbacks_RR;
/*
* Private routines and symbols.
*/
void
_Block_object_assign(void **, void *, BlockCaptureFlags const);
void
_Block_object_dispose(void *, BlockCaptureFlags const);
void
_Block_use_RR2(Block_callbacks_RR const *);
bool
_Block_has_signature(void const *);
char const *
_Block_signature(void const *);
bool
_Block_tryRetain(void *);
bool
_Block_isDeallocating(void const *);
unsigned long
_Block_size(void const *);
bool
_Block_use_stret(void const *);
extern void *_NSConcreteStackBlock[32];
extern void *_NSConcreteMallocBlock[32];
extern void *_NSConcreteGlobalBlock[32];
/* libobjc2 expects these; they are only used under GC and should go away. */
extern void *_NSConcreteAutoBlock[32];
extern void *_NSConcreteFinalizingBlock[32];
#if __cplusplus
}
#endif