objective c - Make NSInvocation invoke a specific IMP -


i'm looking way make nsinvocation invoke specific imp. default, invokes "lowest" imp can find (ie, most-recently-overridden version), i'm looking way make invoke imp higher in inheritance chain. imp want invoke determined dynamically, or else i'd able use super keyword or that.

my thought use -forwardinvocation: mechanism capture message (easy , working) , alter imp goes method neither super implementation nor furthest descendent's implementation. (hard)

the thing i've found comes remotely close aspectobjectivec, requires libffi, makes non-ios compatible. ideally i'd cross platform.

any ideas?

disclaimer: i'm experimenting


trying out @bbum's idea of trampoline function

so think i've got things set up; i've got following trampoline gets correctly added via class_addmethod(), , entered:

id dd_trampolinefunction(id self, sel _cmd, ...) {     imp imp = [self retrievetheproperimp];     self = [self retrievetheproperselfobject];     asm(         "jmp %0\n"         :         : "r" (imp)         );     return nil; //to shut compiler } 

i've verified both proper self , proper imp right things prior jmp, , _cmd parameter coming in properly. (in other words, correctly added method).

however, going on. find myself jumping method (usually not right one) nil self , _cmd. other times i'll crash in middle of exc_bad_access. ideas? (it's been long time since i've done in assembly...) i'm testing on x86_64.

given have imp, need way raw forward of method call said imp. , given willing use nsinvocation solution, build similar proxy class.

if faced this, create simple proxying class contained imp called , target object (you'll need set self parameter). then, write trampoline function in assembly takes first argument, assumes instance of proxying class, grabs self, stuffs register holding argument 0, grabs imp , *jmps tail call.

with trampoline in hand, add trampoline imp selector on proxying class want forwarded particular imp....

to achieve kind of generic mechanism this, key avoid having rewriting stack frame. avoid c abi. avoid moving arguments about.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -