From: "Nicola Pero" <nicola.pero@meta-innovation.com>
To: "gcc-patches@gnu.org" <gcc-patches@gnu.org>
Subject: libobjc: header cleanup for new API (8)
Date: Sun, 19 Dec 2010 14:13:00 -0000 [thread overview]
Message-ID: <1292767314.029325883@192.168.2.227> (raw)
In-Reply-To: <1292722172.353524519@192.168.2.229>
> 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 <nicola.pero@meta-innovation.com>
+
+ * 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 <cltang@codesourcery.com>
* 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 <objc/runtime.h>
+
+/* For objc_msg_lookup(), objc_msg_lookup_super() and struct
+ objc_super. */
+#include <objc/message.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+@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 <objc/runtime.h>
+
+/* For objc_msg_lookup(), objc_msg_lookup_super() and struct
+ objc_super. */
+#include <objc/message.h>
+
+#include <stdlib.h>
+#include <iostream>
+#include <cstring>
+
+@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);
+}
prev parent reply other threads:[~2010-12-19 14:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-19 7:39 libobjc: header cleanup for new API (4) Nicola Pero
2010-12-19 14:13 ` Nicola Pero [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292767314.029325883@192.168.2.227 \
--to=nicola.pero@meta-innovation.com \
--cc=gcc-patches@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).