• 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: 2 issues with NSInvocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 2 issues with NSInvocation


  • Subject: Re: 2 issues with NSInvocation
  • From: Tim Hart <email@hidden>
  • Date: Mon, 26 Jan 2004 21:54:05 -0700

Thanks - it was just a typo...

I mean to type ( and my code has )
NSLog( @"aFoo.d = %#x", aFoo.d);

What am I trying to accomplish? It's rather complicated - but basically I need to compare 2 different invocation instances for identical arguments. The number and size of the arguments are not known at compile time.

On Monday, January 26, 2004, at 09:43PM, Louis C. Sacha <email@hidden> wrote:

>Hello...
>
>I can't give you a solution to your problem, but maybe a description
>of what you are trying to accomplish would allow us to make some
>suggestions. Are you trying to use NSInvocation to forward messages
>(or store them), or are you implementing your own class that needs to
>store unknown types of structs, etc... ?
>
>
>Also, it's probably just a typo when you wrote up the email, but part
>of the odd behavior when you're logging your foo struct (if you are
>actually running that code as typed) might be that you're using foo
>instead of foo.d in the NSLog statement.
>
>ie
>NSLog( @"aFoo.d = %#x", aFoo );
>should probably be
>NSLog( @"aFoo.d = %#x", aFoo .d);
>
>
> Louis
>
>
>
>>Summary:
>>
>>1. How do I determine the size of an argument if I don't know the
>>type at compile time?
>>
>>2. On 10.2.8, the following behavior is observed:
>>
>>typedef struct{
>> int a;
>> char b, c;
>> void* d;
>>}foo;
>>
>>@interface MyClass
>>
>>-( void ) setFoo:( foo ) aFoo;
>>
>>@end
>>
>>@implementation MyClass
>>
>>-( void ) setFoo:( foo ) aFoo
>>{
>> NSLog( @"aFoo.d = %#x", aFoo );
>>}
>>
>>@end
>>//code snippets...
>>int a;
>>foo myFoo;
>>myFoo.d = &a;
>>
>>[ myClass setFoo:myFoo ];//Output is something like aFoo.d = 0xffdc4484
>>NSInvocation *myInvocation;
>>// set up invocation with method signature, selector
>>
>>[ myInvocation setArgument:&myFoo atIndex:2 ];
>>[ myInvocation invokeWithTarget:myClass ];//Output is aFoo.d = 0xffdc0000
>>@end
>>
>>Detail:
>>
>>1). With the exception of issue 2 above, it seems that NSInvocation
>>is able to progamatically determine the size of an argument at any
>>particular index. I've tried objc's 'method_getArgumentInfo', but
>>the return values seem completely wrong for sizes. It returned 2 for
>>the size of a char, and 3 for the size of an id.
>>
>>I can ( to a limited degree ) take the encoded type of the argument,
>>and pass it to a big case statement to retrieve the size, but that
>>leads me to 2 other issues:
>>
>>1. The struct above is encoded as "{?=icc^v}". Simply summing their
>>individual sizes is 10. sizeof( foo ) returns 12. I either have to
>>limit my functionality to simple types ( no structs or unions ), or
>>try to figure out at runtime all the alignment/padding issues (
>>which can be compile time choices ). To the best of my knowledge,
>>determining alignment at runtime is impossible without knowing
>>something about the data.
>>
>>2. I'd rather not reinvent the wheel. Since -[ NSInvocation
>>setArgument:atIndex ] doesn't require a size, I'm assuming that
>>*somewhere* in the runtime there is code to determine the size of an
>>argument.
>>
>>In my implementation, I can require the user of my API to pass in
>>argument sizes, but I'm hoping for 2 - so the user won't have to.
>>
>>P.S. - yes, I realize MacOSX is up to 10.3.2 now. I will test
>>against 10.3 when I get the chance to upgrade in a couple of weeks.
>>I was hoping someone knew about this issue and a workaround.
>>_______________________________________________
>>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.
_______________________________________________
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.

  • Prev by Date: What's it called if it's not a controller?
  • Next by Date: Re: iPhoto Library Info
  • Previous by thread: 2 issues with NSInvocation
  • Next by thread: iPhoto Library Info
  • Index(es):
    • Date
    • Thread