use objc_getProtocol

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29841 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-03-05 05:44:39 +00:00
parent ef908fbb5b
commit acf69942e9
2 changed files with 30 additions and 62 deletions

View file

@ -652,63 +652,6 @@ gs_string_hash(const char *s)
return val;
}
static inline Protocol *
gs_find_protocol_named_in_protocol_list(const char *name,
struct objc_protocol_list *pcllist)
{
Protocol *p = NULL;
size_t i;
while (pcllist != NULL)
{
for (i = 0; i < pcllist->count; i++)
{
p = (Protocol*)pcllist->list[i];
if (strcmp([p name], name) == 0)
{
return p;
}
}
pcllist = pcllist->next;
}
return NULL;
}
static inline Protocol *
gs_find_protocol_named(const char *name)
{
Protocol *p = NULL;
Class cls;
#ifdef NeXT_RUNTIME
Class *clsList, *clsListStart;
unsigned int num;
/* Setting the clearCache flag is a noop for the Apple runtime. */
num = GSClassList(NULL, 0, NO);
clsList = malloc(sizeof(Class) * (num + 1));
GSClassList(clsList, num, NO);
clsListStart = clsList;
while (p == NULL && (cls = *clsList++))
{
p = gs_find_protocol_named_in_protocol_list(name, cls->protocols);
}
free(clsListStart);
#else
void *iterator = NULL;
while (p == NULL && (cls = objc_next_class(&iterator)))
{
p = gs_find_protocol_named_in_protocol_list(name, cls->protocols);
}
#endif
return p;
}
#define GSI_MAP_HAS_VALUE 1
#define GSI_MAP_RETAIN_KEY(M, X)
#define GSI_MAP_RETAIN_VAL(M, X)
@ -794,7 +737,7 @@ GSProtocolFromName(const char *name)
}
else
{
p = gs_find_protocol_named(name);
p = objc_getProtocol(name);
if (p)
{
/* Use the protocol's name to save us from allocating

View file

@ -994,6 +994,7 @@ objc_registerClassPair(Class cls)
__objc_resolve_class_links();
}
/*
static id
objectNew(id cls)
{
@ -1007,15 +1008,39 @@ objectNew(id cls)
newIMP = (IMP) objc_msg_lookup((void *) cls, newSel);
return newIMP((id) cls, newSel);
}
*/
Protocol *
objc_getProtocol(const char *name)
{
// Protocols are not centrally registered in the GNU runtime.
Protocol *protocol = (Protocol *) (objectNew(objc_getClass("Protocol")));
Protocol *p = NULL;
Class cls;
void *iterator = NULL;
protocol->protocol_name = (char *) name;
return protocol;
/* Protocols are not centrally registered in the GNU runtime.
* So we just find the first match we can.
*/
while (p == NULL && (cls = objc_next_class(&iterator)))
{
struct objc_protocol_list *pcllist = cls->protocols;
size_t i;
while (pcllist != NULL)
{
for (i = 0; i < pcllist->count; i++)
{
if (strcmp(pcllist->list[i]->protocol_name, name) == 0)
{
p = (Protocol*)pcllist->list[i];
break;
}
}
pcllist = pcllist->next;
}
}
return p;
}
BOOL