From patchwork Sun Dec 19 14:01:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: =?UTF-8?Q?libobjc:=20header=20cleanup=20for=20new=20API=20(8)?= From: Nicola Pero X-Patchwork-Id: 76128 Message-Id: <1292767314.029325883@192.168.2.227> To: "gcc-patches@gnu.org" Date: Sun, 19 Dec 2010 15:01:54 +0100 (CET) > It also avoids having objc/objc.h include objc/message.h directly. This had been done to > provide the deprecated objc_msg_sendv() declarations (which was in objc/message.h before > this patch) for the old API, but had the side effect of always defining struct objc_super > in the old API way even if the new API is in use. :-( This patch completes the previous one (number 4) and adds a testcase to make sure "struct objc_super" is now declared in the right way in the new API (ie, that the fix in patch #4 worked). Since I was writing a testcase, and I'm trying to make sure all functions in the new API have a testcase each, I also added tests of objc_msg_lookup() and objc_msg_lookup_super(). Committed. Thanks Index: ChangeLog =================================================================== --- ChangeLog (revision 168051) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-12-19 Nicola Pero + + * objc.dg/gnu-api-2-objc_msg_lookup.m: New. + * obj-c++.dg/gnu-api-2-objc_msg_lookup.mm: New. + 2010-12-19 Chung-Lin Tang * gcc.target/arm/vfp-1.c (test_ldst): New test for VFP Index: objc.dg/gnu-api-2-objc_msg_lookup.m =================================================================== --- objc.dg/gnu-api-2-objc_msg_lookup.m (revision 0) +++ objc.dg/gnu-api-2-objc_msg_lookup.m (revision 0) @@ -0,0 +1,77 @@ +/* Test the Modern GNU Objective-C Runtime API. + + This is test 'objc_msg_lookup', covering objc_msg_lookup(), + objc_msg_lookup_super() and struct objc_super. */ + +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include + +/* For objc_msg_lookup(), objc_msg_lookup_super() and struct + objc_super. */ +#include + +#include +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; +- (int) test; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } +- (int) test { return 20; } +@end + +@interface MySubClass : MyRootClass +- (int) test; +@end + +@implementation MySubClass +- (int) test { return 11; } +@end + +int main (int argc, void **args) +{ + /* Functions are tested in alphabetical order. */ + + printf ("Testing objc_msg_lookup ()...\n"); + { + MySubClass *object = [[MySubClass alloc] init]; + int (* test_IMP) (id receiver, SEL selector); + + test_IMP = (int (*)(id, SEL))objc_msg_lookup (object, @selector (test)); + + if (test_IMP (object, @selector (test)) != 11) + abort (); + } + + printf ("Testing objc_msg_lookup_super ()...\n"); + { + MySubClass *object = [[MySubClass alloc] init]; + struct objc_super super = { 0, 0 }; + int (* test_IMP) (id receiver, SEL selector); + + /* Get the implementation of -test for the superclass of object - + as if we were calling [super test] inside a method + implementation of object. */ + super.self = object; + super.super_class = class_getSuperclass (object_getClass (object)); + test_IMP = (int (*)(id, SEL))objc_msg_lookup_super (&super, @selector (test)); + + /* Invoke it. The method in MyRootClass, not the one in + MySubClass, should be invoked. */ + if (test_IMP (object, @selector (test)) != 20) + abort (); + } + + return 0; +} Index: obj-c++.dg/gnu-api-2-objc_msg_lookup.mm =================================================================== --- obj-c++.dg/gnu-api-2-objc_msg_lookup.mm (revision 0) +++ obj-c++.dg/gnu-api-2-objc_msg_lookup.mm (revision 0) @@ -0,0 +1,77 @@ +/* Test the Modern GNU Objective-C Runtime API. + + This is test 'objc_msg_lookup', covering objc_msg_lookup(), + objc_msg_lookup_super() and struct objc_super. */ + +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include + +/* For objc_msg_lookup(), objc_msg_lookup_super() and struct + objc_super. */ +#include + +#include +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; +- (int) test; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } +- (int) test { return 20; } +@end + +@interface MySubClass : MyRootClass +- (int) test; +@end + +@implementation MySubClass +- (int) test { return 11; } +@end + +int main () +{ + /* Functions are tested in alphabetical order. */ + + std::cout << "Testing objc_msg_lookup () ...\n"; + { + MySubClass *object = [[MySubClass alloc] init]; + int (* test_IMP) (id receiver, SEL selector); + + test_IMP = (int (*)(id, SEL))objc_msg_lookup (object, @selector (test)); + + if (test_IMP (object, @selector (test)) != 11) + abort (); + } + + std::cout << "Testing objc_msg_lookup_super () ...\n"; + { + MySubClass *object = [[MySubClass alloc] init]; + struct objc_super super = { 0, 0 }; + int (* test_IMP) (id receiver, SEL selector); + + /* Get the implementation of -test for the superclass of object - + as if we were calling [super test] inside a method + implementation of object. */ + super.self = object; + super.super_class = class_getSuperclass (object_getClass (object)); + test_IMP = (int (*)(id, SEL))objc_msg_lookup_super (&super, @selector (test)); + + /* Invoke it. The method in MyRootClass, not the one in + MySubClass, should be invoked. */ + if (test_IMP (object, @selector (test)) != 20) + abort (); + } + + return (0); +}