mirror of
https://github.com/darlinghq/darling-libobjc2.git
synced 2024-11-23 12:19:44 +00:00
Correctly calculate the offset when adding ivars.
This commit is contained in:
parent
9e64fb7828
commit
e1562b28d4
38
runtime.c
38
runtime.c
@ -94,8 +94,9 @@ BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment,
|
||||
|
||||
if (offset << alignment != cls->instance_size)
|
||||
{
|
||||
offset = (offset+ 1) << alignment;
|
||||
offset++;
|
||||
}
|
||||
offset <<= alignment;
|
||||
|
||||
ivar->offset = offset;
|
||||
// Increase the instance size to make space for this.
|
||||
@ -288,30 +289,27 @@ size_t class_getInstanceSize(Class cls)
|
||||
Ivar
|
||||
class_getInstanceVariable(Class cls, const char *name)
|
||||
{
|
||||
if (name != NULL)
|
||||
{
|
||||
while (cls != Nil)
|
||||
if (name != NULL)
|
||||
{
|
||||
struct objc_ivar_list *ivarlist = cls->ivars;
|
||||
|
||||
if (ivarlist != NULL)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ivarlist->count; i++)
|
||||
while (cls != Nil)
|
||||
{
|
||||
Ivar ivar = &ivarlist->ivar_list[i];
|
||||
struct objc_ivar_list *ivarlist = cls->ivars;
|
||||
|
||||
if (strcmp(ivar->name, name) == 0)
|
||||
{
|
||||
return ivar;
|
||||
}
|
||||
if (ivarlist != NULL)
|
||||
{
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user