From 8058495e3974c1b8339537aee8bf620e16759bf9 Mon Sep 17 00:00:00 2001 From: theraven Date: Mon, 25 Jan 2010 23:34:00 +0000 Subject: [PATCH] Fix crash with gcc-compiled protocols. --- protocol.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- runtime.c | 41 ----------------------------------------- 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/protocol.c b/protocol.c index 71c0d80..671dcfa 100644 --- a/protocol.c +++ b/protocol.c @@ -48,9 +48,13 @@ static Class ObjC2ProtocolClass = 0; static int isEmptyProtocol(struct objc_protocol2 *aProto) { - int isEmpty = (aProto->instance_methods->count == 0) && - (aProto->class_methods->count == 0) && - (aProto->protocol_list->count == 0); + int isEmpty = + ((aProto->instance_methods == NULL) || + (aProto->instance_methods->count == 0)) && + ((aProto->class_methods == NULL) || + (aProto->class_methods->count == 0)) && + ((aProto->protocol_list == NULL) || + (aProto->protocol_list->count == 0)); if (aProto->class_pointer == ObjC2ProtocolClass) { struct objc_protocol2 *p2 = (struct objc_protocol2*)aProto; @@ -132,3 +136,47 @@ Protocol *objc_getProtocol(const char *name) { return (Protocol*)protocol_for_name(name); } + +BOOL protocol_conformsToProtocol(Protocol *p, Protocol *other) +{ + + return NO; +} + +struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p, + BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count) +{ + *count = 0; + return NULL; +} + +Protocol **protocol_copyProtocolList(Protocol *p, unsigned int *count) +{ + *count = 0; + return NULL; +} + +const char *protocol_getName(Protocol *p) +{ + if (NULL != p) + { + return p->protocol_name; + } + return NULL; +} + +BOOL protocol_isEqual(Protocol *p, Protocol *other) +{ + if (NULL == p || NULL == other) + { + return NO; + } + if (p == other || + p->protocol_name == other->protocol_name || + 0 == strcmp(p->protocol_name, other->protocol_name)) + { + return YES; + } + return NO; +} + diff --git a/runtime.c b/runtime.c index ec9b214..c05c5a2 100644 --- a/runtime.c +++ b/runtime.c @@ -826,47 +826,6 @@ static id objectNew(id cls) return newIMP((id)cls, newSel); } -BOOL protocol_conformsToProtocol(Protocol *p, Protocol *other) -{ - return NO; -} - -struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p, - BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count) -{ - *count = 0; - return NULL; -} - -Protocol **protocol_copyProtocolList(Protocol *p, unsigned int *count) -{ - *count = 0; - return NULL; -} - -const char *protocol_getName(Protocol *p) -{ - if (NULL != p) - { - return p->protocol_name; - } - return NULL; -} - -BOOL protocol_isEqual(Protocol *p, Protocol *other) -{ - if (NULL == p || NULL == other) - { - return NO; - } - if (p == other || - 0 == strcmp(p->protocol_name, other->protocol_name)) - { - return YES; - } - return NO; -} - const char *sel_getName(SEL sel) { return sel_get_name(sel);