diff --git a/ivar.c b/ivar.c index 671eea4..37f99d7 100644 --- a/ivar.c +++ b/ivar.c @@ -22,6 +22,11 @@ PRIVATE void objc_compute_ivar_offsets(Class class) legacy = (struct objc_ivar_list_legacy *)class->ivars; class->ivars = upgradeIvarList(class, legacy); } + if (class->ivars->size != sizeof(struct objc_ivar)) + { + fprintf(stderr, "Downgrading ivar struct not yet implemented"); + abort(); + } int i = 0; /* If this class was compiled with support for late-bound ivars, the * instance_size field will contain 0 - {the size of the instance variables @@ -159,6 +164,7 @@ static struct objc_ivar_list *upgradeIvarList(Class cls, struct objc_ivar_list_l } struct objc_ivar_list *n = calloc(1, sizeof(struct objc_ivar_list) + l->count*sizeof(struct objc_ivar)); + n->size = sizeof(struct objc_ivar); n->count = l->count; for (int i=0 ; icount ; i++) { diff --git a/ivar.h b/ivar.h index a7b42bb..5ebcf20 100644 --- a/ivar.h +++ b/ivar.h @@ -27,7 +27,7 @@ struct objc_ivar /** * Flags for this instance variable. */ - int flags; + long flags; }; /** @@ -107,6 +107,12 @@ struct objc_ivar_list * The number of instance variables in this list. */ int count; + /** + * The size of a `struct objc_ivar`. This allows the runtime to load + * versions of this that come from a newer compiler, if we ever need to do + * so. + */ + size_t size; /** * An array of instance variable metadata structures. Note that this array * has count elements. diff --git a/runtime.c b/runtime.c index c52dadf..4c56a29 100644 --- a/runtime.c +++ b/runtime.c @@ -129,6 +129,7 @@ BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment, if (NULL == ivarlist) { cls->ivars = malloc(sizeof(struct objc_ivar_list) + sizeof(struct objc_ivar)); + cls->ivars->size = sizeof(struct objc_ivar); cls->ivars->count = 1; } else