Re: "-forwardInvocation:" like NSInvocation creation
Re: "-forwardInvocation:" like NSInvocation creation
- Subject: Re: "-forwardInvocation:" like NSInvocation creation
- From: Michael Ash <email@hidden>
- Date: Tue, 30 Mar 2010 14:54:37 -0400
On Mon, Mar 29, 2010 at 2:15 PM, Philip Mötteli
<email@hidden> wrote:
> Hi,
>
>
> Am 29.03.2010 um 18:52 schrieb A.M.:
>>
>> On Mar 29, 2010, at 11:07 AM, Philip Mötteli wrote:
>>
>>> I need to temporary save the invocation of a method. For that, I just need to put the stack frame into an NSInvocation. Unfortunately, Apple has removed the -setStackFrame: from NSInvocation. Though they still use something like it, because they need it for -forwardInvocation:.
>>> Has anybody implemented a method like [NSInvocation initWithArgframe: (arglist_t)frame selector: (SEL)aSelector]?
>>
>> Hm- you haven't made it clear why you need the stack frame. The stack frame is still there (or constructed on-the-fly), but it is an opaque, hidden structure. As long as you call retainArguments, NSInvocation can be saved for later use.
>
> I see, I really wasn't enough clear. Lets say, I have a method
>
> - someMethodWithArgument:(struct *)anArgument andSomeOtherArgument:(id)anotherArgument
> {
> // Here I want to create an NSInvocation, capturing the call of this method. Something like:
> NSInvocation *anInvocation = [NSInvocation initWithArgframe: (arglist_t)frame selector: _cmd];
> }
I don't think that such a thing is possible in the general case
without compiler support, because once your function begins executing,
there's no guarantee that the arguments remain in their original
locations on the stack frame. (Especially true on PPC and x86_64,
where arguments are frequently passed in registers.) And no such
compiler support exists.
I'd say that your best bet is probably to do some fancy method
replacement stuff so that your IMP gets replaced with the forwarding
IMP, then your -forwardInvocation: method can store the invocation
somewhere and then pass control over to the real method, where it can
retrieve it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden