From 8d42cc25b65785ff2752a079ace0ece64906ab6b Mon Sep 17 00:00:00 2001 From: Jordy Dickinson Date: Tue, 11 Oct 2016 10:00:45 -0400 Subject: [PATCH 1/4] Remove support for 10.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I also fixed some linker errors that appeared when switching to 10.8 deployment target. Note that my system is 10.12, so I can’t _fully_ test 10.8 compatibility. --- ...CrossPersistentRootDeadRelationshipCache.h | 4 -- ...CrossPersistentRootDeadRelationshipCache.m | 11 ----- Core/COPrimitiveCollection.m | 40 +++---------------- CoreObject.xcodeproj/project.pbxproj | 30 ++++++++++++-- .../xcschemes/BasicPersistence.xcscheme | 2 +- .../xcschemes/BenchmarkCoreObject.xcscheme | 2 +- .../xcschemes/CoreObject.xcscheme | 2 +- .../xcschemes/TestCoreObject.xcscheme | 2 +- Debugging/COSQLiteStore+Graphviz.m | 7 +--- StorageDataModel/COItem+JSON.m | 18 +-------- Store/COSQLiteStore.m | 8 ---- Tests/StorageDataModel/TestItem.m | 6 +-- Tests/TestCommon.m | 2 - Undo/COUndoTrackStore+Private.h | 10 ++--- Undo/COUndoTrackStore.m | 9 ----- 15 files changed, 46 insertions(+), 107 deletions(-) diff --git a/Core/COCrossPersistentRootDeadRelationshipCache.h b/Core/COCrossPersistentRootDeadRelationshipCache.h index c809b80c1..146eff1d4 100644 --- a/Core/COCrossPersistentRootDeadRelationshipCache.h +++ b/Core/COCrossPersistentRootDeadRelationshipCache.h @@ -56,10 +56,6 @@ NS_ASSUME_NONNULL_BEGIN * When a persistent root or branch is unloaded, any matching paths should be * kept in the cache, in case it gets reloaded later (we cannot figure out cross * persistent root incoming relationships from the reloading). - * - * For referring object graph contexts, when unloaded or finalized, the - * deallocation will trigger their removal of their inner objects from the hash - * tables in the cache on 10.8 or iOS 6 or higher, but not on 10.7. */ - (void)removePath: (COPath *)aPath; diff --git a/Core/COCrossPersistentRootDeadRelationshipCache.m b/Core/COCrossPersistentRootDeadRelationshipCache.m index 1cdcf6c32..de2e4e8ee 100644 --- a/Core/COCrossPersistentRootDeadRelationshipCache.m +++ b/Core/COCrossPersistentRootDeadRelationshipCache.m @@ -16,11 +16,7 @@ - (instancetype)init { SUPERINIT; _pathToReferringObjects = [NSMutableDictionary new]; -#if TARGET_OS_IPHONE _referringObjectToPaths = [NSMapTable weakToStrongObjectsMapTable]; -#else - _referringObjectToPaths = [NSMapTable mapTableWithWeakToStrongObjects]; -#endif return self; } @@ -32,14 +28,7 @@ - (void)addReferringObject: (COObject *)aReferrer if (referringObjects == nil) { - // FIXME: If we don't ditch 10.7 support, we need a reverse mapping - // from each referringObject to a path set, that can be used to remove - // the referring objects when their object graph context is discarded. -#if TARGET_OS_IPHONE referringObjects = [NSHashTable weakObjectsHashTable]; -#else - referringObjects = [NSHashTable hashTableWithWeakObjects]; -#endif _pathToReferringObjects[aPath] = referringObjects; } diff --git a/Core/COPrimitiveCollection.m b/Core/COPrimitiveCollection.m index babdb042b..cb569b072 100644 --- a/Core/COPrimitiveCollection.m +++ b/Core/COPrimitiveCollection.m @@ -83,11 +83,7 @@ - (BOOL)isMutable - (NSPointerArray *)makeBacking { -#if TARGET_OS_IPHONE return [NSPointerArray strongObjectsPointerArray]; -#else - return [NSPointerArray pointerArrayWithStrongObjects]; -#endif } - (instancetype)init @@ -250,26 +246,14 @@ - (void)insertObject: (id)anObject atIndex: (NSUInteger)index COThrowExceptionIfNotMutable(_permanentlyMutable, _temporaryMutable); COThrowExceptionIfOutOfBounds(self, index, YES); - // NSPointerArray on 10.7 doesn't allow inserting at the end using index == count, so - // call addPointer in that case as a workaround. - if (index == _externalIndexToBackingIndex.count) - { - // insert at end - [_externalIndexToBackingIndex addPointer: (void *)_backing.count]; - [_backing addPointer: (__bridge void *)anObject]; - } - else - { - // insert in the beginning or middle - NSUInteger backingIndex = [self backingIndex: index]; + NSUInteger backingIndex = [self backingIndex: index]; - [self shiftBackingIndicesGreaterThanOrEqualTo: backingIndex by: 1]; + [self shiftBackingIndicesGreaterThanOrEqualTo: backingIndex by: 1]; - [_externalIndexToBackingIndex insertPointer: (void *)backingIndex - atIndex: index]; - [_backing insertPointer: (__bridge void *)anObject - atIndex: backingIndex]; - } + [_externalIndexToBackingIndex insertPointer: (void *)backingIndex + atIndex: index]; + [_backing insertPointer: (__bridge void *)anObject + atIndex: backingIndex]; } - (void)removeLastObject @@ -366,20 +350,12 @@ @implementation COUnsafeRetainedMutableArray - (NSPointerArray *)makeBacking { -#if TARGET_OS_IPHONE return [NSPointerArray weakObjectsPointerArray]; -#else - return [NSPointerArray pointerArrayWithWeakObjects]; -#endif } - (NSHashTable *)makeBackingHashTable { -#if TARGET_OS_IPHONE return [NSHashTable weakObjectsHashTable]; -#else - return [NSHashTable hashTableWithWeakObjects]; -#endif } - (instancetype)initWithObjects: (const id[])objects count: (NSUInteger)count @@ -672,11 +648,7 @@ @implementation COUnsafeRetainedMutableSet - (NSHashTable *)makeBacking { -#if TARGET_OS_IPHONE return [NSHashTable weakObjectsHashTable]; -#else - return [NSHashTable hashTableWithWeakObjects]; -#endif } @end diff --git a/CoreObject.xcodeproj/project.pbxproj b/CoreObject.xcodeproj/project.pbxproj index b3b08988e..8e465c9db 100644 --- a/CoreObject.xcodeproj/project.pbxproj +++ b/CoreObject.xcodeproj/project.pbxproj @@ -2958,7 +2958,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = ""; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Étoilé"; TargetAttributes = { 60E08C6119792BEA00D1B7AD = { @@ -4248,23 +4248,35 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_GENERATE_TEST_COVERAGE_FILES = YES; GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.8; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-DDEBUG"; SDKROOT = macosx; @@ -4279,18 +4291,30 @@ C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; + CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES; CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.8; SDKROOT = macosx; WARNING_CFLAGS = ( "-Wall", diff --git a/CoreObject.xcodeproj/xcshareddata/xcschemes/BasicPersistence.xcscheme b/CoreObject.xcodeproj/xcshareddata/xcschemes/BasicPersistence.xcscheme index 1049ebc42..c14d49ea1 100644 --- a/CoreObject.xcodeproj/xcshareddata/xcschemes/BasicPersistence.xcscheme +++ b/CoreObject.xcodeproj/xcshareddata/xcschemes/BasicPersistence.xcscheme @@ -1,6 +1,6 @@ COItem attribute value -/* - * Returning the parsed value as a NSNumber rather a NSDecimalNumber to ensure - * the rounding is the same than the serialized NSNumber object. - * - * Without this workaround, 123.456789012 roundtrip doesn't succeed on 10.7 (see - * -testJSONDoubleEquality in TestItem.m)). - * - * For 123.456789012, NSJSONSerialization returns a NSDecimalNumber, but the - * rounding doesn't produce the same internal representation than a NSNumber - * initialized with the same double value. - */ -static inline NSNumber *basicNumberFromDecimalNumber(NSNumber *aValue) -{ - return @(aValue.description.doubleValue); -} - static id valueForPrimitivePlistValue(id aValue, COType aType) { if (aValue == [NSNull null]) @@ -195,7 +179,7 @@ static id valueForPrimitivePlistValue(id aValue, COType aType) case kCOTypeInt64: return aValue; case kCOTypeDouble: - return basicNumberFromDecimalNumber(aValue); + return aValue; case kCOTypeString: return aValue; case kCOTypeAttachment: diff --git a/Store/COSQLiteStore.m b/Store/COSQLiteStore.m index 4a03a79bf..be5601aad 100644 --- a/Store/COSQLiteStore.m +++ b/Store/COSQLiteStore.m @@ -124,14 +124,6 @@ - (void)dealloc [db_ close]; db_ = nil; }); - -#if !(TARGET_OS_IPHONE) - // N.B.: We are using deployment target 10.7, so ARC does not manage libdispatch objects. - // If we switch to deployment target 10.8, ARC will manage libdispatch objects automatically. - // For GNUstep, ARC doesn't manage libdispatch objects since libobjc2 doesn't support it - // currently (we compile CoreObject with -DOS_OBJECT_USE_OBJC=0). - dispatch_release(queue_); -#endif } - (BOOL)setupSchema diff --git a/Tests/StorageDataModel/TestItem.m b/Tests/StorageDataModel/TestItem.m index 6904b7e9f..3a1a49ed8 100644 --- a/Tests/StorageDataModel/TestItem.m +++ b/Tests/StorageDataModel/TestItem.m @@ -82,16 +82,12 @@ - (void)testJSONDoubleEquality NSNumber *newValueFromDesc = @(roundTripValue.description.doubleValue); #ifndef GNUSTEP - // NOTE: Doesn't matter on GNUstep since newValue is not a NSDecimalNumber, - // and we don't have to convert it into a NSDoubleNumber (unlike on 10.7). + // NOTE: Doesn't matter on GNUstep since newValue is not a NSDecimalNumber. UKTrue([[NSDecimalNumber defaultBehavior] scale] == NSDecimalNoScale); #endif NSLog(@"Double representation in JSON: %@", [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]); - - /* Rounding is visible in the ouput for numbers that contain more than two - decimals on 10.7 (e.g. 123.45 output is the same for all numbers). */ NSLog(@"value doubleValue: %.20f, description: %@, class: %@", value.doubleValue, value, [value class]); NSLog(@"decimalValue doubleValue: %.20f, description: %@, class: %@", diff --git a/Tests/TestCommon.m b/Tests/TestCommon.m index 1e0052398..22fffeb47 100644 --- a/Tests/TestCommon.m +++ b/Tests/TestCommon.m @@ -91,8 +91,6 @@ - (instancetype)init - (void)dealloc { #ifdef DELETE_STORE_AFTER_EACH_TEST_METHOD - // FIXME: For Mac OS X 10.7, this is unsupported, SQLite disk errors - // (DB Error: 10 "disk I/O error") appear in TestStoreSQLite.m. [[self class] deleteStores]; #endif } diff --git a/Undo/COUndoTrackStore+Private.h b/Undo/COUndoTrackStore+Private.h index 67d63afc7..5dc3bd061 100644 --- a/Undo/COUndoTrackStore+Private.h +++ b/Undo/COUndoTrackStore+Private.h @@ -11,22 +11,22 @@ @class FMDatabase; @class ETUUID; -NSString *const COUndoTrackStoreTrackDidChangeNotification; +extern NSString *const COUndoTrackStoreTrackDidChangeNotification; // User info keys for COUndoTrackStoreTrackDidChangeNotification -NSString *const COUndoTrackStoreTrackName; +extern NSString *const COUndoTrackStoreTrackName; /** * UUID string */ -NSString *const COUndoTrackStoreTrackHeadCommandUUID; +extern NSString *const COUndoTrackStoreTrackHeadCommandUUID; /** * NSNull or UUID string */ -NSString *const COUndoTrackStoreTrackCurrentCommandUUID; +extern NSString *const COUndoTrackStoreTrackCurrentCommandUUID; /** * NSNumber boolean */ -NSString *const COUndoTrackStoreTrackCompacted; +extern NSString *const COUndoTrackStoreTrackCompacted; @interface COUndoTrackSerializedCommand : NSObject diff --git a/Undo/COUndoTrackStore.m b/Undo/COUndoTrackStore.m index 7303a0361..402cac5b1 100644 --- a/Undo/COUndoTrackStore.m +++ b/Undo/COUndoTrackStore.m @@ -203,15 +203,6 @@ - (void)dealloc { [_db close]; }); - -#if !(TARGET_OS_IPHONE) - // N.B.: We are using deployment target 10.7, so ARC does not manage libdispatch objects. - // If we switch to deployment target 10.8, ARC will manage libdispatch objects automatically. - // For GNUstep, ARC doesn't manage libdispatch objects since libobjc2 doesn't support it - // currently (we compile CoreObject with -DOS_OBJECT_USE_OBJC=0). - dispatch_release(_queue); - dispatch_release(_transactionLock); -#endif } - (BOOL)setupSchema From 914738862d8e04d438a1891b242804e639a73b5d Mon Sep 17 00:00:00 2001 From: Jordy Dickinson Date: Tue, 11 Oct 2016 11:13:31 -0400 Subject: [PATCH 2/4] Fix -[COPrimitiveCollection insertObject:atIndex:] on <=10.9 --- Core/COPrimitiveCollection.m | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Core/COPrimitiveCollection.m b/Core/COPrimitiveCollection.m index cb569b072..d248d3498 100644 --- a/Core/COPrimitiveCollection.m +++ b/Core/COPrimitiveCollection.m @@ -246,14 +246,26 @@ - (void)insertObject: (id)anObject atIndex: (NSUInteger)index COThrowExceptionIfNotMutable(_permanentlyMutable, _temporaryMutable); COThrowExceptionIfOutOfBounds(self, index, YES); - NSUInteger backingIndex = [self backingIndex: index]; + // NSPointerArray on 10.9 (at least) doesn't allow inserting at the end using index == count, so + // call addPointer in that case as a workaround. + if (index == _externalIndexToBackingIndex.count) + { + // insert at end + [_externalIndexToBackingIndex addPointer: (void *)_backing.count]; + [_backing addPointer: (__bridge void *)anObject]; + } + else + { + // insert in the beginning or middle + NSUInteger backingIndex = [self backingIndex: index]; - [self shiftBackingIndicesGreaterThanOrEqualTo: backingIndex by: 1]; + [self shiftBackingIndicesGreaterThanOrEqualTo: backingIndex by: 1]; - [_externalIndexToBackingIndex insertPointer: (void *)backingIndex - atIndex: index]; - [_backing insertPointer: (__bridge void *)anObject - atIndex: backingIndex]; + [_externalIndexToBackingIndex insertPointer: (void *)backingIndex + atIndex: index]; + [_backing insertPointer: (__bridge void *)anObject + atIndex: backingIndex]; + } } - (void)removeLastObject From 051ffd53ee63a9b345076a936ca9b7179c92e8b9 Mon Sep 17 00:00:00 2001 From: Jordy Dickinson Date: Tue, 11 Oct 2016 14:34:56 -0400 Subject: [PATCH 3/4] Make requested changes Add back GNUstep compatibility, make requested changes to comments, and fix Graphviz task execution. --- Core/COCrossPersistentRootDeadRelationshipCache.h | 4 ++++ Debugging/COSQLiteStore+Graphviz.m | 5 +++-- Store/COSQLiteStore.m | 8 ++++++++ Undo/COUndoTrackStore.m | 8 ++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Core/COCrossPersistentRootDeadRelationshipCache.h b/Core/COCrossPersistentRootDeadRelationshipCache.h index 146eff1d4..648f7394e 100644 --- a/Core/COCrossPersistentRootDeadRelationshipCache.h +++ b/Core/COCrossPersistentRootDeadRelationshipCache.h @@ -56,6 +56,10 @@ NS_ASSUME_NONNULL_BEGIN * When a persistent root or branch is unloaded, any matching paths should be * kept in the cache, in case it gets reloaded later (we cannot figure out cross * persistent root incoming relationships from the reloading). + * + * For referring object graph contexts, when unloaded or finalized, the + * deallocation will trigger their removal of their inner objects from the hash + * tables in the cache on 10.8 or iOS 6 or higher, which we require. */ - (void)removePath: (COPath *)aPath; diff --git a/Debugging/COSQLiteStore+Graphviz.m b/Debugging/COSQLiteStore+Graphviz.m index 958cc0d9d..0f0e3b5f4 100644 --- a/Debugging/COSQLiteStore+Graphviz.m +++ b/Debugging/COSQLiteStore+Graphviz.m @@ -179,8 +179,9 @@ void COViewDOTGraphFile(NSString *dotFilePath) continue; } - [NSTask launchedTaskWithLaunchPath:executablePath - arguments:@[@"-Tpdf", dotFilePath, pdfPath]]; + NSTask *task = [NSTask launchedTaskWithLaunchPath:executablePath + arguments:@[@"-Tpdf", dotFilePath, @"-o", pdfPath]]; + [task waitUntilExit]; [[NSWorkspace sharedWorkspace] openFile: pdfPath]; break; } diff --git a/Store/COSQLiteStore.m b/Store/COSQLiteStore.m index be5601aad..71d597f5a 100644 --- a/Store/COSQLiteStore.m +++ b/Store/COSQLiteStore.m @@ -124,6 +124,14 @@ - (void)dealloc [db_ close]; db_ = nil; }); + +#if defined(GNUSTEP) + // N.B.: We are using deployment target 10.8, so ARC will manage + // libdispatch objects automatically. For GNUstep, ARC doesn't + // manage libdispatch objects since libobjc2 doesn't support it + // currently (we compile CoreObject with -DOS_OBJECT_USE_OBJC=0). + dispatch_release(_queue); +#endif } - (BOOL)setupSchema diff --git a/Undo/COUndoTrackStore.m b/Undo/COUndoTrackStore.m index 402cac5b1..312dd32d4 100644 --- a/Undo/COUndoTrackStore.m +++ b/Undo/COUndoTrackStore.m @@ -203,6 +203,14 @@ - (void)dealloc { [_db close]; }); + +#if defined(GNUSTEP) + // N.B.: We are using deployment target 10.8, so ARC will manage libdispatch objects automatically. + // For GNUstep, ARC doesn't manage libdispatch objects since libobjc2 doesn't support it + // currently (we compile CoreObject with -DOS_OBJECT_USE_OBJC=0). + dispatch_release(_queue); + dispatch_release(_transactionLock); +#endif } - (BOOL)setupSchema From dc9ec9d194e3482e601d7803c4d0cfbb834a0b7b Mon Sep 17 00:00:00 2001 From: Jordy Dickinson Date: Tue, 11 Oct 2016 19:16:40 -0400 Subject: [PATCH 4/4] Format code appropriately --- Debugging/COSQLiteStore+Graphviz.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Debugging/COSQLiteStore+Graphviz.m b/Debugging/COSQLiteStore+Graphviz.m index 0f0e3b5f4..37664bfc5 100644 --- a/Debugging/COSQLiteStore+Graphviz.m +++ b/Debugging/COSQLiteStore+Graphviz.m @@ -179,8 +179,8 @@ void COViewDOTGraphFile(NSString *dotFilePath) continue; } - NSTask *task = [NSTask launchedTaskWithLaunchPath:executablePath - arguments:@[@"-Tpdf", dotFilePath, @"-o", pdfPath]]; + NSTask *task = [NSTask launchedTaskWithLaunchPath: executablePath + arguments: @[@"-Tpdf", dotFilePath, @"-o", pdfPath]]; [task waitUntilExit]; [[NSWorkspace sharedWorkspace] openFile: pdfPath]; break;