groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

objc_msgSend() does work on ARM64 when cast correctly. #86

Closed jonathandann closed 8 years ago

jonathandann commented 9 years ago

+[GRMustacheKeyAccess valueForMustacheKey:inFoundationCollectionObject:] does work if you cast the call to objc_msgSend() properly.

WWDC 2014, Session 417, "What's new in LLVM". "objc_msgSend without a typecast is usually an error."

ENABLE_STRICT_OBJC_MSGSEND can help

groue commented 9 years ago

That's very interesting, thank you @jonathandann! Let's dive into this session :smile:

groue commented 9 years ago

Inspired by this WWDC session, the following code snippets actually do successfully execute NSObject's implementation of valueForKey: on NSArray, NSSet and NSOrderedSet (this trick helps us evaluating tags like {{ items.count }}):

// Using class_getMethodImplementation
typedef id (*send_type)(id, SEL, id);
send_type func = (send_type)class_getMethodImplementation([NSObject class], @selector(valueForKey:));
return func(object, @selector(valueForKey:), key);

// Using objc_msgSendSuper
typedef id (*send_type)(struct objc_super *, SEL, id key);
send_type func = (send_type)objc_msgSendSuper;
return func(&(struct objc_super){ .receiver = object, .super_class = [NSObject class] }, @selector(valueForKey:), key);

I still have to test them on arm64, and pick my favorite option :-)

This would be a nice fix to issue #70, much better than the current one (https://github.com/groue/GRMustache/blob/master/src/classes/Rendering/GRMustacheKeyAccess.m#L204-L337)

groue commented 8 years ago

This issue will become obsolete with #100.