mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 18:21:04 +00:00
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:
parent
42e39c0df8
commit
b4c1a94377
2 changed files with 30 additions and 62 deletions
|
@ -652,63 +652,6 @@ gs_string_hash(const char *s)
|
||||||
return val;
|
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_HAS_VALUE 1
|
||||||
#define GSI_MAP_RETAIN_KEY(M, X)
|
#define GSI_MAP_RETAIN_KEY(M, X)
|
||||||
#define GSI_MAP_RETAIN_VAL(M, X)
|
#define GSI_MAP_RETAIN_VAL(M, X)
|
||||||
|
@ -794,7 +737,7 @@ GSProtocolFromName(const char *name)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p = gs_find_protocol_named(name);
|
p = objc_getProtocol(name);
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
/* Use the protocol's name to save us from allocating
|
/* Use the protocol's name to save us from allocating
|
||||||
|
|
|
@ -994,6 +994,7 @@ objc_registerClassPair(Class cls)
|
||||||
__objc_resolve_class_links();
|
__objc_resolve_class_links();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static id
|
static id
|
||||||
objectNew(id cls)
|
objectNew(id cls)
|
||||||
{
|
{
|
||||||
|
@ -1007,15 +1008,39 @@ objectNew(id cls)
|
||||||
newIMP = (IMP) objc_msg_lookup((void *) cls, newSel);
|
newIMP = (IMP) objc_msg_lookup((void *) cls, newSel);
|
||||||
return newIMP((id) cls, newSel);
|
return newIMP((id) cls, newSel);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
Protocol *
|
Protocol *
|
||||||
objc_getProtocol(const char *name)
|
objc_getProtocol(const char *name)
|
||||||
{
|
{
|
||||||
// Protocols are not centrally registered in the GNU runtime.
|
Protocol *p = NULL;
|
||||||
Protocol *protocol = (Protocol *) (objectNew(objc_getClass("Protocol")));
|
Class cls;
|
||||||
|
void *iterator = NULL;
|
||||||
|
|
||||||
protocol->protocol_name = (char *) name;
|
/* Protocols are not centrally registered in the GNU runtime.
|
||||||
return protocol;
|
* 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
|
BOOL
|
||||||
|
|
Loading…
Reference in a new issue