From 1f2d35006b8f1c7cf7ae87ed8a6068331584d611 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sun, 24 Dec 2017 16:19:01 +0000 Subject: [PATCH] Make the ObjC++ interop test compile --- Test/CMakeLists.txt | 9 ++++++--- Test/MyException.h | 2 +- Test/MyException.m | 10 +++++----- Test/Test.h | 11 ++++++++--- Test/Test.m | 36 +++--------------------------------- Test/minRep.mm | 2 +- Test/minRep1.h | 2 +- Test/minRep1.mm | 2 +- Test/minRep2.h | 2 +- Test/minRep2.mm | 2 +- Test/minRepM.h | 2 +- Test/minRepM.m | 2 +- 12 files changed, 30 insertions(+), 52 deletions(-) diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 074827f..f6d6eba 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -63,9 +63,12 @@ foreach(TEST_SOURCE ${TESTS}) get_filename_component(TEST ${TEST_SOURCE} NAME_WE) addtest_flags(${TEST} "-O0 -UNDEBUG" ${TEST_SOURCE}) addtest_flags("${TEST}_optimised" "-O3 -UNDEBUG" ${TEST_SOURCE}) + target_compile_definitions(${TEST} PRIVATE SINGLE_FILE_TEST=1) + target_compile_definitions("${TEST}_optimised" PRIVATE SINGLE_FILE_TEST=1) endforeach() # Tests that are more than a single file. -addtest_flags(CXXExceptions "-O0" "CXXException.m;CXXException.cc") -addtest_flags(CXXExceptions_optimised "-O3" "CXXException.m;CXXException.cc") -addtest_flags(MinRep "-O0" "minRep1.mm;minRep2.mm;minRep.mm;minRepM.m;ModTest.m;MyException.m") +addtest_flags(CXXExceptions "-O0" "CXXException.m;CXXException.cc;Test.m") +addtest_flags(CXXExceptions_optimised "-O3" "CXXException.m;CXXException.cc;Test.m") +addtest_flags(ObjCXXEHInterop "-O0" "minRep1.mm;minRep2.mm;minRep.mm;minRepM.m;MyException.m;Test.m") +addtest_flags(ObjCXXEHInterop_opttimised "-O3" "minRep1.mm;minRep2.mm;minRep.mm;minRepM.m;MyException.m;Test.m") diff --git a/Test/MyException.h b/Test/MyException.h index 8ca3d4c..fb7596e 100644 --- a/Test/MyException.h +++ b/Test/MyException.h @@ -1,4 +1,4 @@ -#include "ModTest.h" +#include "Test.h" @interface MyException : Test { @private diff --git a/Test/MyException.m b/Test/MyException.m index 316f5cf..2b548fd 100644 --- a/Test/MyException.m +++ b/Test/MyException.m @@ -1,21 +1,20 @@ #import "MyException.h" +#include @implementation MyException - (MyException *)initWithName:(char *)name reason:(char *)reason { - if ((self = [super init]) != nil) { - _name = name; - _reason = reason; - } + _name = name; + _reason = reason; return self; } + (void) raise: (char *)name format: (char *)reason { - MyException *e = [[[MyException alloc] initWithName:name + MyException *e = [[[MyException new] initWithName:name reason:reason] autorelease]; [e raise]; } @@ -28,6 +27,7 @@ if (_reason) { free(_reason); } + [super dealloc]; } - (void) raise { diff --git a/Test/Test.h b/Test/Test.h index 6ca0261..e455aaa 100644 --- a/Test/Test.h +++ b/Test/Test.h @@ -23,6 +23,11 @@ __attribute__((objc_root_class)) #endif @end +@interface NSAutoreleasePool : Test +@end + +#ifdef SINGLE_FILE_TEST + #if !__has_feature(objc_arc) @implementation Test + (Class)class { return self; } @@ -48,10 +53,7 @@ __attribute__((objc_root_class)) } - (void)_ARCCompliantRetainRelease {} @end -#endif -@interface NSAutoreleasePool : Test -@end @implementation NSAutoreleasePool - (void)_ARCCompatibleAutoreleasePool {} + (void)addObject:(id)anObject @@ -59,3 +61,6 @@ __attribute__((objc_root_class)) objc_autorelease(anObject); } @end +#endif + +#endif diff --git a/Test/Test.m b/Test/Test.m index 83a4c3d..87bfcae 100644 --- a/Test/Test.m +++ b/Test/Test.m @@ -4,37 +4,7 @@ #undef NDEBUG #endif #include - -#ifndef __has_attribute -#define __has_attribute(x) 0 +#ifndef SINGLE_FILE_TEST +#define SINGLE_FILE_TEST 1 #endif - -#if __has_attribute(objc_root_class) -__attribute__((objc_root_class)) -#endif -@interface Test { id isa; } -@end -@implementation Test -+ (Class)class { return self; } -+ (id)new -{ - return class_createInstance(self, 0); -} -- (void)dealloc -{ - object_dispose(self); -} -- (id)autorelease -{ - return objc_autorelease(self); -} -- (id)retain -{ - return objc_retain(self); -} -- (void)release -{ - objc_release(self); -} -- (void)_ARCCompliantRetainRelease {} -@end +#include "Test.h" diff --git a/Test/minRep.mm b/Test/minRep.mm index 6d75f60..7daf632 100644 --- a/Test/minRep.mm +++ b/Test/minRep.mm @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRepM.h" diff --git a/Test/minRep1.h b/Test/minRep1.h index b92e360..aa07f16 100644 --- a/Test/minRep1.h +++ b/Test/minRep1.h @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRep2.h" diff --git a/Test/minRep1.mm b/Test/minRep1.mm index 88a2ad4..8d6e212 100644 --- a/Test/minRep1.mm +++ b/Test/minRep1.mm @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRep1.h" diff --git a/Test/minRep2.h b/Test/minRep2.h index 3522281..bff182f 100644 --- a/Test/minRep2.h +++ b/Test/minRep2.h @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" @interface MinRep2 : Test { } diff --git a/Test/minRep2.mm b/Test/minRep2.mm index 592e98e..00fc588 100644 --- a/Test/minRep2.mm +++ b/Test/minRep2.mm @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRep2.h" #import "MyException.h" diff --git a/Test/minRepM.h b/Test/minRepM.h index da5631e..16915c6 100644 --- a/Test/minRepM.h +++ b/Test/minRepM.h @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRep1.h" diff --git a/Test/minRepM.m b/Test/minRepM.m index eaa011d..7b3b821 100644 --- a/Test/minRepM.m +++ b/Test/minRepM.m @@ -1,4 +1,4 @@ -#import "ModTest.h" +#import "Test.h" #import "minRepM.h" #import "minRep1.h"