Commit 5826c8d2 by Iain Sandoe

next-mapping.h: Add copyright header.


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.

From-SVN: r168653
parent 2aa9c6ae
2011-01-11 Iain Sandoe <iains@gcc.gnu.org>
* 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 <rguenther@suse.de> 2011-01-12 Richard Guenther <rguenther@suse.de>
PR middle-end/32511 PR middle-end/32511
......
...@@ -5,24 +5,24 @@ ...@@ -5,24 +5,24 @@
/* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-fconstant-string-class=MyTestString" } */
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ /* { 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 <stdlib.h> /* For abort() */ #include <stdlib.h> /* For abort() */
@interface MyTestString : Object @interface MyTestString
{ {
void *dummy_class_ptr;
char *string; char *string;
unsigned int len; unsigned int len;
} }
+ initialize;
/* All strings should contain the C string 'test'. Call -check to /* All strings should contain the C string 'test'. Call -check to
test that this is true. */ test that this is true. */
- (void) check; - (void) check;
@end @end
@implementation MyTestString @implementation MyTestString
+ + initialize {return self;}
- (void) check - (void) check
{ {
if (len != 4 || string[0] != 't' || string[1] != 'e' if (len != 4 || string[0] != 't' || string[1] != 'e'
...@@ -31,13 +31,7 @@ ...@@ -31,13 +31,7 @@
} }
@end @end
#ifdef __NEXT_RUNTIME__ TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */
# ifdef NEXT_OBJC_USE_NEW_INTERFACE
struct fudge_objc_class _MyTestStringClassReference;
# else
struct objc_class _MyTestStringClassReference;
# endif
#endif
int main (void) int main (void)
{ {
...@@ -59,6 +53,7 @@ int main (void) ...@@ -59,6 +53,7 @@ int main (void)
} }
#ifdef __NEXT_RUNTIME__ #ifdef __NEXT_RUNTIME__
#include <string.h>
/* The MyTestString metaclass will need to be initialized before we can /* The MyTestString metaclass will need to be initialized before we can
send messages to strings. */ send messages to strings. */
......
...@@ -3,17 +3,21 @@ ...@@ -3,17 +3,21 @@
/* { dg-do run } */ /* { dg-do run } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { 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 <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
#include "../objc-obj-c++-shared/Object1.h"
#include "../objc-obj-c++-shared/next-mapping.h"
#define CHECK_IF(expr) if(!(expr)) abort() #define CHECK_IF(expr) if(!(expr)) abort()
template <class ARR, class TYPE> class TestT template <class ARR, class TYPE> class TestT
......
...@@ -6,32 +6,26 @@ ...@@ -6,32 +6,26 @@
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ /* { 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" #include "../../../objc-obj-c++-shared/objc-test-suite-types.h"
#import "../../../objc-obj-c++-shared/next-mapping.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <string.h>
#include <objc/objc.h>
#ifndef __NEXT_RUNTIME__
#include <objc/objc-api.h>
#endif
@interface Foo: Object { @interface Foo {
void *dummy_class_ref;
char *cString; char *cString;
unsigned int len; unsigned int len;
} }
+ initialize;
- (char *)customString; - (char *)customString;
@end @end
#ifdef NEXT_OBJC_USE_NEW_INTERFACE TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */
struct fudge_objc_class _FooClassReference;
#else
struct objc_class _FooClassReference;
#endif
@implementation Foo : Object @implementation Foo
+ + initialize {return self;}
- (char *)customString { - (char *)customString {
return cString; return cString;
} }
...@@ -45,11 +39,14 @@ int main () { ...@@ -45,11 +39,14 @@ int main () {
abort(); abort();
printf("Strings are being uniqued properly\n"); printf("Strings are being uniqued properly\n");
#ifdef __NEXT_RUNTIME__
/* This memcpy has to be done before the first message is sent to a /* 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_ 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")) { if (strcmp ([string customString], "bla")) {
abort (); abort ();
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/* { dg-do run } */ /* { dg-do run } */
/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { 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/Object1.h"
#include "../../../objc-obj-c++-shared/next-mapping.h" #include "../../../objc-obj-c++-shared/next-mapping.h"
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../../../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
int main(int argc, char **args) int main(int argc, char **args)
......
/* 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 <iains@gcc.gnu.org>
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
<http://www.gnu.org/licenses/>. */
#ifndef _OBJC_NEXT_ABI_H_ #ifndef _OBJC_NEXT_ABI_H_
#define _OBJC_NEXT_ABI_H_ #define _OBJC_NEXT_ABI_H_
...@@ -6,9 +26,8 @@ ...@@ -6,9 +26,8 @@
*/ */
/* By default we do nothing - therefore ifdef NEXT_OBJC_USE_NEW_INTERFACE /* By default we do nothing - therefore ifdef NEXT_OBJC_USE_NEW_INTERFACE
* is reliable for detecting * is reliable for detecting versions of the target that require either
* (a) versions of the compiler that are transitional to the new next ABI * API=2, or both API & ABI = 2 (m64 code).
* (b) versions of the target that require the new ABI.
* *
* This applies for versions of OSX >= 10.5 (darwin9). * This applies for versions of OSX >= 10.5 (darwin9).
* *
......
/* Compatibility header between runtimes and APIs.
Copyright (C) 2010, 2011 Free Software Foundation, Inc.
Original Authors: Ziemowit Laski <zlaski@apple.com>
David Ayers <d.ayers@inode.at>
re-work for ObjC2 by Iain Sandoe <iains@gcc.gnu.org>
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
<http://www.gnu.org/licenses/>. */
#ifndef _OBJC_NEXT_MAPPING_H_ #ifndef _OBJC_NEXT_MAPPING_H_
#define _OBJC_NEXT_MAPPING_H_ #define _OBJC_NEXT_MAPPING_H_
/* This file "renames" various ObjC GNU runtime entry points /* This file provides a two-way mapping of API names for the original
(and fakes the existence of several others) GNU & NeXT APIs.
if the NeXT runtime is being used. */
/* Authors: Ziemowit Laski <zlaski@apple.com> */ It is being expanded to provide mapping (where possible) between between the
/* David Ayers <d.ayers@inode.at> */ older API and API-2.
/* Darwin 64bit/OBJC2 modifications Iain Sandoe */ */
#include "objc-test-suite-types.h"
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#define CLASSPTRFIELD(x) (x)->class_pointer # define CLASSFIELD class_pointer
# define CLASSPTRFIELD(x) (x)->class_pointer
#else # define SUPERCLASS superClass
/* Includes next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ # define OBJC_GETCLASS objc_get_class
#ifndef _OBJC_OBJECT1_H_
#include "Object1.h" # ifdef __objc_api_INCLUDE_GNU
#endif # define class_createInstance(C, S) class_create_instance(C)
#include <objc/objc-class.h> # endif
#include <ctype.h> # define method_get_types(M) (M)->method_types
#include <stdlib.h>
#include <string.h> #else /* NeXT */
/* Force a definition of nil that is compatible with GNU runtime. */ /* Include next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/
#undef nil # include "next-abi.h"
#define nil ((id)0)
# ifdef NEXT_OBJC_USE_NEW_INTERFACE
#define objc_get_class(C) objc_getClass(C) /* API=2. */
#define objc_get_meta_class(C) objc_getMetaClass(C) # include <objc/runtime.h>
#define class_get_class_method(C, S) class_getClassMethod(C, S) # else
#define class_get_instance_method(C, S) class_getInstanceMethod(C, S) /* API=0. */
#define sel_get_name(S) sel_getName(S) # include <objc/objc-class.h>
#define class_create_instance(C) class_createInstance(C, 0) # endif
#define class_get_class_name(C) object_getClassName(C)
# define CLASSPTRFIELD(x) (x)->isa
#define CLASSPTRFIELD(x) (x)->isa # define SUPERCLASS superclass
# define OBJC_GETCLASS objc_getClass
#ifdef NEXT_OBJC_USE_NEW_INTERFACE
# 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_class_name(O) (object_getClassName(O))
# define object_get_class(O) (object_getClass((id)O)) # define object_get_class(O) (object_getClass((id)O))
# define object_get_super_class(O) class_get_super_class(object_get_class(O)) # define object_get_super_class(O) class_get_super_class(object_get_class(O))
...@@ -51,7 +88,8 @@ ...@@ -51,7 +88,8 @@
# define class_is_meta_class(C) (class_isMetaClass((Class)C) ? YES: NO) # define class_is_meta_class(C) (class_isMetaClass((Class)C) ? YES: NO)
# define class_is_class(C) (class_is_meta_class(C) == 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_class_name(O) (O->name)
# define object_get_super_class(O) class_get_super_class(*(struct objc_class **)O) # define object_get_super_class(O) class_get_super_class(*(struct objc_class **)O)
# define object_get_class(O) (*(struct objc_class **)O) # define object_get_class(O) (*(struct objc_class **)O)
...@@ -64,94 +102,8 @@ ...@@ -64,94 +102,8 @@
# define class_get_super_class(C) (((struct objc_class *)C)->super_class) # 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_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) # define class_is_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_CLASS)? YES: NO)
#endif
#define objc_lookup_class(N) objc_lookUpClass(N)
/* 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. */ # endif /* NEXT_OBJC_USE_NEW_INTERFACE */
#ifndef NULL # endif /*__NEXT_RUNTIME__ */
#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 <objc/Object.h> 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 /* _OBJC_NEXT_MAPPING_H_ */ #endif /* _OBJC_NEXT_MAPPING_H_ */
\ No newline at end of file
/* A small NSConstantString implementation for use with the NeXT runtime.
Copyright (C) 2011 Free Software Foundation, Inc.
Contributed by Iain Sandoe <iains@gcc.gnu.org>
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
<http://www.gnu.org/licenses/>. */
#ifdef __NEXT_RUNTIME__
#include "nsconstantstring-class.h"
#include <string.h>
/* 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
/* Allow code to be shared between the FEs but avoid issues with
C++-only flags. */
#include "nsconstantstring-class-impl.h"
/* Allow code to be shared between the FEs but avoid issues with
C++-only flags. */
#include "nsconstantstring-class-impl.h"
/* 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
<http://www.gnu.org/licenses/>. */
#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_ */
...@@ -10,29 +10,18 @@ typedef void * PMETH; ...@@ -10,29 +10,18 @@ typedef void * PMETH;
#else #else
#include <objc/objc-runtime.h> #include <objc/objc-runtime.h>
typedef struct objc_method * PMETH; 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 /* Missing from old NeXT objc headers... */
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
#define _C_LNG_LNG 'q' #define _C_LNG_LNG 'q'
#endif
#ifndef _C_ULNG_LNG
#define _C_ULNG_LNG 'Q' #define _C_ULNG_LNG 'Q'
#endif
#ifndef _C_ATOM
#define _C_ATOM '%' #define _C_ATOM '%'
#endif
#ifndef _C_BOOL
#define _C_BOOL 'B' #define _C_BOOL 'B'
#endif
/* The NeXT headers do not define NULL. */
#ifndef NULL
#define NULL 0
#endif #endif
#define _C_CONST 'r' #define _C_CONST 'r'
...@@ -53,7 +42,8 @@ typedef struct objc_method * PMETH; ...@@ -53,7 +42,8 @@ typedef struct objc_method * PMETH;
#define _F_ONEWAY 0x10 #define _F_ONEWAY 0x10
#define _F_GCINVISIBLE 0x20 #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 struct objc_struct_layout
{ {
......
/* 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
<http://www.gnu.org/licenses/>. */
#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 <objc/runtime.h>
#else
#include <objc/objc-runtime.h>
#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
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
/* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { 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/Object1.h"
#include "../objc-obj-c++-shared/next-mapping.h" #include "../objc-obj-c++-shared/next-mapping.h"
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
extern int printf (const char *, ...); extern int printf (const char *, ...);
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
/* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { 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/Object1.h"
#import "../objc-obj-c++-shared/next-mapping.h" #import "../objc-obj-c++-shared/next-mapping.h"
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
extern int printf (const char *, ...); extern int printf (const char *, ...);
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
/* { dg-skip-if "No NeXT fast enum. pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { 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-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */ /* { 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/Object1.h"
#import "../objc-obj-c++-shared/next-mapping.h" #import "../objc-obj-c++-shared/next-mapping.h"
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
extern int printf (const char *, ...); extern int printf (const char *, ...);
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
/* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ /* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
#include "../../objc-obj-c++-shared/Object1.h" #include <objc/Object.h>
#import "../../objc-obj-c++-shared/next-mapping.h" #include "../../objc-obj-c++-shared/objc-test-suite-types.h"
@interface Foo: Object { @interface Foo: Object {
char *cString; char *cString;
...@@ -19,11 +19,7 @@ ...@@ -19,11 +19,7 @@
+ (Foo *) getString: (int) which; + (Foo *) getString: (int) which;
@end @end
#ifdef NEXT_OBJC_USE_NEW_INTERFACE TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */
struct fudge_objc_class _FooClassReference;
#else
struct objc_class _FooClassReference;
#endif
@implementation Bar @implementation Bar
+ (Foo *) getString: (int) which { + (Foo *) getString: (int) which {
......
...@@ -5,24 +5,25 @@ ...@@ -5,24 +5,25 @@
/* { dg-options "-fconstant-string-class=MyTestString" } */ /* { dg-options "-fconstant-string-class=MyTestString" } */
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */ /* { 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 <stdlib.h> /* For abort() */ #include <stdlib.h> /* For abort() */
@interface MyTestString : Object @interface MyTestString
{ {
void *dummy_class_ptr;
char *string; char *string;
unsigned int len; unsigned int len;
} }
+ initialize;
/* All strings should contain the C string 'test'. Call -check to /* All strings should contain the C string 'test'. Call -check to
test that this is true. */ test that this is true. */
- (void) check; - (void) check;
@end @end
@implementation MyTestString @implementation MyTestString
+ + initialize {return self;}
- (void) check - (void) check
{ {
if (len != 4 || string[0] != 't' || string[1] != 'e' if (len != 4 || string[0] != 't' || string[1] != 'e'
...@@ -31,13 +32,7 @@ ...@@ -31,13 +32,7 @@
} }
@end @end
#ifdef __NEXT_RUNTIME__ TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */
# ifdef NEXT_OBJC_USE_NEW_INTERFACE
struct fudge_objc_class _MyTestStringClassReference;
# else
struct objc_class _MyTestStringClassReference;
# endif
#endif
int main (void) int main (void)
{ {
...@@ -61,6 +56,7 @@ int main (void) ...@@ -61,6 +56,7 @@ int main (void)
#ifdef __NEXT_RUNTIME__ #ifdef __NEXT_RUNTIME__
/* The MyTestString metaclass will need to be initialized before we can /* The MyTestString metaclass will need to be initialized before we can
send messages to strings. */ send messages to strings. */
#include <string.h>
void testsuite_mytest_string_init (void) __attribute__((constructor)); void testsuite_mytest_string_init (void) __attribute__((constructor));
void testsuite_mytest_string_init (void) { void testsuite_mytest_string_init (void) {
......
...@@ -4,28 +4,27 @@ ...@@ -4,28 +4,27 @@
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
/* { dg-options "-fconstant-string-class=Foo" } */ /* { dg-options "-fconstant-string-class=Foo" } */
/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */ /* { 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/objc-test-suite-types.h"
#include "../../../objc-obj-c++-shared/next-mapping.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@interface Foo: Object { @interface Foo {
void *dummy_class_ref;
char *cString; char *cString;
unsigned int len; unsigned int len;
} }
+ initialize;
- (char *)customString; - (char *)customString;
@end @end
#ifdef NEXT_OBJC_USE_NEW_INTERFACE TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */
struct fudge_objc_class _FooClassReference;
#else @implementation Foo
struct objc_class _FooClassReference; + + initialize {return self;}
#endif
@implementation Foo : Object
- (char *)customString { - (char *)customString {
return cString; return cString;
} }
...@@ -39,11 +38,13 @@ int main () { ...@@ -39,11 +38,13 @@ int main () {
abort(); abort();
printf("Strings are being uniqued properly\n"); printf("Strings are being uniqued properly\n");
#ifdef __NEXT_RUNTIME__
/* This memcpy has to be done before the first message is sent to a /* 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_ 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")) { if (strcmp ([string customString], "bla")) {
abort (); abort ();
} }
......
/* Based on a test case contributed by Nicola Pero. */ /* Based on a test case contributed by Nicola Pero. */
/* { dg-do run } */ /* { 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-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 <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../../../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
int main(int argc, void **args) int main(int argc, void **args)
......
/* Based on a test case contributed by Nicola Pero. */ /* Based on a test case contributed by Nicola Pero. */
/* { dg-do run } */ /* { 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-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 <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../../../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
int main(int argc, void **args) int main(int argc, void **args)
......
/* Based on a test case contributed by Nicola Pero. */ /* Based on a test case contributed by Nicola Pero. */
/* { dg-do run } */ /* { 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-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 <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../../../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
#define STRING "this is a string" #define STRING "this is a string"
......
/* Based on a test case contributed by Nicola Pero. */ /* Based on a test case contributed by Nicola Pero. */
/* { dg-do run } */ /* { 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-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 <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __NEXT_RUNTIME__ #ifndef __NEXT_RUNTIME__
#include <objc/NXConstStr.h> #include <objc/NXConstStr.h>
#else
#include "../../../objc-obj-c++-shared/nsconstantstring-class.h"
#endif #endif
int main(int argc, void **args) int main(int argc, void **args)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment