1 // TEST_CFLAGS -framework Foundation
2 // need Foundation to get NSObject compatibility additions for class Protocol
3 // because ARC calls [protocol retain]
6 .*protocolSmall.m:\d+:\d+: warning: cannot find protocol definition for 'SmallProto'
7 .*protocolSmall.m:\d+:\d+: note: protocol 'SmallProto' has no definition
13 #include <objc/runtime.h>
15 struct MethodListOneEntry {
16 uint32_t entSizeAndFlags;
23 struct SmallProtoStructure {
25 const char *mangledName;
26 struct protocol_list_t *protocols;
27 void *instanceMethods;
29 void *optionalInstanceMethods;
30 void *optionalClassMethods;
31 void *instanceProperties;
32 uint32_t size; // sizeof(protocol_t)
36 struct MethodListOneEntry SmallProtoMethodList = {
37 .entSizeAndFlags = 3 * sizeof(void *),
44 struct SmallProtoStructure SmallProtoData
45 __asm__("__OBJC_PROTOCOL_$_SmallProto")
47 .mangledName = "SmallProto",
48 .instanceMethods = &SmallProtoMethodList,
49 .size = sizeof(struct SmallProtoStructure),
52 void *SmallProtoListEntry
53 __attribute__((section("__DATA,__objc_protolist,coalesced,no_dead_strip")))
61 @interface C: TestRoot <SmallProto, NormalProto> @end
63 - (void)protoMethod {}
68 // Fix up the method list selector by hand, getting the compiler to generate a
69 // proper selref as a compile-time constant is a pain.
70 SmallProtoMethodList.name = @selector(protoMethod);
73 Protocol * __unsafe_unretained *protos = class_copyProtocolList([C class], &protoCount);
74 for (unsigned i = 0; i < protoCount; i++) {
75 testprintf("Checking index %u protocol %p\n", i, protos[i]);
76 const char *name = protocol_getName(protos[i]);
77 testprintf("Name is %s\n", name);
78 testassert(strcmp(name, "SmallProto") == 0 || strcmp(name, "NormalProto") == 0);
80 objc_property_t *classProperties = protocol_copyPropertyList2(protos[i], NULL, YES, NO);
81 testassert(classProperties == NULL);
83 struct objc_method_description desc = protocol_getMethodDescription(protos[i], @selector(protoMethod), YES, YES);
84 testprintf("Protocol protoMethod name is %s types are %s\n", desc.name, desc.types);
85 testassert(desc.name == @selector(protoMethod));
86 testassert(desc.types[0] == 'v');