From 53bc9f38925bdbc1ff1beda748cc759d6a13d43a Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 7 Dec 2015 09:04:47 +0000 Subject: [PATCH] Fix the size of run-time generated root classes. The size of the new class with should be sizeof(Class), not sizeof(struct objc_class). --- Test/AllocatePair.m | 2 ++ runtime.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Test/AllocatePair.m b/Test/AllocatePair.m index cab64a7..3afeb48 100644 --- a/Test/AllocatePair.m +++ b/Test/AllocatePair.m @@ -15,6 +15,8 @@ int main() { Class a, b, c, d, e; + assert(class_getInstanceSize(objc_allocateClassPair(Nil, "Empty", 0)) == sizeof(Class)); + a = objc_allocateClassPair([Test class], "A", 0); a = objc_allocateClassPair([Test class], "A", 0); objc_registerClassPair(a); diff --git a/runtime.c b/runtime.c index 4352ccc..14a8d9e 100644 --- a/runtime.c +++ b/runtime.c @@ -726,7 +726,7 @@ Class objc_allocateClassPair(Class superclass, const char *name, size_t extraByt if (Nil == superclass) { - newClass->instance_size = sizeof(struct objc_class); + newClass->instance_size = sizeof(struct objc_class*); } else {