• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange NSInvocation behavior when passing pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange NSInvocation behavior when passing pointers


  • Subject: Re: Strange NSInvocation behavior when passing pointers
  • From: Nathan Day <email@hidden>
  • Date: Sun, 14 Jul 2002 21:35:28 +0930

Passed pointers are handled like this if you call the -[NSInvocation retainArguments] method, if you tried to return a pointer to a local variable then that would not be safe since once the method ends, it's stack frame is no longer valid. I assume you can't just declare the return type of the method as (void *), if you can call the method using one of the performSelector: methods I sure I read somewhere that it will work if the return type is the same size as an id, so you can just recast your returned value to the right type. You could perhaps try declaring a method that takes the same arguments as your method but with a void* return type as a informal protocol create your NSInvocation using the NSMethodSignature for this new method but then set the NSInvocation's selector to the method you really want to call.

On Sunday, July 14, 2002, at 08:53 PM, Philippe Mougin wrote:

When a method returning a pointer (other than an object pointer) is invoked through a NSInvocation, it seems that you don't get back the original pointer returned by the method.

Instead, it seems that NSInvocation dereference the pointer, copy the value it points to, and give you back a pointer to this copy (note: if the invoked method is declared to return a generic pointer (i.e. void *), NSInvocation does not have enough information to dereference the pointer, so in this case it give you back the original pointer)

I haven't verified, but I suppose the same kind of "copying" behavior is not only applied to return value but also to arguments, in the case of pointers.

All of this seems similar to the distributed object system behavior regarding pointers.

Questions:

1) What is the point of doing this in the non-distributed situation? (Doesn't sounds like a good idea to me).

2) Do you know if this NSInvocation behavior this documented somewhere?

3) In my program, I want to get at the "real" pointers returned or passed as argument. Is there a way to turn-off this strange NSInvocation behavior?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Strange NSInvocation behavior when passing pointers
      • From: Philippe Mougin <email@hidden>
References: 
 >Strange NSInvocation behavior when passing pointers (From: Philippe Mougin <email@hidden>)

  • Prev by Date: Re: Carbon API with carbon
  • Next by Date: GNUStep and Cocoa Portabilitiy (Re: Carbon API with carbon)
  • Previous by thread: Strange NSInvocation behavior when passing pointers
  • Next by thread: Re: Strange NSInvocation behavior when passing pointers
  • Index(es):
    • Date
    • Thread