From patchwork Sun Dec 19 14:01:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 03175B6EF2 for ; Mon, 20 Dec 2010 01:02:06 +1100 (EST) Received: (qmail 15372 invoked by alias); 19 Dec 2010 14:02:04 -0000 Received: (qmail 15363 invoked by uid 22791); 19 Dec 2010 14:02:03 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 19 Dec 2010 14:01:59 +0000 Received: from eggs.gnu.org ([140.186.70.92]:60226) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PUJpi-00031U-Hg for gcc-patches@gnu.org; Sun, 19 Dec 2010 09:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PUJpj-0003AC-8w for gcc-patches@gnu.org; Sun, 19 Dec 2010 09:01:57 -0500 Received: from smtp131.iad.emailsrvr.com ([207.97.245.131]:53110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PUJpj-00039x-42 for gcc-patches@gnu.org; Sun, 19 Dec 2010 09:01:55 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 4C4D02D0409 for ; Sun, 19 Dec 2010 09:01:54 -0500 (EST) Received: from dynamic6.wm-web.iad.mlsrvr.com (dynamic6.wm-web.iad1a.rsapps.net [192.168.2.147]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 3B2742D02C3 for ; Sun, 19 Dec 2010 09:01:54 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic6.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 0804A3F0054 for ; Sun, 19 Dec 2010 09:01:54 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sun, 19 Dec 2010 15:01:54 +0100 (CET) Date: Sun, 19 Dec 2010 15:01:54 +0100 (CET) Subject: =?UTF-8?Q?libobjc:=20header=20cleanup=20for=20new=20API=20(8)?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain In-Reply-To: <1292722172.353524519@192.168.2.229> References: <1292722172.353524519@192.168.2.229> Message-ID: <1292767314.029325883@192.168.2.227> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org > 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); +}