@@ -139,12 +139,13 @@ instance = malloc(PRE_IVAR_ALIGN + instanceSize + extraAlignment + extraSize); if (OF_UNLIKELY(instance == nil)) { - alloc_failed_exception.isa = [OFAllocFailedException class]; - @throw (OFAllocFailedException*)&alloc_failed_exception; + object_setClass((id)&alloc_failed_exception, + [OFAllocFailedException class]); + @throw (id)&alloc_failed_exception; } ((struct pre_ivar*)instance)->retainCount = 1; ((struct pre_ivar*)instance)->firstMem = NULL; ((struct pre_ivar*)instance)->lastMem = NULL; @@ -158,13 +159,12 @@ } #endif instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN); - instance->isa = class; - memset((char*)instance + sizeof(instance->isa), 0, - instanceSize - sizeof(instance->isa)); + memset(instance, 0, instanceSize); + object_setClass(instance, class); if (OF_UNLIKELY(extra != NULL)) *extra = (char*)instance + instanceSize + extraAlignment; return instance; @@ -365,11 +365,11 @@ + (IMP)replaceClassMethod: (SEL)selector withImplementation: (IMP)implementation typeEncoding: (const char*)typeEncoding { - return class_replaceMethod(((OFObject*)self)->isa, selector, + return class_replaceMethod(object_getClass(self), selector, implementation, typeEncoding); } + (void)inheritMethodsFromClass: (Class)class { @@ -380,11 +380,11 @@ #if defined(OF_APPLE_RUNTIME) Method *methodList; unsigned i, count; - methodList = class_copyMethodList(((OFObject*)class)->isa, &count); + methodList = class_copyMethodList(object_getClass(class), &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* @@ -420,11 +420,11 @@ free(methodList); } #elif defined(OF_OBJFW_RUNTIME) struct objc_method_list *methodlist; - for (methodlist = class->isa->methodlist; + for (methodlist = object_getClass(class)->methodlist; methodlist != NULL; methodlist = methodlist->next) { int i; for (i = 0; i < methodlist->count; i++) { SEL selector = (SEL)&methodlist->methods[i].sel; @@ -467,11 +467,12 @@ - init { Class class; void (*last)(id, SEL) = NULL; - for (class = isa; class != Nil; class = class_getSuperclass(class)) { + for (class = object_getClass(self); class != Nil; + class = class_getSuperclass(class)) { void (*construct)(id, SEL); if ([class instancesRespondToSelector: cxx_construct]) { if ((construct = (void(*)(id, SEL))[class instanceMethodForSelector: cxx_construct]) != last) @@ -485,48 +486,49 @@ return self; } - (Class)class { - return isa; + return object_getClass(self); } - (OFString*)className { - return [OFString stringWithCString: class_getName(isa) + return [OFString stringWithCString: object_getClassName(self) encoding: OF_STRING_ENCODING_ASCII]; } - (BOOL)isKindOfClass: (Class)class { Class iter; - for (iter = isa; iter != Nil; iter = class_getSuperclass(iter)) + for (iter = object_getClass(self); iter != Nil; + iter = class_getSuperclass(iter)) if (iter == class) return YES; return NO; } - (BOOL)isMemberOfClass: (Class)class { - return (isa == class); + return (object_getClass(self) == class); } - (BOOL)respondsToSelector: (SEL)selector { - return class_respondsToSelector(isa, selector); + return class_respondsToSelector(object_getClass(self), selector); } - (BOOL)conformsToProtocol: (Protocol*)protocol { - return [isa conformsToProtocol: protocol]; + return [object_getClass(self) conformsToProtocol: protocol]; } - (IMP)methodForSelector: (SEL)selector { - return class_getMethodImplementation(isa, selector); + return class_getMethodImplementation(object_getClass(self), selector); } - (id)performSelector: (SEL)selector { id (*imp)(id, SEL) = (id(*)(id, SEL))[self methodForSelector: selector]; @@ -556,23 +558,26 @@ - (const char*)typeEncodingForSelector: (SEL)selector { #if defined(OF_OBJFW_RUNTIME) const char *ret; - if ((ret = objc_get_type_encoding(isa, selector)) == NULL) - @throw [OFNotImplementedException exceptionWithClass: isa - selector: selector]; + if ((ret = objc_get_type_encoding(object_getClass(self), + selector)) == NULL) + @throw [OFNotImplementedException + exceptionWithClass: [self class] + selector: selector]; return ret; #else Method m; const char *ret; - if ((m = class_getInstanceMethod(isa, selector)) == NULL || - (ret = method_getTypeEncoding(m)) == NULL) - @throw [OFNotImplementedException exceptionWithClass: isa - selector: selector]; + if ((m = class_getInstanceMethod(object_getClass(self), + selector)) == NULL || (ret = method_getTypeEncoding(m)) == NULL) + @throw [OFNotImplementedException + exceptionWithClass: [self class] + selector: selector]; return ret; #endif } @@ -598,14 +603,14 @@ { void *pointer; struct pre_mem *preMem; if (size > SIZE_MAX - PRE_IVAR_ALIGN) - @throw [OFOutOfRangeException exceptionWithClass: isa]; + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; if ((pointer = malloc(PRE_MEM_ALIGN + size)) == NULL) - @throw [OFOutOfMemoryException exceptionWithClass: isa + @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: size]; preMem = pointer; preMem->owner = self; preMem->prev = PRE_IVAR->lastMem; @@ -624,11 +629,11 @@ { if (size == 0 || count == 0) return NULL; if (count > SIZE_MAX / size) - @throw [OFOutOfRangeException exceptionWithClass: isa]; + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return [self allocMemoryWithSize: size * count]; } - (void*)resizeMemory: (void*)pointer @@ -645,15 +650,15 @@ return NULL; } if (PRE_MEM(pointer)->owner != self) @throw [OFMemoryNotPartOfObjectException - exceptionWithClass: isa + exceptionWithClass: [self class] pointer: pointer]; if ((new = realloc(PRE_MEM(pointer), PRE_MEM_ALIGN + size)) == NULL) - @throw [OFOutOfMemoryException exceptionWithClass: isa + @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: size]; preMem = new; if (preMem != PRE_MEM(pointer)) { if (preMem->prev != NULL) @@ -682,11 +687,11 @@ [self freeMemory: pointer]; return NULL; } if (count > SIZE_MAX / size) - @throw [OFOutOfRangeException exceptionWithClass: isa]; + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return [self resizeMemory: pointer size: size * count]; } @@ -695,11 +700,11 @@ if (pointer == NULL) return; if (PRE_MEM(pointer)->owner != self) @throw [OFMemoryNotPartOfObjectException - exceptionWithClass: isa + exceptionWithClass: [self class] pointer: pointer]; if (PRE_MEM(pointer)->prev != NULL) PRE_MEM(pointer)->prev->next = PRE_MEM(pointer)->next; if (PRE_MEM(pointer)->next != NULL) @@ -785,11 +790,12 @@ { Class class; void (*last)(id, SEL) = NULL; struct pre_mem *iter; - for (class = isa; class != Nil; class = class_getSuperclass(class)) { + for (class = object_getClass(self); class != Nil; + class = class_getSuperclass(class)) { void (*destruct)(id, SEL); if ([class instancesRespondToSelector: cxx_destruct]) { if ((destruct = (void(*)(id, SEL))[class instanceMethodForSelector: cxx_destruct]) != last) @@ -821,21 +827,23 @@ /* Required to use properties with the Apple runtime */ - copyWithZone: (void*)zone { if (zone != NULL) - @throw [OFNotImplementedException exceptionWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException + exceptionWithClass: [self class] + selector: _cmd]; return [(id)self copy]; } - mutableCopyWithZone: (void*)zone { if (zone != NULL) - @throw [OFNotImplementedException exceptionWithClass: isa - selector: _cmd]; + @throw [OFNotImplementedException + exceptionWithClass: [self class] + selector: _cmd]; return [(id)self mutableCopy]; } /*