From 9b8635767148b3f95942593bfeefa86f147d2c53 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Thu, 19 Dec 2013 21:30:10 +0000 Subject: Fix build of Mac GTM project with static analyzer. Remove GTMGarbageCollection. Remove GC build configs. Remove internal dependence on GTMObjectSingleton. DELTA=447 (49 added, 296 deleted, 102 changed) --- Foundation/GTMAbstractDOListenerTest.m | 14 ++---- Foundation/GTMFileSystemKQueueTest.m | 14 ++---- Foundation/GTMFourCharCode.m | 1 - Foundation/GTMGarbageCollection.h | 72 +-------------------------- Foundation/GTMLogger.m | 1 - Foundation/GTMNSAppleScript+Handler.h | 7 --- Foundation/GTMNSAppleScript+Handler.m | 12 ++--- Foundation/GTMNSAppleScript+HandlerTest.m | 16 ------ Foundation/GTMNSDictionary+CaseInsensitive.m | 21 ++------ Foundation/GTMNSFileManager+Carbon.m | 1 - Foundation/GTMNSString+FindFolder.m | 2 +- Foundation/GTMNSString+URLArguments.m | 3 +- Foundation/GTMNSString+XML.m | 1 - Foundation/GTMSQLite.m | 1 - Foundation/GTMSQLiteTest.m | 73 +++++++++++++--------------- Foundation/GTMServiceManagementTest.m | 1 - Foundation/GTMSystemVersion.m | 2 - Foundation/GTMURITemplate.m | 2 +- 18 files changed, 58 insertions(+), 186 deletions(-) (limited to 'Foundation') diff --git a/Foundation/GTMAbstractDOListenerTest.m b/Foundation/GTMAbstractDOListenerTest.m index 2cb4557..d26d4fc 100644 --- a/Foundation/GTMAbstractDOListenerTest.m +++ b/Foundation/GTMAbstractDOListenerTest.m @@ -19,9 +19,6 @@ #import "GTMSenTestCase.h" #import "GTMAbstractDOListener.h" -// Needed for GTMIsGarbageCollectionEnabled -#import "GTMGarbageCollection.h" - // Needed for GTMUnitTestDevLog expectPattern #import "GTMUnitTestDevLog.h" @@ -358,16 +355,11 @@ enum { listenerCount + 1, nil); [pool drain]; - if (!GTMIsGarbageCollectionEnabled()) { - // Not much point with GC on. - STAssertEquals([listener retainCount], (NSUInteger)1, nil); - } + STAssertEquals([listener retainCount], (NSUInteger)1, nil); [listener release]; - if (!GTMIsGarbageCollectionEnabled()) { - STAssertEquals([[GTMAbstractDOListener allListeners] count], listenerCount, - nil); - } + STAssertEquals([[GTMAbstractDOListener allListeners] count], listenerCount, + nil); } @end diff --git a/Foundation/GTMFileSystemKQueueTest.m b/Foundation/GTMFileSystemKQueueTest.m index d80f161..a8eec37 100644 --- a/Foundation/GTMFileSystemKQueueTest.m +++ b/Foundation/GTMFileSystemKQueueTest.m @@ -18,7 +18,6 @@ #import "GTMSenTestCase.h" #import "GTMFileSystemKQueue.h" -#import "GTMGarbageCollection.h" #import "GTMUnitTestDevLog.h" @@ -509,15 +508,10 @@ #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 // Now destroy the queue, with events outstanding from the CFSocket, but - // unconsumed. For GC this involves us using a private method since |helper| - // still has a reference. For non-GC we'll force the release. - if (GTMIsGarbageCollectionEnabled()) { - [testKQ unregisterWithKQueue]; - } else { - STAssertEquals([testKQ retainCount], (NSUInteger)1, nil); - [testKQ release]; - testKQ = nil; - } + // unconsumed. + STAssertEquals([testKQ retainCount], (NSUInteger)1, nil); + [testKQ release]; + testKQ = nil; // Spin the runloop, no events were delivered (and we should not hang) [self spinForEvents:helper]; diff --git a/Foundation/GTMFourCharCode.m b/Foundation/GTMFourCharCode.m index 44ab688..02eea23 100644 --- a/Foundation/GTMFourCharCode.m +++ b/Foundation/GTMFourCharCode.m @@ -19,7 +19,6 @@ #import "GTMDefines.h" #import "GTMFourCharCode.h" -#import "GTMGarbageCollection.h" #import @implementation GTMFourCharCode diff --git a/Foundation/GTMGarbageCollection.h b/Foundation/GTMGarbageCollection.h index 93d4efa..19ba255 100644 --- a/Foundation/GTMGarbageCollection.h +++ b/Foundation/GTMGarbageCollection.h @@ -1,72 +1,4 @@ // -// GTMGarbageCollection.h +// This file previously included utility functions for working +// with Garbage Collection on Mac OS X. // -// Copyright 2007-2008 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy -// of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. -// - -#import - -#import "GTMDefines.h" - -// This allows us to easily move our code from GC to non GC. -// They are no-ops unless we are require Leopard or above. -// See -// http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/index.html -// and -// http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html#//apple_ref/doc/uid/TP40006687-SW1 -// for details. - -#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) && !GTM_IPHONE_SDK -// General use would be to call this through GTMCFAutorelease -// but there may be a reason the you want to make something collectable -// but not autoreleased, especially in pure GC code where you don't -// want to bother with the nop autorelease. Done as a define instead of an -// inline so that tools like Clang's scan-build don't report code as leaking. -#define GTMNSMakeCollectable(cf) ((id)NSMakeCollectable(cf)) - -// GTMNSMakeUncollectable is for global maps, etc. that we don't -// want released ever. You should still retain these in non-gc code. -GTM_INLINE void GTMNSMakeUncollectable(id object) { - [[NSGarbageCollector defaultCollector] disableCollectorForPointer:object]; -} - -// Hopefully no code really needs this, but GTMIsGarbageCollectionEnabled is -// a common way to check at runtime if GC is on. -// There are some places where GC doesn't work w/ things w/in Apple's -// frameworks, so this is here so GTM unittests and detect it, and not run -// individual tests to work around bugs in Apple's frameworks. -GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) { - return ([NSGarbageCollector defaultCollector] != nil); -} - -#else - -#define GTMNSMakeCollectable(cf) ((id)(cf)) - -GTM_INLINE void GTMNSMakeUncollectable(id object) { -} - -GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) { - return NO; -} - -#endif - -// GTMCFAutorelease makes a CF object collectable in GC mode, or adds it -// to the autorelease pool in non-GC mode. Either way it is taken care -// of. Done as a define instead of an inline so that tools like Clang's -// scan-build don't report code as leaking. -#define GTMCFAutorelease(cf) ([GTMNSMakeCollectable(cf) autorelease]) - diff --git a/Foundation/GTMLogger.m b/Foundation/GTMLogger.m index 4b40747..424f3c0 100644 --- a/Foundation/GTMLogger.m +++ b/Foundation/GTMLogger.m @@ -17,7 +17,6 @@ // #import "GTMLogger.h" -#import "GTMGarbageCollection.h" #import #import #import diff --git a/Foundation/GTMNSAppleScript+Handler.h b/Foundation/GTMNSAppleScript+Handler.h index 8fcb8fc..ba4fe72 100644 --- a/Foundation/GTMNSAppleScript+Handler.h +++ b/Foundation/GTMNSAppleScript+Handler.h @@ -19,13 +19,6 @@ #import #import "GTMDefines.h" -// :::WARNING::: NSAppleScript and Garbage Collect (GC) -// -// As of 10.5.6 (and below) Apple has bugs in NSAppleScript when running with -// GC; ie-things crash that have nothing to do w/ this or your code. See -// http://rails.wincent.com/issues/640 for a good amount of detail about the -// problems and simple cases that show it. - // A category for calling handlers in NSAppleScript enum { diff --git a/Foundation/GTMNSAppleScript+Handler.m b/Foundation/GTMNSAppleScript+Handler.m index 34b21c6..e17ba91 100644 --- a/Foundation/GTMNSAppleScript+Handler.m +++ b/Foundation/GTMNSAppleScript+Handler.m @@ -203,7 +203,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); if (propertyName && desc) { NSAppleScript *script = self; OSAID valueID = kOSANullScript; - ComponentInstance component; + ComponentInstance component = NULL; OSAID scriptID = [script gtm_realIDAndComponent:&component]; error = OSACoerceFromDesc(component, [desc aeDesc], @@ -256,7 +256,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); } - (BOOL)gtm_hasOpenDocumentsHandler { - ComponentInstance component; + ComponentInstance component = NULL; OSAID osaID = [self gtm_realIDAndComponent:&component]; long value = 0; OSAError error = OSAGetScriptInfo(component, @@ -332,7 +332,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); NSAppleEventDescriptor *propertyName = [self gtm_descriptorForPropertyValue:property]; if (propertyName) { - ComponentInstance component; + ComponentInstance component = NULL; OSAID scriptID = [self gtm_realIDAndComponent:&component]; OSAID valueID = kOSANullScript; error = OSAGetProperty(component, @@ -380,7 +380,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); GTMAssertRunningOnMainThread(); AEDescList names = { typeNull, NULL }; NSArray *array = nil; - ComponentInstance component; + ComponentInstance component = NULL; OSAID osaID = [self gtm_realIDAndComponent:&component]; OSAError error = OSAGetHandlerNames(component, kOSAModeNull, osaID, &names); if (error == noErr) { @@ -399,7 +399,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); GTMAssertRunningOnMainThread(); AEDescList names = { typeNull, NULL }; NSArray *array = nil; - ComponentInstance component; + ComponentInstance component = NULL; OSAID osaID = [self gtm_realIDAndComponent:&component]; OSAError error = OSAGetPropertyNames(component, kOSAModeNull, osaID, &names); if (error == noErr) { @@ -495,7 +495,7 @@ GTM_METHOD_CHECK(NSAppleEventDescriptor, gtm_registerSelector:forTypes:count:); if (!error) { NSAppleEventDescriptor *desc = nil; NSAppleEventDescriptor *event = [data objectForKey:GTMNSAppleScriptEventKey]; - ComponentInstance component; + ComponentInstance component = NULL; OSAID scriptID = [self gtm_realIDAndComponent:&component]; OSAID valueID; OSAError err = OSAExecuteEvent(component, [event aeDesc], scriptID, diff --git a/Foundation/GTMNSAppleScript+HandlerTest.m b/Foundation/GTMNSAppleScript+HandlerTest.m index 16886a8..6a064dd 100644 --- a/Foundation/GTMNSAppleScript+HandlerTest.m +++ b/Foundation/GTMNSAppleScript+HandlerTest.m @@ -21,7 +21,6 @@ #import "GTMNSAppleScript+Handler.h" #import "GTMNSAppleEventDescriptor+Foundation.h" #import "GTMUnitTestDevLog.h" -#import "GTMGarbageCollection.h" #import "GTMSystemVersion.h" #import "GTMFourCharCode.h" @@ -37,21 +36,6 @@ @end @implementation GTMNSAppleScript_HandlerTest -- (void)invokeTest { - // NOTE: These tests are disabled in GC is on. See the comment/warning in the - // GTMNSAppleScript+Handler.h for more details, but we disable them to avoid - // the tests failing (crashing) when it's Apple's bug. Please bump the system - // check as appropriate when new systems are tested. Currently broken on - // 10.5.8 and below. Radar 6126682. - SInt32 major, minor, bugfix; - [GTMSystemVersion getMajor:&major minor:&minor bugFix:&bugfix]; - BOOL gcEnabled = GTMIsGarbageCollectionEnabled(); - if (gcEnabled && major <= 10 && minor <= 5 && bugfix <= 8) { - NSLog(@"--- %@ NOT run because of GC incompatibilites ---", [self name]); - } else { - [super invokeTest]; - } -} - (void)setUp { NSBundle *bundle diff --git a/Foundation/GTMNSDictionary+CaseInsensitive.m b/Foundation/GTMNSDictionary+CaseInsensitive.m index a207000..96494c2 100644 --- a/Foundation/GTMNSDictionary+CaseInsensitive.m +++ b/Foundation/GTMNSDictionary+CaseInsensitive.m @@ -18,7 +18,6 @@ #import "GTMNSDictionary+CaseInsensitive.h" #import "GTMDefines.h" -#import "GTMGarbageCollection.h" #import @interface NSMutableDictionary (GTMNSMutableDictionaryCaseInsensitiveAdditions) @@ -85,14 +84,9 @@ static CFHashCode CaseInsensitiveHashCallback(const void *value) { keyCallbacks.equal = CaseInsensitiveEqualCallback; keyCallbacks.hash = CaseInsensitiveHashCallback; - // GTMNSMakeCollectable drops the retain count in GC mode so the object can - // be garbage collected. - // GTMNSMakeCollectable not GTMCFAutorelease because this is an initializer - // and in non-GC mode we need to return a +1 retain count object. - self = GTMNSMakeCollectable( - CFDictionaryCreate(kCFAllocatorDefault, - keys, values, count, &keyCallbacks, - &kCFTypeDictionaryValueCallBacks)); + self = (id)CFDictionaryCreate(kCFAllocatorDefault, + keys, values, count, &keyCallbacks, + &kCFTypeDictionaryValueCallBacks); free(keys); free(values); @@ -111,13 +105,8 @@ static CFHashCode CaseInsensitiveHashCallback(const void *value) { - (id)gtm_initWithDictionaryCaseInsensitive:(NSDictionary *)dictionary { if ((self = [super gtm_initWithDictionaryCaseInsensitive:dictionary])) { - // GTMNSMakeCollectable drops the retain count in GC mode so the object can - // be garbage collected. - // GTMNSMakeCollectable not GTMCFAutorelease because this is an initializer - // and in non-GC mode we need to return a +1 retain count object. - id copy = GTMNSMakeCollectable( - CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, - (CFDictionaryRef)self)); + id copy = (id)CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, + (CFDictionaryRef)self); [self release]; self = copy; } diff --git a/Foundation/GTMNSFileManager+Carbon.m b/Foundation/GTMNSFileManager+Carbon.m index 9b91a4d..8c51f66 100644 --- a/Foundation/GTMNSFileManager+Carbon.m +++ b/Foundation/GTMNSFileManager+Carbon.m @@ -20,7 +20,6 @@ #import #import #import "GTMDefines.h" -#import "GTMGarbageCollection.h" @implementation NSFileManager (GTMFileManagerCarbonAdditions) diff --git a/Foundation/GTMNSString+FindFolder.m b/Foundation/GTMNSString+FindFolder.m index 2e847e3..1e1b50a 100644 --- a/Foundation/GTMNSString+FindFolder.m +++ b/Foundation/GTMNSString+FindFolder.m @@ -17,7 +17,7 @@ // #import "GTMNSString+FindFolder.h" -#import "GTMGarbageCollection.h" +#import "GTMDefines.h" @implementation NSString (GTMStringFindFolderAdditions) diff --git a/Foundation/GTMNSString+URLArguments.m b/Foundation/GTMNSString+URLArguments.m index 46d2c99..90c65c5 100644 --- a/Foundation/GTMNSString+URLArguments.m +++ b/Foundation/GTMNSString+URLArguments.m @@ -17,7 +17,8 @@ // #import "GTMNSString+URLArguments.h" -#import "GTMGarbageCollection.h" + +#import "GTMDefines.h" @implementation NSString (GTMNSStringURLArgumentsAdditions) diff --git a/Foundation/GTMNSString+XML.m b/Foundation/GTMNSString+XML.m index 0e16ddb..2e165e6 100644 --- a/Foundation/GTMNSString+XML.m +++ b/Foundation/GTMNSString+XML.m @@ -18,7 +18,6 @@ #import "GTMDefines.h" #import "GTMNSString+XML.h" -#import "GTMGarbageCollection.h" enum { kGTMXMLCharModeEncodeQUOT = 0, diff --git a/Foundation/GTMSQLite.m b/Foundation/GTMSQLite.m index 29980ae..502a5cc 100644 --- a/Foundation/GTMSQLite.m +++ b/Foundation/GTMSQLite.m @@ -27,7 +27,6 @@ #import "GTMMethodCheck.h" #import "GTMDefines.h" #include -#import "GTMGarbageCollection.h" typedef struct { BOOL upperCase; diff --git a/Foundation/GTMSQLiteTest.m b/Foundation/GTMSQLiteTest.m index a158a4f..8a5f18d 100644 --- a/Foundation/GTMSQLiteTest.m +++ b/Foundation/GTMSQLiteTest.m @@ -20,7 +20,6 @@ #import "GTMSQLite.h" #import "GTMSenTestCase.h" #import "GTMUnitTestDevLog.h" -#import "GTMGarbageCollection.h" @interface GTMSQLiteTest : GTMTestCase @end @@ -1744,51 +1743,47 @@ static NSArray* LikeGlobTestHelper(GTMSQLiteDatabase *db, NSString *sql) { } - (void)testThatNotFinalizingStatementsThrowsAssertion { - // The run-time check is discouraged, but we're using it because the - // same test binary is used for both GC & Non-GC runs - if (!GTMIsGarbageCollectionEnabled()) { - NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init]; - int err; - GTMSQLiteDatabase *db = - [[[GTMSQLiteDatabase alloc] initInMemoryWithCFAdditions:YES - utf8:YES - errorCode:&err] - autorelease]; + int err; + GTMSQLiteDatabase *db = + [[[GTMSQLiteDatabase alloc] initInMemoryWithCFAdditions:YES + utf8:YES + errorCode:&err] + autorelease]; - STAssertNotNil(db, @"Failed to create database"); + STAssertNotNil(db, @"Failed to create database"); - sqlite3 *sqlite3DB = [db sqlite3DB]; - - NSString *selectSQL = @"select 1"; - GTMSQLiteStatement *statement; - statement = [GTMSQLiteStatement statementWithSQL:selectSQL - inDatabase:db - errorCode:&err]; - STAssertNotNil(statement, @"Failed to create select statement"); - STAssertEquals(err, SQLITE_OK, @"Failed to create select statement"); + sqlite3 *sqlite3DB = [db sqlite3DB]; + + NSString *selectSQL = @"select 1"; + GTMSQLiteStatement *statement; + statement = [GTMSQLiteStatement statementWithSQL:selectSQL + inDatabase:db + errorCode:&err]; + STAssertNotNil(statement, @"Failed to create select statement"); + STAssertEquals(err, SQLITE_OK, @"Failed to create select statement"); - sqlite3_stmt *sqlite3Statment = [statement sqlite3Statement]; + sqlite3_stmt *sqlite3Statment = [statement sqlite3Statement]; - err = [statement stepRow]; - STAssertEquals(err, SQLITE_ROW, - @"failed to step row for finalize test"); + err = [statement stepRow]; + STAssertEquals(err, SQLITE_ROW, + @"failed to step row for finalize test"); - NSString *expectedLog = - @"-[GTMSQLiteStatement finalizeStatement] must be called " - @"when statement is no longer needed"; + NSString *expectedLog = + @"-[GTMSQLiteStatement finalizeStatement] must be called " + @"when statement is no longer needed"; - [GTMUnitTestDevLog expectString:@"%@", expectedLog]; - [GTMUnitTestDevLog expectPattern:@"Unable to close .*"]; - [localPool drain]; - - // Clean up leaks. Since we hadn't finalized the statement above we - // were unable to clean up the sqlite databases. Since the pool is drained - // all of our objective-c objects are gone, so we have to call the - // sqlite3 api directly. - STAssertEquals(sqlite3_finalize(sqlite3Statment), SQLITE_OK, nil); - STAssertEquals(sqlite3_close(sqlite3DB), SQLITE_OK, nil); - } + [GTMUnitTestDevLog expectString:@"%@", expectedLog]; + [GTMUnitTestDevLog expectPattern:@"Unable to close .*"]; + [localPool drain]; + + // Clean up leaks. Since we hadn't finalized the statement above we + // were unable to clean up the sqlite databases. Since the pool is drained + // all of our objective-c objects are gone, so we have to call the + // sqlite3 api directly. + STAssertEquals(sqlite3_finalize(sqlite3Statment), SQLITE_OK, nil); + STAssertEquals(sqlite3_close(sqlite3DB), SQLITE_OK, nil); } - (void)testCompleteSQLString { diff --git a/Foundation/GTMServiceManagementTest.m b/Foundation/GTMServiceManagementTest.m index f23ceba..95ef0b4 100644 --- a/Foundation/GTMServiceManagementTest.m +++ b/Foundation/GTMServiceManagementTest.m @@ -21,7 +21,6 @@ #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 #import "GTMSenTestCase.h" -#import "GTMGarbageCollection.h" #import #define STANDARD_JOB_LABEL "com.apple.launchctl.Background" diff --git a/Foundation/GTMSystemVersion.m b/Foundation/GTMSystemVersion.m index 9bd969c..2a84168 100644 --- a/Foundation/GTMSystemVersion.m +++ b/Foundation/GTMSystemVersion.m @@ -17,7 +17,6 @@ // #import "GTMSystemVersion.h" -#import "GTMGarbageCollection.h" #import "GTMObjC2Runtime.h" #if GTM_MACOS_SDK #import @@ -134,7 +133,6 @@ static NSString *const kSystemVersionPlistPath = @"/System/Library/CoreServices/ NSDictionary *systemVersionPlist = [NSDictionary dictionaryWithContentsOfFile:kSystemVersionPlistPath]; sBuild = [[systemVersionPlist objectForKey:@"ProductBuildVersion"] retain]; - GTMNSMakeUncollectable(sBuild); _GTMDevAssert(sBuild, @"Unable to get build version"); } } diff --git a/Foundation/GTMURITemplate.m b/Foundation/GTMURITemplate.m index 3240dee..7721d84 100644 --- a/Foundation/GTMURITemplate.m +++ b/Foundation/GTMURITemplate.m @@ -15,7 +15,7 @@ #import "GTMURITemplate.h" -#import "GTMGarbageCollection.h" +#import "GTMDefines.h" #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 -- cgit v1.2.3