ObjFW  Check-in [7a6f696ef3]

Overview
Comment:Make blocks work with the old Apple ObjC runtime.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7a6f696ef32d73c9786b8203fee682c5c3b7a8ad6829a9ec5e587e32afc67753
User & Date: js on 2010-11-12 15:08:31
Other Links: manifest | tags
Context
2010-11-12
16:00
Always use our _Block_copy. check-in: 4285aea3c6 user: js tags: trunk
15:08
Make blocks work with the old Apple ObjC runtime. check-in: 7a6f696ef3 user: js tags: trunk
14:06
More compatibility with other blocks runtimes. check-in: c0863afedf user: js tags: trunk
Changes

Modified src/OFBlock.m from [04ef10271b] to [0576db1a73].

10
11
12
13
14
15
16




17
18
19
20
21
22
23
 */

#include "config.h"

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





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

/// \cond internal
@protocol RetainRelease







>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 */

#include "config.h"

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

#if defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__)
# import <objc/runtime.h>
#endif

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

/// \cond internal
@protocol RetainRelease
102
103
104
105
106
107
108
















109
110
111
112
113
114
115

static void __attribute__((constructor))
constructor()
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
















#else
extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;
extern void *_NSConcreteMallocBlock;
#endif

#ifndef HAVE_BLOCK_COPY







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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

static void __attribute__((constructor))
constructor()
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#elif defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__)
struct class {
	struct class *isa, *super_class;
	const char *name;
	long version, info, instance_size;
	struct ivar_list *ivars;
	struct method_list **methodLists;
	struct cache *cache;
	struct protocol_list *protocols;
	const char *ivar_layout;
	struct class_ext *ext;
};

struct class _NSConcreteStackBlock;
struct class _NSConcreteGlobalBlock;
struct class _NSConcreteMallocBlock;
#else
extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;
extern void *_NSConcreteMallocBlock;
#endif

#ifndef HAVE_BLOCK_COPY
228
229
230
231
232
233
234































235
236
237
238
239
240
241
		break;
	}
}
#endif

/// \cond internal
@implementation OFBlock































+ alloc
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}

- init







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
		break;
	}
}
#endif

/// \cond internal
@implementation OFBlock
#if defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__)
+ (void)load
{
	Class tmp;

	/*
	 * There is no objc_initializeClassPair in 10.5.
	 * However, objc_allocateClassPair does not register the new class with
	 * the subclass in the ObjC1 runtime like the ObjC2 runtime does, so
	 * this workaround should be fine.
	 */
	if ((tmp = objc_allocateClassPair(self, "OFStackBlock", 0)) == NULL)
		@throw [OFInitializationFailedException newWithClass: self];
	memcpy(&_NSConcreteStackBlock, tmp, sizeof(_NSConcreteStackBlock));
	free(tmp);
	objc_registerClassPair((Class)&_NSConcreteStackBlock);

	if ((tmp = objc_allocateClassPair(self, "OFGlobalBlock", 0)) == NULL)
		@throw [OFInitializationFailedException newWithClass: self];
	memcpy(&_NSConcreteGlobalBlock, tmp, sizeof(_NSConcreteGlobalBlock));
	free(tmp);
	objc_registerClassPair((Class)&_NSConcreteGlobalBlock);

	if ((tmp = objc_allocateClassPair(self, "OFMallocBlock", 0)) == NULL)
		@throw [OFInitializationFailedException newWithClass: self];
	memcpy(&_NSConcreteMallocBlock, tmp, sizeof(_NSConcreteMallocBlock));
	free(tmp);
	objc_registerClassPair((Class)&_NSConcreteMallocBlock);
}
#endif

+ alloc
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}

- init
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	[super dealloc];	/* Get rid of a stupid warning */
}
@end

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

@implementation OFGlobalBlock
@end

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







|










374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
	[super dealloc];	/* Get rid of a stupid warning */
}
@end

#if defined(OF_APPLE_RUNTIME) && defined(__OBJC2__)
@implementation OFStackBlock
@end

@implementation OFGlobalBlock
@end

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