ObjFW  Diff

Differences From Artifact [0cda48050d]:

To Artifact [daa6113db1]:


8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26







-




+







 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#import "OFBlock.h"
#import "OFExceptions.h"
#import "atomic.h"

/// \cond internal
@protocol RetainRelease
- retain;
- (void)release;
@end
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
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







-
-
-
+
+
+


+
+
+
+
+









-
-
+
+
+







static void __attribute__((constructor))
constructor()
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#else
void *_NSConcreteStackBlock;
void *_NSConcreteGlobalBlock;
void *_NSConcreteMallocBlock;
extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;
extern void *_NSConcreteMallocBlock;
#endif

#ifndef HAVE_BLOCK_COPY
static struct {
	Class isa;
} alloc_failed_exception;

void*
_Block_copy(const void *block_)
{
	of_block_literal_t *block = (of_block_literal_t*)block_;

	if (block->isa == (Class)&_NSConcreteStackBlock) {
		of_block_literal_t *copy;

		if ((copy = malloc(block->descriptor->size)) == NULL) {
			fputs("Not enough memory to copy block!\n", stderr);
			exit(1);
			alloc_failed_exception.isa =
			    [OFAllocFailedException class];
			@throw (OFAllocFailedException*)&alloc_failed_exception;
		}
		memcpy(copy, block, block->descriptor->size);

		copy->isa = (Class)&_NSConcreteMallocBlock;
		copy->reserved++;

		if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)
172
173
174
175
176
177
178
179
180
181




182
183
184
185
186
187
188
178
179
180
181
182
183
184



185
186
187
188
189
190
191
192
193
194
195







-
-
-
+
+
+
+







		break;
	case OF_BLOCK_FIELD_IS_BYREF:;
		of_block_byref_t *src = (of_block_byref_t*)src_;
		of_block_byref_t **dst = (of_block_byref_t**)dst_;

		if ((src->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) {
			if ((*dst = malloc(src->size)) == NULL) {
				fputs("Not enough memory for block "
				    "variables!\n", stderr);
				exit(1);
				alloc_failed_exception.isa =
				    [OFAllocFailedException class];
				@throw (OFAllocFailedException*)
				    &alloc_failed_exception;
			}

			if (src->forwarding == src)
				src->forwarding = *dst;

			memcpy(*dst, src, src->size);

217
218
219
220
221
222
223

224
225
226




227
228
229
230
231
232
233
234
235
236
237
238
239
240
241











242
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265







+



+
+
+
+















+
+
+
+
+
+
+
+
+
+
+

				obj->byref_dispose(obj);

			free(obj);
		}
		break;
	}
}
#endif

/// \cond internal
@implementation OFBlock
+ (void)initialize
{
}

+ (Class)class
{
	return self;
}

- copy
{
	return Block_copy(self);
}

- (void)release
{
	Block_release(self);
}
@end

#if !defined(OF_GNU_RUNTIME) && !defined(OF_OBJFW_RUNTIME)
@implementation OFStackBlock
@end

@implementation OFGlobalBlock
@end

@implementation OFMallocBlock
@end
#endif
/// \endcond