From patchwork Tue Jan 11 10:25:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 78309 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 7037FB70A3 for ; Tue, 11 Jan 2011 21:26:14 +1100 (EST) Received: (qmail 29524 invoked by alias); 11 Jan 2011 10:26:12 -0000 Received: (qmail 29501 invoked by uid 22791); 11 Jan 2011 10:26:05 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_NONE, TW_BJ, TW_CP X-Spam-Check-By: sourceware.org Received: from c2bthomr13.btconnect.com (HELO mail.btconnect.com) (213.123.20.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Jan 2011 10:25:55 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2bthomr13.btconnect.com with ESMTP id BGX49335; Tue, 11 Jan 2011 10:25:46 +0000 (GMT) Message-Id: <58D5D7B4-490F-4872-8936-979027F96BCE@sandoe-acoustics.co.uk> From: IainS To: GCC Patches Mime-Version: 1.0 (Apple Message framework v936) Subject: [Patch, ObjC/NeXT/Testsuite, committed] complete split of next-mapping.h Date: Tue, 11 Jan 2011 10:25:25 +0000 Cc: Mike Stump , Nicola Pero X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0302.4D2C3015.0258, actions=tag X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B020A.4D2C3030.008D, ss=1, fgs=0, ip=0.0.0.0, so=2010-07-22 22:03:31, dmn=2009-09-10 00:05:08, mode=single engine 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 This completes the splitting of next-mapping into areas of distinct functionality. so now in objc-objc++-shared we have. next-mapping.h (probably would be better named 'api-mapping.h' since, I'm sure we'll end up using it for GNU too). maps function and structure offset names between the APIs. objc-test-suite-types.h : abstracts data types that differ between APIs/ABIs. nsconstantstring-class* : provides a stand-alone constant string class (the header should be used for NeXT wherever you'd include for GNU) objc-test-suite-next-encode-assist* : provide emulation of some functions only available in the GNU runtime (probably about to be retired in 4.7) checked on x86_64-linux, x86_64-darwin10, i686-darwin9, i686-darwin8. Applied as r168653 cheers, Iain. gcc/testsuite: * objc-obj-c++-shared/next-mapping.h: Add copyright header. Split type definitions and NSConstantString class into... * objc-obj-c++-shared/objc-test-suite-types.h: New. * objc-obj-c++-shared/nsconstantstring-class.h: New. * objc-obj-c++-shared/nsconstantstring-class-impl.h: New. * objc-obj-c++-shared/nsconstantstring-class-impl.m: New. * objc-obj-c++-shared/nsconstantstring-class-impl.mm: New. * objc-obj-c++-shared/next-abi.h: Add copyright header, minor update to comments. * objc-obj-c++-shared/objc-test-suite-next-encode-assist.h: Adjust encode defines for newer NeXT system headers. * obj-c++.dg/template-4.mm: Adjust to use nsconstantstring headers. * obj-c++.dg/torture/strings/string1.mm: Likewise. * objc.dg/foreach-5.m: Likewise. * objc.dg/foreach-2.m: Likewise. * objc.dg/foreach-4.m: Likewise. * objc.dg/torture/strings/string1.m: Likewise. * objc.dg/torture/strings/string2.m: Likewise. * objc.dg/torture/strings/string3.m: Likewise. * objc.dg/torture/strings/string4.m: Likewise. * obj-c++.dg/torture/strings/const-str-3.mm: Adjust to use type header and stand alone. * obj-c++.dg/strings/strings-2.mm: Likewise. * objc.dg/torture/strings/const-str-3.m: Likewise. * objc.dg/strings/strings-2.m: Likewise. * objc.dg/strings/const-str-12b.m: Likewise. Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 168652) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,32 @@ +2011-01-11 Iain Sandoe + + * objc-obj-c++-shared/next-mapping.h: Add copyright header. + Split type definitions and NSConstantString class into... + * objc-obj-c++-shared/objc-test-suite-types.h: New. + * objc-obj-c++-shared/nsconstantstring-class.h: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.h: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.m: New. + * objc-obj-c++-shared/nsconstantstring-class-impl.mm: New. + * objc-obj-c++-shared/next-abi.h: Add copyright header, minor update + to comments. + * objc-obj-c++-shared/objc-test-suite-next-encode-assist.h: Adjust + encode defines for newer NeXT system headers. + * obj-c++.dg/template-4.mm: Adjust to use nsconstantstring headers. + * obj-c++.dg/torture/strings/string1.mm: Likewise. + * objc.dg/foreach-5.m: Likewise. + * objc.dg/foreach-2.m: Likewise. + * objc.dg/foreach-4.m: Likewise. + * objc.dg/torture/strings/string1.m: Likewise. + * objc.dg/torture/strings/string2.m: Likewise. + * objc.dg/torture/strings/string3.m: Likewise. + * objc.dg/torture/strings/string4.m: Likewise. + * obj-c++.dg/torture/strings/const-str-3.mm: Adjust to use type + header and stand alone. + * obj-c++.dg/strings/strings-2.mm: Likewise. + * objc.dg/torture/strings/const-str-3.m: Likewise. + * objc.dg/strings/strings-2.m: Likewise. + * objc.dg/strings/const-str-12b.m: Likewise. + 2011-01-12 Richard Guenther PR middle-end/32511 Index: gcc/testsuite/obj-c++.dg/template-4.mm =================================================================== --- gcc/testsuite/obj-c++.dg/template-4.mm (revision 168652) +++ gcc/testsuite/obj-c++.dg/template-4.mm (working copy) @@ -3,17 +3,21 @@ /* { dg-do run } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ -/* { dg-additional-sources "../objc-obj-c++-shared/Object1.mm" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.mm ../objc-obj-c++-shared/nsconstantstring-class-impl.mm" } */ -#include "../objc-obj-c++-shared/Object1.h" -#include "../objc-obj-c++-shared/next-mapping.h" #include #include +#include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif +#include "../objc-obj-c++-shared/Object1.h" +#include "../objc-obj-c++-shared/next-mapping.h" + #define CHECK_IF(expr) if(!(expr)) abort() template class TestT Index: gcc/testsuite/obj-c++.dg/torture/strings/string1.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/string1.mm (revision 168652) +++ gcc/testsuite/obj-c++.dg/torture/strings/string1.mm (working copy) @@ -3,7 +3,7 @@ /* { dg-do run } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm ../../../objc-obj-c++-shared/nsconstantstring-class-impl.mm" } */ #include "../../../objc-obj-c++-shared/Object1.h" #include "../../../objc-obj-c++-shared/next-mapping.h" @@ -13,6 +13,8 @@ #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, char **args) Index: gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm =================================================================== --- gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm (revision 168652) +++ gcc/testsuite/obj-c++.dg/torture/strings/const-str-3.mm (working copy) @@ -6,32 +6,26 @@ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.mm" } */ -#import "../../../objc-obj-c++-shared/Object1.h" -#import "../../../objc-obj-c++-shared/next-mapping.h" +#include "../../../objc-obj-c++-shared/objc-test-suite-types.h" + #include #include -#include -#include -#ifndef __NEXT_RUNTIME__ -#include -#endif +#include -@interface Foo: Object { +@interface Foo { + void *dummy_class_ref; char *cString; unsigned int len; } ++ initialize; - (char *)customString; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ -@implementation Foo : Object +@implementation Foo ++ initialize {return self;} - (char *)customString { return cString; } @@ -45,11 +39,14 @@ int main () { abort(); printf("Strings are being uniqued properly\n"); +#ifdef __NEXT_RUNTIME__ /* This memcpy has to be done before the first message is sent to a constant string object. Can't be moved to +initialize since _that_ is already a message. */ - memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference)); + memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); +#endif + if (strcmp ([string customString], "bla")) { abort (); } Index: gcc/testsuite/obj-c++.dg/strings/strings-2.mm =================================================================== --- gcc/testsuite/obj-c++.dg/strings/strings-2.mm (revision 168652) +++ gcc/testsuite/obj-c++.dg/strings/strings-2.mm (working copy) @@ -5,24 +5,24 @@ /* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ -/* { dg-additional-sources "../../objc-obj-c++-shared/Object1.mm" } */ +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" -#include "../../objc-obj-c++-shared/Object1.h" -#include "../../objc-obj-c++-shared/next-mapping.h" - #include /* For abort() */ -@interface MyTestString : Object +@interface MyTestString { + void *dummy_class_ptr; char *string; unsigned int len; } ++ initialize; /* All strings should contain the C string 'test'. Call -check to test that this is true. */ - (void) check; @end @implementation MyTestString ++ initialize {return self;} - (void) check { if (len != 4 || string[0] != 't' || string[1] != 'e' @@ -31,13 +31,7 @@ } @end -#ifdef __NEXT_RUNTIME__ -# ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _MyTestStringClassReference; -# else -struct objc_class _MyTestStringClassReference; -# endif -#endif +TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ int main (void) { @@ -59,6 +53,7 @@ int main (void) } #ifdef __NEXT_RUNTIME__ +#include /* The MyTestString metaclass will need to be initialized before we can send messages to strings. */ Index: gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h (revision 168652) +++ gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h (working copy) @@ -10,31 +10,20 @@ typedef void * PMETH; #else #include typedef struct objc_method * PMETH; -#endif -/* The NeXT headers do not define NULL. */ -#ifndef NULL -#define NULL 0 -#endif - -/* The NeXT runtimes do not include these functions (at least not through - any public API). They are required for the objc/execute/bf-* and bycopy-3. */ - -/* Not sure why the following are missing from NeXT objc headers... */ - -#ifndef _C_LNG_LNG +/* Missing from old NeXT objc headers... */ #define _C_LNG_LNG 'q' -#endif -#ifndef _C_ULNG_LNG #define _C_ULNG_LNG 'Q' -#endif -#ifndef _C_ATOM #define _C_ATOM '%' -#endif -#ifndef _C_BOOL #define _C_BOOL 'B' + #endif +/* The NeXT headers do not define NULL. */ +#ifndef NULL +#define NULL 0 +#endif + #define _C_CONST 'r' #define _C_IN 'n' #define _C_INOUT 'N' @@ -53,7 +42,8 @@ typedef struct objc_method * PMETH; #define _F_ONEWAY 0x10 #define _F_GCINVISIBLE 0x20 -/* Functions available in the GNU runtime, emulated here for testing with NeXT. */ +/* The NeXT runtimes do not include these functions (at least not through + any public API). They are required for the objc/execute/bf-* and bycopy-3. */ struct objc_struct_layout { Index: gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h (revision 0) +++ gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h (revision 0) @@ -0,0 +1,80 @@ +/* Define test-suite types to minimize conditional test-case source. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Iain Sandoe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef _OBJC_TEST_SUITE_TYPES_H_ +#define _OBJC_TEST_SUITE_TYPES_H_ + +#ifdef __cplusplus +#define ProtoBool bool +#else +#define ProtoBool _Bool +#endif + +#ifndef __NEXT_RUNTIME__ + +#define METHOD Method_t +#define IVAR_T struct objc_ivar + +/* dummy const string class ref. */ +typedef void * TNS_STRING_REF_T; + +#else /* NeXT */ + +#include "next-abi.h" +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +#include +#else +#include +#endif + +/* Force a definition of nil that is compatible with GNU runtime. */ +#undef nil +#define nil ((id)0) + +#ifndef NULL +#define NULL 0 +#endif + +#define METHOD Method + +/* Where there are equivalent interfaces between APIs we substitute + a macro or typedef. */ +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +typedef void * PMETH; +#define IVAR_T Ivar +#else +typedef struct objc_method * PMETH; +#define IVAR_T struct objc_ivar +#endif + +#ifdef __OBJC2__ +/* Const String Class ref. */ +typedef Class TNS_STRING_REF_T; +#else +/* Const String Class ref. */ +/* We need objc_class - but we don't need endless reminders that it's deprecated. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +typedef struct objc_class TNS_STRING_REF_T; +#pragma GCC diagnostic pop +#endif + +#endif /*__NEXT_RUNTIME__ */ +#endif /* _OBJC_TEST_SUITE_TYPES_H_ */ \ No newline at end of file Index: gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h (revision 0) +++ gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h (revision 0) @@ -0,0 +1,61 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 Free Software Foundation, Inc. + + Contributed by Iain Sandoe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifdef __NEXT_RUNTIME__ + +#include "nsconstantstring-class.h" +#include + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +@implementation NSConstantString +/* NeXT requires this or forward: */ ++initialize { return self; } + +-(const char *) cString +{ + return (c_string); +} + +-(unsigned int) length +{ + return (len); +} +@end + +TNS_STRING_REF_T _NSConstantStringClassReference; + +/* The NSConstantString metaclass will need to be initialized before we can + send messages to strings. */ + +void objc_constant_string_init (void) __attribute__((constructor)); +void objc_constant_string_init (void) { + memcpy (&_NSConstantStringClassReference, + objc_getClass ("NSConstantString"), + sizeof (_NSConstantStringClassReference)); +} +#endif Index: gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h (revision 0) +++ gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h (revision 0) @@ -0,0 +1,51 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef _test_suite_nsconstantstring_class_h_ +#define _test_suite_nsconstantstring_class_h_ +#ifdef __NEXT_RUNTIME__ + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +#include "objc-test-suite-types.h" + +extern TNS_STRING_REF_T _NSConstantStringClassReference; + +@interface NSConstantString +{ + Class isa; + char *c_string; + unsigned int len; +} + ++ (id) initialize; + +- (const char *) cString; +- (unsigned int) length; + +@end + +#endif /* __NEXT_RUNTIME__ */ +#endif /* _test_suite_nsconstantstring_class_h_ */ Index: gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm =================================================================== --- gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm (revision 0) +++ gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm (revision 0) @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" Index: gcc/testsuite/objc-obj-c++-shared/next-abi.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/next-abi.h (revision 168652) +++ gcc/testsuite/objc-obj-c++-shared/next-abi.h (working copy) @@ -1,4 +1,24 @@ +/* Check which version of the API and ABI are appropriate for the target. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + Contributed by Iain Sandoe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + #ifndef _OBJC_NEXT_ABI_H_ #define _OBJC_NEXT_ABI_H_ /* Produce a define that allows us to figure out what facilities are @@ -6,9 +26,8 @@ */ /* By default we do nothing - therefore ifdef NEXT_OBJC_USE_NEW_INTERFACE - * is reliable for detecting - * (a) versions of the compiler that are transitional to the new next ABI - * (b) versions of the target that require the new ABI. + * is reliable for detecting versions of the target that require either + * API=2, or both API & ABI = 2 (m64 code). * * This applies for versions of OSX >= 10.5 (darwin9). * Index: gcc/testsuite/objc-obj-c++-shared/next-mapping.h =================================================================== --- gcc/testsuite/objc-obj-c++-shared/next-mapping.h (revision 168652) +++ gcc/testsuite/objc-obj-c++-shared/next-mapping.h (working copy) @@ -1,42 +1,79 @@ +/* Compatibility header between runtimes and APIs. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + + Original Authors: Ziemowit Laski + David Ayers + + re-work for ObjC2 by Iain Sandoe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + #ifndef _OBJC_NEXT_MAPPING_H_ #define _OBJC_NEXT_MAPPING_H_ -/* This file "renames" various ObjC GNU runtime entry points - (and fakes the existence of several others) - if the NeXT runtime is being used. */ -/* Authors: Ziemowit Laski */ -/* David Ayers */ -/* Darwin 64bit/OBJC2 modifications Iain Sandoe */ +/* This file provides a two-way mapping of API names for the original + GNU & NeXT APIs. + + It is being expanded to provide mapping (where possible) between between the + older API and API-2. +*/ +#include "objc-test-suite-types.h" + #ifndef __NEXT_RUNTIME__ -#define CLASSPTRFIELD(x) (x)->class_pointer +# define CLASSFIELD class_pointer +# define CLASSPTRFIELD(x) (x)->class_pointer +# define SUPERCLASS superClass +# define OBJC_GETCLASS objc_get_class -#else -/* Includes next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ -#ifndef _OBJC_OBJECT1_H_ -#include "Object1.h" -#endif -#include -#include -#include -#include +# ifdef __objc_api_INCLUDE_GNU +# define class_createInstance(C, S) class_create_instance(C) +# endif +# define method_get_types(M) (M)->method_types -/* Force a definition of nil that is compatible with GNU runtime. */ -#undef nil -#define nil ((id)0) +#else /* NeXT */ -#define objc_get_class(C) objc_getClass(C) -#define objc_get_meta_class(C) objc_getMetaClass(C) -#define class_get_class_method(C, S) class_getClassMethod(C, S) -#define class_get_instance_method(C, S) class_getInstanceMethod(C, S) -#define sel_get_name(S) sel_getName(S) -#define class_create_instance(C) class_createInstance(C, 0) -#define class_get_class_name(C) object_getClassName(C) +/* Include next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ +# include "next-abi.h" -#define CLASSPTRFIELD(x) (x)->isa +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + /* API=2. */ +# include +# else + /* API=0. */ +# include +# endif -#ifdef NEXT_OBJC_USE_NEW_INTERFACE +# define CLASSPTRFIELD(x) (x)->isa +# define SUPERCLASS superclass +# define OBJC_GETCLASS objc_getClass + +# define objc_get_class(C) objc_getClass(C) +# define objc_get_meta_class(C) objc_getMetaClass(C) +# define class_get_class_method(C, S) class_getClassMethod(C, S) +# define class_get_instance_method(C, S) class_getInstanceMethod(C, S) +# define sel_get_name(S) sel_getName(S) +# define class_create_instance(C) class_createInstance(C, 0) +# define class_get_class_name(C) object_getClassName(C) +# define objc_lookup_class(N) objc_lookUpClass(N) + +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + # define object_class_name(O) (object_getClassName(O)) # define object_get_class(O) (object_getClass((id)O)) # define object_get_super_class(O) class_get_super_class(object_get_class(O)) @@ -51,7 +88,8 @@ # define class_is_meta_class(C) (class_isMetaClass((Class)C) ? YES: NO) # define class_is_class(C) (class_is_meta_class(C) == NO) -#else +# else /* OLD API */ + # define object_class_name(O) (O->name) # define object_get_super_class(O) class_get_super_class(*(struct objc_class **)O) # define object_get_class(O) (*(struct objc_class **)O) @@ -64,94 +102,8 @@ # define class_get_super_class(C) (((struct objc_class *)C)->super_class) # define class_is_meta_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_META)? YES: NO) # define class_is_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_CLASS)? YES: NO) -#endif -#define objc_lookup_class(N) objc_lookUpClass(N) +# endif /* NEXT_OBJC_USE_NEW_INTERFACE */ -/* You need either an empty +initialize method or an empty -forward:: method. - The NeXT runtime unconditionally sends +initialize to classes when they are - first used, and unconditionally tries to forward methods that the class - doesn't understand (including +initialize). If you have neither +initialize - nor -forward::, the runtime complains. - - The simplest workaround is to add - - + initialize { return self; } - - to every root class @implementation. */ - -#ifndef NULL -#define NULL 0 -#endif - - -/* A small, portable NSConstantString implementation for use with the NeXT - runtime. - - On full-fledged Mac OS X systems, NSConstantString is provided - as part of the Foundation framework. However, on bare Darwin systems, - Foundation is not included, and hence there is no NSConstantString - implementation to link against. - - This code is derived from the GNU runtime's NXConstantString implementation. -*/ - -/* This definition cut out of with the OBJC2 deprecation - messages removed. -*/ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class { - Class isa; -#if NEXT_OBJC_ABI_VERSION < 2 - Class super_class ; - const char *name ; - long version ; - long info ; - long instance_size ; - struct anon *ivars ; /* objc_ivar_list */ - struct anon1 **methodLists ; /* objc_method_list */ - struct objc_cache *cache ; - struct objc_protocol_list *protocols ; -#endif -} _NSConstantStringClassReference ; -#else -struct objc_class _NSConstantStringClassReference ; -#endif - -@interface NSConstantString : Object -{ - char *c_string; - unsigned int len; -} - --(const char *) cString; --(unsigned int) length; - -@end - -@implementation NSConstantString - --(const char *) cString -{ - return (c_string); -} - --(unsigned int) length -{ - return (len); -} - -@end - -/* The NSConstantString metaclass will need to be initialized before we can - send messages to strings. */ - -void objc_constant_string_init (void) __attribute__((constructor)); -void objc_constant_string_init (void) { - memcpy (&_NSConstantStringClassReference, - objc_getClass ("NSConstantString"), - sizeof (_NSConstantStringClassReference)); -} - -#endif /*__NEXT_RUNTIME__ */ +# endif /*__NEXT_RUNTIME__ */ #endif /* _OBJC_NEXT_MAPPING_H_ */ \ No newline at end of file Index: gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m =================================================================== --- gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m (revision 0) +++ gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m (revision 0) @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" Index: gcc/testsuite/objc.dg/foreach-5.m =================================================================== --- gcc/testsuite/objc.dg/foreach-5.m (revision 168652) +++ gcc/testsuite/objc.dg/foreach-5.m (working copy) @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ -/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #import "../objc-obj-c++-shared/Object1.h" #import "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...); Index: gcc/testsuite/objc.dg/foreach-2.m =================================================================== --- gcc/testsuite/objc.dg/foreach-2.m (revision 168652) +++ gcc/testsuite/objc.dg/foreach-2.m (working copy) @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ -/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #include "../objc-obj-c++-shared/Object1.h" #include "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...); Index: gcc/testsuite/objc.dg/torture/strings/string1.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string1.m (revision 168652) +++ gcc/testsuite/objc.dg/torture/strings/string1.m (working copy) @@ -1,18 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#include "../../../objc-obj-c++-shared/next-mapping.h" - #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) Index: gcc/testsuite/objc.dg/torture/strings/string2.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string2.m (revision 168652) +++ gcc/testsuite/objc.dg/torture/strings/string2.m (working copy) @@ -1,18 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#include "../../../objc-obj-c++-shared/next-mapping.h" - #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) Index: gcc/testsuite/objc.dg/torture/strings/string3.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string3.m (revision 168652) +++ gcc/testsuite/objc.dg/torture/strings/string3.m (working copy) @@ -1,17 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#import "../../../objc-obj-c++-shared/next-mapping.h" #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif #define STRING "this is a string" Index: gcc/testsuite/objc.dg/torture/strings/string4.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/string4.m (revision 168652) +++ gcc/testsuite/objc.dg/torture/strings/string4.m (working copy) @@ -1,17 +1,17 @@ /* Based on a test case contributed by Nicola Pero. */ /* { dg-do run } */ -/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ +/* { dg-options "-mno-constant-cfstrings -Wno-deprecated-declarations" { target *-*-darwin* } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../../../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#import "../../../objc-obj-c++-shared/next-mapping.h" #include #include #ifndef __NEXT_RUNTIME__ #include +#else +#include "../../../objc-obj-c++-shared/nsconstantstring-class.h" #endif int main(int argc, void **args) Index: gcc/testsuite/objc.dg/torture/strings/const-str-3.m =================================================================== --- gcc/testsuite/objc.dg/torture/strings/const-str-3.m (revision 168652) +++ gcc/testsuite/objc.dg/torture/strings/const-str-3.m (working copy) @@ -4,28 +4,27 @@ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ -/* { dg-additional-sources "../../../objc-obj-c++-shared/Object1.m" } */ -#include "../../../objc-obj-c++-shared/Object1.h" -#include "../../../objc-obj-c++-shared/next-mapping.h" +#include "../../../objc-obj-c++-shared/objc-test-suite-types.h" + #include #include #include -@interface Foo: Object { +@interface Foo { + void *dummy_class_ref; char *cString; unsigned int len; } ++ initialize; - (char *)customString; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ -@implementation Foo : Object +@implementation Foo ++ initialize {return self;} + - (char *)customString { return cString; } @@ -39,11 +38,13 @@ int main () { abort(); printf("Strings are being uniqued properly\n"); +#ifdef __NEXT_RUNTIME__ /* This memcpy has to be done before the first message is sent to a constant string object. Can't be moved to +initialize since _that_ - is already a message. */ + is already a message. */ - memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference)); + memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); +#endif if (strcmp ([string customString], "bla")) { abort (); } Index: gcc/testsuite/objc.dg/strings/strings-2.m =================================================================== --- gcc/testsuite/objc.dg/strings/strings-2.m (revision 168652) +++ gcc/testsuite/objc.dg/strings/strings-2.m (working copy) @@ -5,24 +5,25 @@ /* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ -/* { dg-additional-sources "../../objc-obj-c++-shared/Object1.m" } */ +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" -#include "../../objc-obj-c++-shared/Object1.h" -#include "../../objc-obj-c++-shared/next-mapping.h" - #include /* For abort() */ -@interface MyTestString : Object +@interface MyTestString { + void *dummy_class_ptr; char *string; unsigned int len; } ++ initialize; /* All strings should contain the C string 'test'. Call -check to test that this is true. */ - (void) check; @end @implementation MyTestString ++ initialize {return self;} + - (void) check { if (len != 4 || string[0] != 't' || string[1] != 'e' @@ -31,13 +32,7 @@ } @end -#ifdef __NEXT_RUNTIME__ -# ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _MyTestStringClassReference; -# else -struct objc_class _MyTestStringClassReference; -# endif -#endif +TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */ int main (void) { @@ -61,6 +56,7 @@ int main (void) #ifdef __NEXT_RUNTIME__ /* The MyTestString metaclass will need to be initialized before we can send messages to strings. */ +#include void testsuite_mytest_string_init (void) __attribute__((constructor)); void testsuite_mytest_string_init (void) { Index: gcc/testsuite/objc.dg/strings/const-str-12b.m =================================================================== --- gcc/testsuite/objc.dg/strings/const-str-12b.m (revision 168652) +++ gcc/testsuite/objc.dg/strings/const-str-12b.m (working copy) @@ -5,8 +5,8 @@ /* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ -#include "../../objc-obj-c++-shared/Object1.h" -#import "../../objc-obj-c++-shared/next-mapping.h" +#include +#include "../../objc-obj-c++-shared/objc-test-suite-types.h" @interface Foo: Object { char *cString; @@ -19,11 +19,7 @@ + (Foo *) getString: (int) which; @end -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class _FooClassReference; -#else -struct objc_class _FooClassReference; -#endif +TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */ @implementation Bar + (Foo *) getString: (int) which { Index: gcc/testsuite/objc.dg/foreach-4.m =================================================================== --- gcc/testsuite/objc.dg/foreach-4.m (revision 168652) +++ gcc/testsuite/objc.dg/foreach-4.m (working copy) @@ -5,12 +5,14 @@ /* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ -/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m" } */ +/* { dg-additional-sources "../objc-obj-c++-shared/Object1.m ../objc-obj-c++-shared/nsconstantstring-class-impl.m" } */ #import "../objc-obj-c++-shared/Object1.h" #import "../objc-obj-c++-shared/next-mapping.h" #ifndef __NEXT_RUNTIME__ #include +#else +#include "../objc-obj-c++-shared/nsconstantstring-class.h" #endif extern int printf (const char *, ...);