Re: subclass overwriting superclass ivar
Re: subclass overwriting superclass ivar
- Subject: Re: subclass overwriting superclass ivar
- From: "email@hidden" <email@hidden>
- Date: Thu, 27 May 2010 12:53:23 +0100
On 26 May 2010, at 20:00, Greg Parker wrote:
>>
>
> Mac or iPhone?
> iPhone device or iPhone simulator?
> 32-bit Mac or 64-bit Mac?
>
Sorry for the vagueness. 32 bit mac.
> My guess is that (1) you're running on iPhone Simulator or 32-bit Mac, and (2) you recently added an ivar to MGS_A but did not recompile all code that uses MGS_B. In that case, any MGS_B code that was compiled with the old declaration of MGS_A will think MGS_A is smaller than it actually is, and write its ivar values to the wrong place.
>
> Try a clean rebuild of everything. If the above is the problem, a clean build should fix it.
A clean build does sort it out.
I am astonished that I don't fall over this simple issue every day.
MGS_A and MGS_B exist in the same module (a private framework).
If I add an ivar to MGS_A and build my app then MGS_B succumbs to the fragile ivar syndrome.
I have to touch MGS_B and rebuild in order to update its ivar offsets.
I always presumed that as MGS_B is a subclass of MGS_A it would get built too.
Is there no build support to help with these sorts of class dependencies?
Or have I borked my build settings somewhere?
>
> You can also check ivar offsets that the runtime expects. These two values should be different:
> #include <objc/runtime.h>
> printf("tempFilePath %zu, stderrData %zu\n",
> (size_t)ivar_getOffset(class_getInstanceVariable(objc_getClass("MGS_A"), "tempFilePath")),
> (size_t)ivar_getOffset(class_getInstanceVariable(objc_getClass("MGS_B"), "stderrData")));
>
This does indeed confirm the offsets. Thanks.
>
> iPhone device and 64-bit Mac should not have this problem. The compiler and runtime cooperate to allow the runtime to move the subclass's ivars out of the way if the superclass grows.
> http://sealiesoftware.com/blog/archive/2009/01/27/objc_explain_Non-fragile_ivars.html
>
I presume that 32 cannot not get this bit of TLC for backwards compatibility reasons.
Regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
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