Re: App hangs when displaying any sheet in 10.5 [SOLVED]
Re: App hangs when displaying any sheet in 10.5 [SOLVED]
- Subject: Re: App hangs when displaying any sheet in 10.5 [SOLVED]
- From: Graham Cox <email@hidden>
- Date: Fri, 6 Jun 2008 15:26:17 +1000
I guess the question is, given an object type 'id', which method
signature will the compiler go with? Does the return type affect the
method signature? (In C++ it doesn't for example), so two methods:
- (CGPoint) position;
- (float) position;
might well have identical signatures. The compiler doesn't have an
object type to narrow it down, so which will it use - the first it
finds maybe.
So if it picked the first case, it will generate code that returns a
struct CGPoint and try and stuff it into the address of a float, thus
overrunning the stack - in spite of the fact that at runtime, it does
call the correct method which returns a float - there's still a
mismatch between what the compiler expected and what really happened.
In other words, the code to handle the return type was set in stone at
compile time.
That's my best guess as to what's happened here. However, I get no
compile-time warning, despite having many extra warnings turned on,
including the one that usually warns about having no signature for the
method, so assuming it returns int. The lack of this warning suggests
it has found a method signature to use - and it's got the wrong return
type.
This does seem to me either a compiler bug, or something that should
be warned about. (Or it could be that my guesses here are wrong, and
it's something else). This bug has now bitten me twice, and can easily
come to affect code already considered debugged because if Apple
happens to add a method to Cocoa having the same signature but a
different return type from one of your own, it may well cause the
compiler to generate bad code unless you strongly type everything. If
only Obj-C had namespaces....
In this case, Apple did exactly that - two new methods named
'position' were added to Cocoa in 10.5 - one in CALayer, the other in
NSPositionalSpecifier. In 10.4, no method named 'position' existed
anywhere in Cocoa.
cheers, Graham
On 6 Jun 2008, at 2:12 pm, Hamish Allan wrote:
On Thu, Jun 5, 2008 at 5:12 PM, Brian Stern <email@hidden>
wrote:
While float and int are the same size they are returned from
functions in
different registers (on both ppc and intel). If the calling
function expects
a float returned type but an int is returned instead the calling
function
will certainly get a bogus value. In addition it may save and
restore the
wrong registers and not save and restore a register that needs to be
preserved, resulting in memory corruption.
That shouldn't be what happened here, though -- the method in question
was returning a float. Perhaps the calling function expected an int,
but I don't see why...
Hamish
_______________________________________________
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
_______________________________________________
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