diff --git a/objc/runtime.h b/objc/runtime.h index de63aa8..5282066 100644 --- a/objc/runtime.h +++ b/objc/runtime.h @@ -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. diff --git a/protocol.c b/protocol.c index f8bfbd5..c889e02 100644 --- a/protocol.c +++ b/protocol.c @@ -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; +} +