ObjFW  Check-in [3cd9d0ad69]

Overview
Comment:Change behaviour of class_getMethodImplementation.

It behaves like in the Apple runtime now.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3cd9d0ad69819d522b1a108ed40fc02230b59c203ead459f677c28dff92b7489
User & Date: js on 2014-01-05 22:31:44
Other Links: manifest | tags
Context
2014-01-09
00:01
Add --disable-files configure flag. check-in: f89edd8ed9 user: js tags: trunk
2014-01-05
22:31
Change behaviour of class_getMethodImplementation. check-in: 3cd9d0ad69 user: js tags: trunk
2014-01-04
16:05
Small documentation improvement. check-in: 130d06933a user: js tags: trunk
Changes

Modified src/runtime/class.m from [753600fe38] to [e18e9ca229].

610
611
612
613
614
615
616










617




















618
619
620
621
622
623
624
{
	return cls->instance_size;
}

IMP
class_getMethodImplementation(Class cls, SEL sel)
{










	return objc_sparsearray_get(cls->dtable, (uint32_t)sel->uid);




















}

const char*
class_getMethodTypeEncoding(Class cls, SEL sel)
{
	struct objc_method_list *ml;
	struct objc_category **cats;







>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
{
	return cls->instance_size;
}

IMP
class_getMethodImplementation(Class cls, SEL sel)
{
	/*
	 * We use a dummy object here so that the normal lookup is used, even
	 * though we don't have an object. Doing so is safe, as objc_msg_lookup
	 * does not access the object, but only its class.
	 *
	 * Just looking it up in the dispatch table could result in returning
	 * NULL instead of the forwarding handler, it would also mean
	 * +[resolveClassMethod:] / +[resolveInstanceMethod:] would not be
	 * called.
	 */

	struct {
		Class isa;
	} dummy = { cls };

	return objc_msg_lookup((id)&dummy, sel);
}

IMP
class_getMethodImplementation_stret(Class cls, SEL sel)
{
	/*
	 * Same as above, but use objc_msg_lookup_stret instead, so that the
	 * correct forwarding handler is returned.
	 */

	struct {
		Class isa;
	} dummy = { cls };

	return objc_msg_lookup_stret((id)&dummy, sel);
}

const char*
class_getMethodTypeEncoding(Class cls, SEL sel)
{
	struct objc_method_list *ml;
	struct objc_category **cats;

Modified src/runtime/lookup.m from [55f05a8843] to [cccd16e367].

25
26
27
28
29
30
31





32
33
34
35
36
37
38

static void *forward_handler = NULL;
static void *forward_handler_stret = NULL;

static IMP
common_method_not_found(id obj, SEL sel, IMP (*lookup)(id, SEL), void *forward)
{





	bool is_class = object_getClass(obj)->info & OBJC_CLASS_INFO_METACLASS;

	if (!(object_getClass(obj)->info & OBJC_CLASS_INFO_INITIALIZED)) {
		Class cls = (is_class ? (Class)obj : object_getClass(obj));

		objc_initialize_class(cls);








>
>
>
>
>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

static void *forward_handler = NULL;
static void *forward_handler_stret = NULL;

static IMP
common_method_not_found(id obj, SEL sel, IMP (*lookup)(id, SEL), void *forward)
{
	/*
	 * obj might be a dummy object (see class_getMethodImplementation), so
	 * don't access obj directly unless it's a class!
	 */

	bool is_class = object_getClass(obj)->info & OBJC_CLASS_INFO_METACLASS;

	if (!(object_getClass(obj)->info & OBJC_CLASS_INFO_INITIALIZED)) {
		Class cls = (is_class ? (Class)obj : object_getClass(obj));

		objc_initialize_class(cls);

Modified src/runtime/runtime.h from [ea4bfdaaf7] to [0f2d559e1c].

193
194
195
196
197
198
199

200
201
202
203
204
205
206
extern const char* class_getName(Class);
extern Class class_getSuperclass(Class);
extern bool class_isKindOfClass(Class, Class);
extern unsigned long class_getInstanceSize(Class);
extern bool class_respondsToSelector(Class, SEL);
extern bool class_conformsToProtocol(Class, Protocol*);
extern IMP class_getMethodImplementation(Class, SEL);

extern const char* class_getMethodTypeEncoding(Class, SEL);
extern IMP class_replaceMethod(Class, SEL, IMP, const char*);
extern Class object_getClass(id);
extern Class object_setClass(id, Class);
extern const char* object_getClassName(id);
extern const char* protocol_getName(Protocol*);
extern bool protocol_isEqual(Protocol*, Protocol*);







>







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
extern const char* class_getName(Class);
extern Class class_getSuperclass(Class);
extern bool class_isKindOfClass(Class, Class);
extern unsigned long class_getInstanceSize(Class);
extern bool class_respondsToSelector(Class, SEL);
extern bool class_conformsToProtocol(Class, Protocol*);
extern IMP class_getMethodImplementation(Class, SEL);
extern IMP class_getMethodImplementation_stret(Class, SEL);
extern const char* class_getMethodTypeEncoding(Class, SEL);
extern IMP class_replaceMethod(Class, SEL, IMP, const char*);
extern Class object_getClass(id);
extern Class object_setClass(id, Class);
extern const char* object_getClassName(id);
extern const char* protocol_getName(Protocol*);
extern bool protocol_isEqual(Protocol*, Protocol*);