From 877bf1953af3383597ad4f76971539e5e05c6d31 Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Fri, 24 Dec 2010 15:32:25 +0000 Subject: [PATCH] In libobjc/: 2010-12-24 Nicola Pero In libobjc/: 2010-12-24 Nicola Pero * objc/runtime.h (class_conformsToProtocol, class_copyProtocolList): Updated documentation. In gcc/testsuite/: 2010-12-24 Nicola Pero * obj-c.dg/gnu-api-2-class.m: Test that class_conformsToProtocol() does not check the superclasses. * obj-c++.dg/gnu-api-2-class.mm: Same change. From-SVN: r168226 --- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm | 11 +++++++++++ gcc/testsuite/objc.dg/gnu-api-2-class.m | 11 +++++++++++ libobjc/ChangeLog | 5 +++++ libobjc/objc/runtime.h | 10 ++++++++-- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2cc045ba7e20..1324aeb83b80 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-12-24 Nicola Pero + + * obj-c.dg/gnu-api-2-class.m: Test that class_conformsToProtocol() + does not check the superclasses. + * obj-c++.dg/gnu-api-2-class.mm: Same change. + 2010-12-24 Alexander Monakov PR rtl-optimization/47036 diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm index da25663d171d..b86396f2144a 100644 --- a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm +++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm @@ -42,6 +42,12 @@ - (id) variable { return variable_ivar; } @end +@interface MyOtherSubClass : MySubClass +@end + +@implementation MyOtherSubClass +@end + @interface DifferentClass : MyRootClass - (id) myClass; - (id) self; @@ -188,6 +194,11 @@ int main () if (!class_conformsToProtocol (objc_getClass ("MySubClass"), @protocol (MyProtocol))) abort (); + + /* Test that class_conformsToProtocol checks the class, but not + superclasses. */ + if (class_conformsToProtocol (objc_getClass ("MyOtherSubClass"), @protocol (MyProtocol))) + abort (); } std::cout << "Testing class_copyIvarList ()...\n"; diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class.m b/gcc/testsuite/objc.dg/gnu-api-2-class.m index d38d9c253dc3..ff0425966cdc 100644 --- a/gcc/testsuite/objc.dg/gnu-api-2-class.m +++ b/gcc/testsuite/objc.dg/gnu-api-2-class.m @@ -42,6 +42,12 @@ - (id) variable { return variable_ivar; } @end +@interface MyOtherSubClass : MySubClass +@end + +@implementation MyOtherSubClass +@end + @interface DifferentClass : MyRootClass - (id) myClass; - (id) self; @@ -188,6 +194,11 @@ int main(int argc, void **args) if (!class_conformsToProtocol (objc_getClass ("MySubClass"), @protocol (MyProtocol))) abort (); + + /* Test that class_conformsToProtocol checks the class, but not + superclasses. */ + if (class_conformsToProtocol (objc_getClass ("MyOtherSubClass"), @protocol (MyProtocol))) + abort (); } printf ("Testing class_copyIvarList ()...\n"); diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index fbeaf3fa5716..78112bdecfe1 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,3 +1,8 @@ +2010-12-24 Nicola Pero + + * objc/runtime.h (class_conformsToProtocol, + class_copyProtocolList): Updated documentation. + 2010-12-23 Nicola Pero * init.c (create_tree_of_subclasses_inherited_from): Updated diff --git a/libobjc/objc/runtime.h b/libobjc/objc/runtime.h index 8d380156e41c..7ad46dcc6fd0 100644 --- a/libobjc/objc/runtime.h +++ b/libobjc/objc/runtime.h @@ -768,7 +768,11 @@ objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProt objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol); /* Return YES if the class 'class_' conforms to Protocol 'protocol', - and NO if not. */ + and NO if not. This function does not check superclasses; if you + want to check for superclasses (in the way that [NSObject + +conformsToProtocol:] does) you need to iterate over the class + hierarchy using class_getSuperclass(), and call + class_conformsToProtocol() for each of them. */ objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol); /* Return all the protocols that the class conforms to. The return @@ -777,7 +781,9 @@ objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol); class. It does not include protocols adopted by superclasses. The list is terminated by NULL. Optionally, if you pass a non-NULL 'numberOfReturnedProtocols' pointer, the unsigned int that it - points to will be filled with the number of protocols returned. */ + points to will be filled with the number of protocols returned. + This function does not return protocols that superclasses conform + to. */ objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols); /* Return YES if protocol 'protocol' conforms to protocol -- 2.47.2