backport bugfixes from ObjectiveC2 code

main
rfm 16 years ago
parent bf92e25952
commit e2f4f38e45

@ -550,12 +550,17 @@ class_get_meta_class(Class _class)
static inline Class static inline Class
class_get_super_class(Class _class) class_get_super_class(Class _class)
{ {
void __objc_resolve_class_links(void); if (!CLS_ISRESOLV(cls))
if (!CLS_ISRESOLV(_class))
{ {
__objc_resolve_class_links(); /* This class is not yet resolved ... so lookup superclass by name.
* We need to allow for this case because we might doing a lookup in
* a class which has not yet been registered with the runtime and
* which might have ivars or methods added after this call (so we
* mustn't resolve this class now).
*/
return (Class)objc_getClass((const char*)cls->super_class);
} }
return _class->super_class; return cls->super_class;
} }
static inline int static inline int

@ -124,21 +124,25 @@ static void objc_updateDtableForClassContainingMethod(Method m)
} }
} }
BOOL
BOOL class_addIvar(Class cls, class_addIvar(Class cls, const char *name,
const char *name, size_t size, uint8_t alignment, const char *types)
size_t size,
uint8_t alignment,
const char *types)
{ {
struct objc_ivar_list *ivarlist;
unsigned off;
Ivar ivar;
if (CLS_ISRESOLV(cls) || CLS_ISMETA(cls)) if (CLS_ISRESOLV(cls) || CLS_ISMETA(cls))
{ {
return NO; return NO;
} }
struct objc_ivar_list *ivarlist = cls->ivars; if (class_getInstanceVariable(cls, name) != NULL)
{
return NO;
}
if (class_getInstanceVariable(cls, name) != NULL) { return NO; } ivarlist = cls->ivars;
if (NULL == ivarlist) if (NULL == ivarlist)
{ {
@ -150,14 +154,18 @@ BOOL class_addIvar(Class cls,
ivarlist->ivar_count++; ivarlist->ivar_count++;
// objc_ivar_list contains one ivar. Others follow it. // objc_ivar_list contains one ivar. Others follow it.
cls->ivars = objc_realloc(ivarlist, sizeof(struct objc_ivar_list) cls->ivars = objc_realloc(ivarlist, sizeof(struct objc_ivar_list)
+ (ivarlist->ivar_count - 1) * sizeof(struct objc_ivar)); + (ivarlist->ivar_count -
1) * sizeof(struct objc_ivar));
} }
Ivar ivar = &cls->ivars->ivar_list[cls->ivars->ivar_count - 1]; ivar = &cls->ivars->ivar_list[cls->ivars->ivar_count - 1];
ivar->ivar_name = strdup(name); ivar->ivar_name = strdup(name);
ivar->ivar_type = strdup(types); ivar->ivar_type = strdup(types);
// Round up the offset of the ivar so it is correctly aligned. // Round up the offset of the ivar so it is correctly aligned.
ivar->ivar_offset = cls->instance_size + (cls->instance_size % alignment); off = cls->instance_size >> alignment;
if (off << alignment != cls->instance_size)
off = (off + 1) << alignment;
ivar->ivar_offset = off;
// Increase the instance size to make space for this. // Increase the instance size to make space for this.
cls->instance_size = ivar->ivar_offset + size; cls->instance_size = ivar->ivar_offset + size;
return YES; return YES;

Loading…
Cancel
Save