@@ -576,28 +576,40 @@ } bool class_isMetaClass(Class cls) { + if (cls == Nil) + return false; + return (cls->info & OBJC_CLASS_INFO_METACLASS); } const char* class_getName(Class cls) { + if (cls == Nil) + return ""; + return cls->name; } Class class_getSuperclass(Class cls) { + if (cls == Nil) + return nil; + return cls->superclass; } unsigned long class_getInstanceSize(Class cls) { + if (cls == Nil) + return 0; + return cls->instance_size; } IMP class_getMethodImplementation(Class cls, SEL sel) @@ -610,15 +622,18 @@ * Just looking it up in the dispatch table could result in returning * NULL instead of the forwarding handler, it would also mean * +[resolveClassMethod:] / +[resolveInstanceMethod:] would not be * called. */ - struct { Class isa; - } dummy = { cls }; + } dummy; + + if (cls == Nil) + return NULL; + dummy.isa = cls; return objc_msg_lookup((id)&dummy, sel); } IMP class_getMethodImplementation_stret(Class cls, SEL sel) @@ -625,24 +640,30 @@ { /* * Same as above, but use objc_msg_lookup_stret instead, so that the * correct forwarding handler is returned. */ - struct { Class isa; - } dummy = { cls }; + } dummy; + + if (cls == Nil) + return NULL; + dummy.isa = cls; return objc_msg_lookup_stret((id)&dummy, sel); } const char* class_getMethodTypeEncoding(Class cls, SEL sel) { struct objc_method_list *ml; struct objc_category **cats; unsigned int i; + + if (cls == Nil) + return NULL; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { @@ -749,31 +770,41 @@ } Class object_getClass(id obj_) { - struct objc_object *obj = (struct objc_object*)obj_; + struct objc_object *obj; + + if (obj_ == nil) + return Nil; + + obj = (struct objc_object*)obj_; return obj->isa; } Class object_setClass(id obj_, Class cls) { - struct objc_object *obj = (struct objc_object*)obj_; + struct objc_object *obj; Class old; + if (obj_ == nil) + return Nil; + + obj = (struct objc_object*)obj_; + old = obj->isa; obj->isa = cls; return old; } const char* object_getClassName(id obj) { - return object_getClass(obj)->name; + return class_getName(object_getClass(obj)); } static void unregister_class(Class rcls) {