ObjFW  Check-in [ede088a30d]

Overview
Comment:runtime: Match Apple's +[initialize] behavior

This now calls +[initialize] several times on the same class if it is
unimplemented in one or more of the classes in the chain, to match the
behavior of the Apple runtime. While the behavior before was safer, it
can lead to testing against the ObjFW runtime and everything working,
but then failing when trying to use it with the Apple runtime.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ede088a30d32e56c2db4e1d7344a006682ed979f6b5d6390b18be2bf7ff3fbe5
User & Date: js on 2019-04-14 13:35:38
Other Links: manifest | tags
Context
2019-04-14
15:40
Use more const check-in: dfd61e781e user: js tags: trunk
13:35
runtime: Match Apple's +[initialize] behavior check-in: ede088a30d user: js tags: trunk
10:59
OFStringTests: Fix a new Clang warning check-in: efb964a3ae user: js tags: trunk
Changes

Modified src/runtime/class.m from [6851361cb3] to [889cba075c].

331
332
333
334
335
336
337


338
339
340
341
342
343
344
345
	/*
	 * Set it first to prevent calling it recursively due to message sends
	 * in the initialize method
	 */
	class->info |= OBJC_CLASS_INFO_INITIALIZED;
	class->isa->info |= OBJC_CLASS_INFO_INITIALIZED;



	callMethod(class, "initialize");
}

void
objc_initialize_class(Class class)
{
	if (class->info & OBJC_CLASS_INFO_INITIALIZED)
		return;







>
>
|







331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
	/*
	 * Set it first to prevent calling it recursively due to message sends
	 * in the initialize method
	 */
	class->info |= OBJC_CLASS_INFO_INITIALIZED;
	class->isa->info |= OBJC_CLASS_INFO_INITIALIZED;

	if (class_respondsToSelector(object_getClass(class),
	    @selector(initialize)))
		[class initialize];
}

void
objc_initialize_class(Class class)
{
	if (class->info & OBJC_CLASS_INFO_INITIALIZED)
		return;

Modified src/runtime/lookup.m from [b612119f40] to [15533381ae].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>

#import "ObjFW_RT.h"
#import "private.h"
#import "macros.h"

@interface DummyObject
{
	Class isa;
}

+ (bool)resolveClassMethod: (SEL)selector;
+ (bool)resolveInstanceMethod: (SEL)selector;
@end

static IMP forwardHandler = (IMP)0;
static IMP stretForwardHandler = (IMP)0;

static IMP
commonMethodNotFound(id object, SEL selector, IMP (*lookup)(id, SEL),
    IMP forward)
{







<
<
<
<
<
<
<
<
<







20
21
22
23
24
25
26









27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>

#import "ObjFW_RT.h"
#import "private.h"
#import "macros.h"










static IMP forwardHandler = (IMP)0;
static IMP stretForwardHandler = (IMP)0;

static IMP
commonMethodNotFound(id object, SEL selector, IMP (*lookup)(id, SEL),
    IMP forward)
{

Modified src/runtime/private.h from [69f97ea107] to [88abdbc6a0].

274
275
276
277
278
279
280










		fprintf(stderr, "[objc @ " __FILE__ ":%d] ", __LINE__);	\
		fprintf(stderr, __VA_ARGS__);				\
		fprintf(stderr, "\n");					\
		fflush(stderr);						\
		abort();						\
		OF_UNREACHABLE						\
	}

















>
>
>
>
>
>
>
>
>
>
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
		fprintf(stderr, "[objc @ " __FILE__ ":%d] ", __LINE__);	\
		fprintf(stderr, __VA_ARGS__);				\
		fprintf(stderr, "\n");					\
		fflush(stderr);						\
		abort();						\
		OF_UNREACHABLE						\
	}

@interface DummyObject
{
	Class _Nonnull isa;
}

+ (void)initialize;
+ (bool)resolveClassMethod: (nonnull SEL)selector;
+ (bool)resolveInstanceMethod: (nonnull SEL)selector;
@end