Implemented objc_copyProtocolList().

This commit is contained in:
theraven 2011-04-28 18:53:11 +00:00
parent 79b67ad044
commit c6f0651609
2 changed files with 29 additions and 0 deletions

View File

@ -600,6 +600,15 @@ objc_property_t *protocol_copyPropertyList(Protocol *p, unsigned int *count);
*/
Protocol **protocol_copyProtocolList(Protocol *p, unsigned int *count);
/**
* Returns all of the protocols that the runtime is aware of. Note that
* protocols compiled by GCC and not attacked to classes may not have been
* registered with the runtime. The number of protocols returned is stored at
* the address indicated by the pointer argument.
*
* The caller is responsible for freeing the returned array.
*/
Protocol **objc_copyProtocolList(unsigned int *outCount);
/**
* Returns the method description for the specified method within a given
* protocol.

View File

@ -474,3 +474,23 @@ BOOL protocol_isEqual(Protocol *p, Protocol *other)
return NO;
}
Protocol **objc_copyProtocolList(unsigned int *outCount)
{
unsigned int total = known_protocol_table->table_used;
Protocol **p = calloc(sizeof(Protocol*), known_protocol_table->table_used);
struct protocol_table_enumerator *e = NULL;
Protocol *next;
unsigned int count = 0;
while ((count < total) && (next = protocol_next(known_protocol_table, &e)))
{
p[count++] = next;
}
if (NULL != outCount)
{
*outCount = total;
}
return p;
}