Correctly calculate the offset when adding ivars.

main
theraven 16 years ago
parent 9e64fb7828
commit e1562b28d4

@ -94,8 +94,9 @@ BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment,
if (offset << alignment != cls->instance_size) if (offset << alignment != cls->instance_size)
{ {
offset = (offset+ 1) << alignment; offset++;
} }
offset <<= alignment;
ivar->offset = offset; ivar->offset = offset;
// Increase the instance size to make space for this. // Increase the instance size to make space for this.
@ -288,30 +289,27 @@ size_t class_getInstanceSize(Class cls)
Ivar Ivar
class_getInstanceVariable(Class cls, const char *name) class_getInstanceVariable(Class cls, const char *name)
{ {
if (name != NULL) if (name != NULL)
{
while (cls != Nil)
{ {
struct objc_ivar_list *ivarlist = cls->ivars; while (cls != Nil)
if (ivarlist != NULL)
{
int i;
for (i = 0; i < ivarlist->count; i++)
{ {
Ivar ivar = &ivarlist->ivar_list[i]; struct objc_ivar_list *ivarlist = cls->ivars;
if (strcmp(ivar->name, name) == 0) if (ivarlist != NULL)
{ {
return ivar; for (int i = 0; i < ivarlist->count; i++)
} {
Ivar ivar = &ivarlist->ivar_list[i];
if (strcmp(ivar->name, name) == 0)
{
return ivar;
}
}
}
cls = class_getSuperclass(cls);
} }
}
cls = class_getSuperclass(cls);
} }
} return NULL;
return NULL;
} }
// The format of the char* is undocumented. This function is only ever used in // The format of the char* is undocumented. This function is only ever used in

Loading…
Cancel
Save