• 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: Which flavor of objc_msgSend for NSSize return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which flavor of objc_msgSend for NSSize return


  • Subject: Re: Which flavor of objc_msgSend for NSSize return
  • From: Rosyna <email@hidden>
  • Date: Fri, 11 May 2007 19:20:14 -0700

You're just getting "lucky" that it returns what is perceived to be the correct values. If you run it multiple times, you may get completely different values.

[stability-drive:~/Desktop] rosyna% gcc -framework Foundation donkey.m
[stability-drive:~/Desktop] rosyna% ./a.out
2007-05-11 18:55:51.277 a.out[9461] Point is {0, -1.9996}

The typecast is crashing because stret expects the second arg to be id but you're shifting the params.

With this version, you're passing the correct types, but completely... off the kilter.

Try this

NSPoint point = { nan(""), nan("") };
objc_msgSend_stret(&point, [Foo class], @selector(point));

You'll get

[stability-drive:~/Desktop] rosyna% ./a.out
2007-05-11 19:03:47.660 a.out[9493] Point is {nan, nan}

Which is clearly not correct. It's reading the old values and not setting any new ones.

To really show this, try this:

@interface Foo : NSObject {} @end
@implementation Foo
+ (NSPoint)point
{
NSLog(@"%@ %@", NSStringFromPoint(*(NSPoint *)self), _cmd);
return NSMakePoint(1, 2);
}
@end

You may get

[stability-drive:~/Desktop] rosyna% ./a.out
2007-05-11 19:13:51.167 a.out[9525] {nan, inf} Foo
2007-05-11 19:13:51.168 a.out[9525] Point is {nan, inf}

All the arguments are shifted incorrectly by one.

So not only are you now getting junk values, you've changed the arguments around.

Final test code:

#import <Foundation/Foundation.h>
#import <objc/objc-runtime.h>
@interface Foo : NSObject {} @end
@implementation Foo
+ (NSPoint)point {
NSLog(@"%@ %@", NSStringFromPoint(*(NSPoint *)self), _cmd);
return NSMakePoint(1, 2); }
@end

int main(int argc, const char *argv[])
{
[NSAutoreleasePool new];
NSPoint point = { nan(""), INFINITY };
objc_msgSend_stret(&point, [Foo class], @selector(point));
NSLog(@"Point is %@", NSStringFromPoint(point));
return 0;
}

Ack, at 5/11/07, Sherm Pendley said:

When I call objc_msgSend_stret() in CamelBones, I call it as documented in the runtime reference, returning the struct by reference in the first argument. It's much simpler, with no need for the typecast. Does this variation work for you?

Yes, I'm aware of the note regarding typecasting in objc-runtime.h; IMHO, the runtime reference docs are the official last word, and take precedence over a cryptic comment buried in a header file. That comment has been there for at least six years, to my knowledge, and all the while the runtime reference has made no mention of this function being unreliable for future use.

--


Sincerely, Rosyna Keller Technical Support/Carbon troll/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People

It's either this, or imagining Phil Schiller in a thong.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >Which flavor of objc_msgSend for NSSize return (From: Rosyna <email@hidden>)
 >Re: Which flavor of objc_msgSend for NSSize return (From: Sherm Pendley <email@hidden>)
 >Re: Which flavor of objc_msgSend for NSSize return (From: Rosyna <email@hidden>)
 >Re: Which flavor of objc_msgSend for NSSize return (From: Sherm Pendley <email@hidden>)
 >Re: Which flavor of objc_msgSend for NSSize return (From: Rosyna <email@hidden>)
 >Re: Which flavor of objc_msgSend for NSSize return (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Which flavor of objc_msgSend for NSSize return
  • Next by Date: Re: Which flavor of objc_msgSend for NSSize return
  • Previous by thread: Re: Which flavor of objc_msgSend for NSSize return
  • Next by thread: Re: Which flavor of objc_msgSend for NSSize return
  • Index(es):
    • Date
    • Thread