Skip to content

Instantly share code, notes, and snippets.

@danielpunkass
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpunkass/1290afe953edc2401736 to your computer and use it in GitHub Desktop.
Save danielpunkass/1290afe953edc2401736 to your computer and use it in GitHub Desktop.
// These function pointers are intialized to point to objc_msgSend but with specific
// signatures to help clarify what the selector's expected signature and behavior are.
extern NSString* (*PerformSelectorReturningAutoreleasedString)(id, SEL);
extern NSString* (*PerformSelectorWithObjectReturningAutoreleasedString)(id, SEL, id);
extern id (*PerformSelectorReturningAutoreleasedObject)(id, SEL);
extern void (*PerformSelectorWithObjectReturningVoid)(id, SEL, id);
// To safely dynamic message an object where we expect a BOOL response, we
// need to clue the compiler into the situation sufficiently (this is especially
// broken on Intel if we don't do this).
extern BOOL (*PerformSelectorReturningBOOL)(id, SEL);
extern BOOL (*PerformSelectorWithObjectReturningBOOL)(id, SEL, id);
--------
NSString* (*PerformSelectorReturningAutoreleasedString)(id, SEL) = (NSString* (*)(id, SEL)) objc_msgSend;
NSString* (*PerformSelectorWithObjectReturningAutoreleasedString)(id, SEL, id) = (NSString* (*)(id, SEL, id)) objc_msgSend;
id (*PerformSelectorReturningAutoreleasedObject)(id, SEL) = (id (*)(id, SEL)) objc_msgSend;
void (*PerformSelectorWithObjectReturningVoid)(id, SEL, id) = (void (*)(id, SEL, id)) objc_msgSend;
BOOL (*PerformSelectorReturningBOOL)(id, SEL) = (BOOL (*)(id, SEL)) objc_msgSend;
BOOL (*PerformSelectorWithObjectReturningBOOL)(id, SEL, id) = (BOOL (*)(id, SEL, id)) objc_msgSend;
---------
- (NSString *) rsScriptingValueForSelector:(SEL)selector
{
NSString *s = PerformSelectorReturningAutoreleasedString(self, selector);
if (!s)
{
return @"";
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment