From a43107b29c2236d47e447c9039674b9040a9ec25 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Thu, 14 Jun 2012 12:00:23 +0000 Subject: [Author: thomasvl] Pile of fixes for trunk version of clang. R=dmaclach DELTA=59 (26 added, 0 deleted, 33 changed) --- Foundation/GTMLoggerTest.m | 6 ++--- Foundation/GTMNSFileHandle+UniqueNameTest.m | 6 ++--- Foundation/GTMNSFileManager+Path.h | 4 +-- Foundation/GTMNSFileManager+Path.m | 40 ++++++++++++++--------------- Foundation/GTMNSFileManager+PathTest.m | 10 ++++---- Foundation/GTMNSString+URLArgumentsTest.m | 4 +-- Foundation/GTMPath.m | 33 ++++++++++++++++-------- Foundation/GTMPathTest.m | 13 +++++++--- Foundation/GTMStackTrace.m | 12 ++++----- GTMDefines.h | 2 +- GTMiPhone.xcodeproj/project.pbxproj | 4 +-- UnitTesting/GTMDevLogUnitTestingBridge.m | 5 +++- UnitTesting/GTMUnitTestDevLog.m | 3 +++ 13 files changed, 84 insertions(+), 58 deletions(-) diff --git a/Foundation/GTMLoggerTest.m b/Foundation/GTMLoggerTest.m index 2211499..36e9a88 100644 --- a/Foundation/GTMLoggerTest.m +++ b/Foundation/GTMLoggerTest.m @@ -95,7 +95,7 @@ @"GTMLoggerUnitTest.log"] retain]; STAssertNotNil(path_, nil); // Make sure we're cleaned up from the last run -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [[NSFileManager defaultManager] removeFileAtPath:path_ handler:nil]; #else [[NSFileManager defaultManager] removeItemAtPath:path_ error:NULL]; @@ -104,7 +104,7 @@ - (void)tearDown { STAssertNotNil(path_, nil); -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [[NSFileManager defaultManager] removeFileAtPath:path_ handler:nil]; #else [[NSFileManager defaultManager] removeItemAtPath:path_ error:NULL]; @@ -407,7 +407,7 @@ msg = [self stringFromFormatter:fmtr level:kGTMLoggerLevelDebug - format:@" ", 1]; + format:@" "]; STAssertEqualObjects(msg, @" ", nil); } diff --git a/Foundation/GTMNSFileHandle+UniqueNameTest.m b/Foundation/GTMNSFileHandle+UniqueNameTest.m index 833edc9..34453a0 100644 --- a/Foundation/GTMNSFileHandle+UniqueNameTest.m +++ b/Foundation/GTMNSFileHandle+UniqueNameTest.m @@ -95,7 +95,7 @@ STAssertNil(handle, nil); STAssertNil(newPath, nil); -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [fm removeFileAtPath:tempDir handler:nil]; #else // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 [fm removeItemAtPath:tempDir error:nil]; @@ -121,7 +121,7 @@ STAssertNotNil(handle, nil); STAssertNotNil(path, nil); STAssertTrue([fm fileExistsAtPath:path], nil); -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [fm removeFileAtPath:path handler:nil]; #else // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 [fm removeItemAtPath:path error:nil]; @@ -156,7 +156,7 @@ BOOL isDirectory = NO; STAssertTrue([fm fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory, nil); -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [fm removeFileAtPath:path handler:nil]; #else // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 [fm removeItemAtPath:path error:nil]; diff --git a/Foundation/GTMNSFileManager+Path.h b/Foundation/GTMNSFileManager+Path.h index f377215..7c12158 100644 --- a/Foundation/GTMNSFileManager+Path.h +++ b/Foundation/GTMNSFileManager+Path.h @@ -22,7 +22,7 @@ /// A few useful methods for dealing with paths. @interface NSFileManager (GMFileManagerPathAdditions) -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) /// For the Unix-y at heart, this is "mkdir -p". It tries to create /// the directory specified by |path|, and any intervening directories that @@ -47,7 +47,7 @@ - (BOOL)gtm_createFullPathToDirectory:(NSString *)path attributes:(NSDictionary *)attributes; -#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#endif // GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) /// Return an the paths for all resources in |directoryPath| that have the /// |extension| file extension. diff --git a/Foundation/GTMNSFileManager+Path.m b/Foundation/GTMNSFileManager+Path.m index 6ec298b..a22258a 100644 --- a/Foundation/GTMNSFileManager+Path.m +++ b/Foundation/GTMNSFileManager+Path.m @@ -6,9 +6,9 @@ // 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 @@ -21,7 +21,7 @@ @implementation NSFileManager (GMFileManagerPathAdditions) -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) - (BOOL)gtm_createFullPathToDirectory:(NSString *)path attributes:(NSDictionary *)attributes { @@ -29,17 +29,17 @@ BOOL isDir; BOOL exists = [self fileExistsAtPath:path isDirectory:&isDir]; - + // Quick check for the case where we have nothing to do. if (exists && isDir) return YES; - + NSString *actualPath = @"/"; NSString *directory; - + GTM_FOREACH_OBJECT(directory, [path pathComponents]) { actualPath = [actualPath stringByAppendingPathComponent:directory]; - + if ([self fileExistsAtPath:actualPath isDirectory:&isDir] && isDir) { continue; } else if ([self createDirectoryAtPath:actualPath attributes:attributes]) { @@ -48,20 +48,20 @@ return NO; } } - + return YES; } -#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#endif // GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) - (NSArray *)gtm_filePathsWithExtension:(NSString *)extension inDirectory:(NSString *)directoryPath { NSArray *extensions = nil; - + // Treat no extension and an empty extension as the user requesting all files if (extension != nil && ![extension isEqualToString:@""]) extensions = [NSArray arrayWithObject:extension]; - + return [self gtm_filePathsWithExtensions:extensions inDirectory:directoryPath]; } @@ -71,39 +71,39 @@ if (!directoryPath) { return nil; } - + // |basenames| will contain only the matching file names, not their full paths. -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - NSArray *basenames = [self contentsOfDirectoryAtPath:directoryPath +#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) + NSArray *basenames = [self contentsOfDirectoryAtPath:directoryPath error:nil]; #else NSArray *basenames = [self directoryContentsAtPath:directoryPath]; #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 - + // Check if dir doesn't exist or couldn't be opened. if (!basenames) { return nil; } - + // Check if dir is empty. if ([basenames count] == 0) { return basenames; } - + NSMutableArray *paths = [NSMutableArray arrayWithCapacity:[basenames count]]; NSString *basename; - + // Convert all the |basenames| to full paths. GTM_FOREACH_OBJECT(basename, basenames) { NSString *fullPath = [directoryPath stringByAppendingPathComponent:basename]; [paths addObject:fullPath]; } - + // Check if caller wants all files, regardless of extension. if ([extensions count] == 0) { return paths; } - + return [paths pathsMatchingExtensions:extensions]; } diff --git a/Foundation/GTMNSFileManager+PathTest.m b/Foundation/GTMNSFileManager+PathTest.m index db51c9b..cfcab0c 100644 --- a/Foundation/GTMNSFileManager+PathTest.m +++ b/Foundation/GTMNSFileManager+PathTest.m @@ -39,7 +39,7 @@ if (baseDir_) { // clean up our directory NSFileManager *fm = [NSFileManager defaultManager]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 +#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) NSError *error = nil; [fm removeItemAtPath:baseDir_ error:&error]; STAssertNil(error, @@ -53,7 +53,7 @@ } } -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) - (void)testCreateFullPathToDirectoryAttributes { STAssertNotNil(baseDir_, @"setUp failed"); @@ -82,7 +82,7 @@ @"Should have failed when passed (nil)"); } -#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 +#endif // GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) - (void)testfilePathsWithExtensionsInDirectory { STAssertNotNil(baseDir_, @"setUp failed"); @@ -126,7 +126,7 @@ NSString *testDir = nil; if ([testDirs[i] length]) { testDir = [baseDir_ stringByAppendingPathComponent:testDirs[i]]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 +#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) NSError *error = nil; STAssertTrue([fm createDirectoryAtPath:testDir withIntermediateDirectories:YES @@ -236,7 +236,7 @@ // create the empty dir NSString *emptyDir = [baseDir_ stringByAppendingPathComponent:@"emptyDir"]; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 +#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) NSError *error = nil; STAssertTrue([fm createDirectoryAtPath:emptyDir withIntermediateDirectories:YES diff --git a/Foundation/GTMNSString+URLArgumentsTest.m b/Foundation/GTMNSString+URLArgumentsTest.m index 90a5a81..5555acf 100644 --- a/Foundation/GTMNSString+URLArgumentsTest.m +++ b/Foundation/GTMNSString+URLArgumentsTest.m @@ -82,13 +82,13 @@ STAssertEqualObjects([@"this%5Bthat" gtm_stringByUnescapingFromURLArgument], @"this[that", @"- left bracket should be unescaped"); STAssertEqualObjects([@"this%5Dthat" gtm_stringByUnescapingFromURLArgument], @"this]that", @"- right bracket should be unescaped"); // make sure a plus come back out as a space - STAssertEqualObjects([[NSString stringWithString:@"this+that"] gtm_stringByUnescapingFromURLArgument], @"this that", @"- plus should be unescaped"); + STAssertEqualObjects([@"this+that" gtm_stringByUnescapingFromURLArgument], @"this that", @"- plus should be unescaped"); // make sure plus and %2B are handled in the right order STAssertEqualObjects([@"this+that%2Bthe%20other" gtm_stringByUnescapingFromURLArgument], @"this that+the other", @"- pluses and spaces should be different"); // high char test NSString *tester = [NSString stringWithUTF8String:"caf\xC3\xA9"]; STAssertNotNil(tester, @"failed to create from utf8 run"); - STAssertEqualObjects([[NSString stringWithString:@"caf%C3%A9"] gtm_stringByUnescapingFromURLArgument], tester, @"- high chars should work"); + STAssertEqualObjects([@"caf%C3%A9" gtm_stringByUnescapingFromURLArgument], tester, @"- high chars should work"); } @end diff --git a/Foundation/GTMPath.m b/Foundation/GTMPath.m index da4b5a4..2a8c26e 100644 --- a/Foundation/GTMPath.m +++ b/Foundation/GTMPath.m @@ -41,7 +41,7 @@ return nil; } } - + return self; } @@ -77,8 +77,13 @@ - (NSDictionary *)attributes { NSFileManager *mgr = [NSFileManager defaultManager]; - NSDictionary *attributes = [mgr fileAttributesAtPath:fullPath_ - traverseLink:NO]; +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) + NSDictionary *attributes = [mgr fileAttributesAtPath:fullPath_ + traverseLink:NO]; +#else + NSDictionary *attributes = [mgr attributesOfItemAtPath:fullPath_ + error:NULL]; +#endif return attributes; } @@ -101,9 +106,9 @@ - (GTMPath *)createDirectoryName:(NSString *)name attributes:(NSDictionary *)attributes { if ([name length] == 0) return nil; - + // We first check to see if the requested directory alread exists by trying - // to create a GTMPath from the desired new path string. Only if the path + // to create a GTMPath from the desired new path string. Only if the path // doesn't already exist do we attempt to create it. If the path already // exists, we will end up returning a GTMPath for the pre-existing path. NSString *newPath = [fullPath_ stringByAppendingPathComponent:name]; @@ -111,10 +116,18 @@ if (nascentPath && ![nascentPath isDirectory]) { return nil; // Return nil because the path exists, but it's not a dir } - + if (!nascentPath) { NSFileManager *mgr = [NSFileManager defaultManager]; - BOOL created = [mgr createDirectoryAtPath:newPath attributes:attributes]; +#if GTM_IPHONE_SDK || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) + NSError *error = nil; + BOOL created = [mgr createDirectoryAtPath:newPath + withIntermediateDirectories:YES + attributes:attributes + error:&error]; +#else + BOOL created = [mgr createDirectoryAtPath:newPath attributes:nil] +#endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 nascentPath = created ? [GTMPath pathWithFullPath:newPath] : nil; } @@ -137,7 +150,7 @@ attributes:(NSDictionary *)attributes data:(NSData *)data { if ([name length] == 0) return nil; - + // See createDirectoryName:attribute: for some high-level notes about what and // why this method does what it does. NSString *newPath = [fullPath_ stringByAppendingPathComponent:name]; @@ -145,7 +158,7 @@ if (nascentPath != nil && [nascentPath isDirectory]) { return nil; // Return nil because the path exists, but it's a dir } - + if (nascentPath == nil) { BOOL created = [[NSFileManager defaultManager] createFileAtPath:newPath @@ -153,7 +166,7 @@ attributes:attributes]; nascentPath = created ? [GTMPath pathWithFullPath:newPath] : nil; } - + return nascentPath; } diff --git a/Foundation/GTMPathTest.m b/Foundation/GTMPathTest.m index 59e3199..308cc73 100644 --- a/Foundation/GTMPathTest.m +++ b/Foundation/GTMPathTest.m @@ -45,7 +45,11 @@ // Make sure it's safe to remove this directory before nuking it. STAssertNotNil(testDirectory_, nil); STAssertNotEqualObjects(testDirectory_, @"/", nil); +#if GTM_MACOSX_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) [[NSFileManager defaultManager] removeFileAtPath:testDirectory_ handler:nil]; +#else + [[NSFileManager defaultManager] removeItemAtPath:testDirectory_ error:NULL]; +#endif [testDirectory_ release]; } @@ -136,7 +140,8 @@ STAssertEqualObjects([path name], @"foo", nil); // filePosixPermissions has odd return types in different SDKs, so we use // STAssertTrue to avoid the macros type checks from choking us. - STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil); + STAssertTrue([[path attributes] filePosixPermissions] == 0555, + @"got %o", (int)[[path attributes] filePosixPermissions]); STAssertTrue([path isDirectory], nil); STAssertFalse([path isRoot], nil); @@ -148,14 +153,16 @@ path = [tmp createDirectoryName:@"foo" mode:0555]; STAssertNotNil(path, nil); STAssertEqualObjects([path name], @"foo", nil); - STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil); + STAssertTrue([[path attributes] filePosixPermissions] == 0555, + @"got %o", (int)[[path attributes] filePosixPermissions]); STAssertTrue([path isDirectory], nil); STAssertFalse([path isRoot], nil); GTMPath *foo = [GTMPath pathWithFullPath:fooPath]; STAssertNotNil(foo, nil); STAssertEqualObjects([path name], @"foo", nil); - STAssertTrue([[path attributes] filePosixPermissions] == 0555, nil); + STAssertTrue([[path attributes] filePosixPermissions] == 0555, + @"got %o", (int)[[path attributes] filePosixPermissions]); STAssertTrue([path isDirectory], nil); STAssertFalse([path isRoot], nil); } diff --git a/Foundation/GTMStackTrace.m b/Foundation/GTMStackTrace.m index 8019867..8b482e6 100644 --- a/Foundation/GTMStackTrace.m +++ b/Foundation/GTMStackTrace.m @@ -172,24 +172,24 @@ static NSString *GTMStackTraceFromAddressDescriptors(struct GTMAddressDescriptor fileName = @"??"; } if (descs[i].class_name) { - [trace appendFormat:@"#%-2u %-35s %0*p %s[%s %s]", + [trace appendFormat:@"#%-2u %-35s %0*lX %s[%s %s]", i, [fileName UTF8String], // sizeof(void*) * 2 is the length of the hex address (32 vs 64) and + 2 // for the 0x prefix - sizeof(void *) * 2 + 2, - descs[i].address, + (int)(sizeof(void *) * 2 + 2), + (unsigned long)descs[i].address, (descs[i].is_class_method ? "+" : "-"), descs[i].class_name, (descs[i].symbol ? descs[i].symbol : "??")]; } else { - [trace appendFormat:@"#%-2u %-35s %0*p %s()", + [trace appendFormat:@"#%-2u %-35s %0*lX %s()", i, [fileName UTF8String], // sizeof(void*) * 2 is the length of the hex address (32 vs 64) and + 2 // for the 0x prefix - sizeof(void *) * 2 + 2, - descs[i].address, + (int)(sizeof(void *) * 2 + 2), + (unsigned long)descs[i].address, (descs[i].symbol ? descs[i].symbol : "??")]; } } diff --git a/GTMDefines.h b/GTMDefines.h index 630885c..59a1723 100644 --- a/GTMDefines.h +++ b/GTMDefines.h @@ -374,7 +374,7 @@ // Declared here so that it can easily be used for logging tracking if // necessary. See GTMUnitTestDevLog.h for details. @class NSString; -GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...); +GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2); // Macro to allow you to create NSStrings out of other macros. // #define FOO foo diff --git a/GTMiPhone.xcodeproj/project.pbxproj b/GTMiPhone.xcodeproj/project.pbxproj index d241ce9..6d8c89d 100644 --- a/GTMiPhone.xcodeproj/project.pbxproj +++ b/GTMiPhone.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 45; + objectVersion = 46; objects = { /* Begin PBXAggregateTarget section */ @@ -919,7 +919,7 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "GTMiPhone" */; - compatibilityVersion = "Xcode 3.1"; + compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( diff --git a/UnitTesting/GTMDevLogUnitTestingBridge.m b/UnitTesting/GTMDevLogUnitTestingBridge.m index 3d2b84d..ccad535 100644 --- a/UnitTesting/GTMDevLogUnitTestingBridge.m +++ b/UnitTesting/GTMDevLogUnitTestingBridge.m @@ -31,14 +31,17 @@ // // See GTMUnitTestDevLog.h for more information on checking logs in unittests. // -void _GTMUnitTestDevLog(NSString *format, ...) { +void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2) { Class devLogClass = NSClassFromString(@"GTMUnitTestDevLog"); va_list argList; va_start(argList, format); if (devLogClass) { [devLogClass log:format args:argList]; } else { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" NSLogv(format, argList); // COV_NF_LINE the class is in all our unittest setups +#pragma GCC diagnostic pop } va_end(argList); } diff --git a/UnitTesting/GTMUnitTestDevLog.m b/UnitTesting/GTMUnitTestDevLog.m index b35e1bb..aaf1c8f 100644 --- a/UnitTesting/GTMUnitTestDevLog.m +++ b/UnitTesting/GTMUnitTestDevLog.m @@ -192,7 +192,10 @@ static BOOL gTrackingEnabled = NO; } } } else { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" NSLogv(format, args); +#pragma GCC diagnostic pop } } -- cgit v1.2.3