├── .gitignore ├── CommonC-iOS ├── CommonC-iOS.h └── Info.plist ├── CommonC-iOSTests ├── CommonC_iOSTests.m └── Info.plist ├── CommonC.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ ├── CommonC.xcscmblueprint │ └── IDEWorkspaceChecks.plist ├── CommonC ├── Alignment.h ├── Allocator.c ├── Allocator.h ├── Array.c ├── Array.h ├── Assertion.h ├── Assertion_Private.h ├── Base.h ├── BigInt.c ├── BigInt.h ├── BigIntFast.h ├── BitSets.h ├── BitTricks.h ├── Bits.h ├── BitsTemplate.h ├── Buffer.h ├── CCString.c ├── CCString.h ├── CCStringEnumerator.h ├── CFAllocator.c ├── CallbackAllocator.h ├── CircularEnumerable.c ├── CircularEnumerable.h ├── Collection.c ├── Collection.h ├── CollectionArray.c ├── CollectionArray.h ├── CollectionEnumerator.h ├── CollectionFastArray.c ├── CollectionFastArray.h ├── CollectionInterface.h ├── CollectionList.c ├── CollectionList.h ├── CollectionTypes.h ├── Common.h ├── CommonC-Info.plist ├── CommonC-Prefix.pch ├── CommonC.c ├── Comparator.h ├── ConcurrentArray.c ├── ConcurrentArray.h ├── ConcurrentBuffer.c ├── ConcurrentBuffer.h ├── ConcurrentCircularBuffer.h ├── ConcurrentCircularBufferTemplate.h ├── ConcurrentGarbageCollector.c ├── ConcurrentGarbageCollector.h ├── ConcurrentGarbageCollectorInterface.h ├── ConcurrentIDGenerator.c ├── ConcurrentIDGenerator.h ├── ConcurrentIDGeneratorInterface.h ├── ConcurrentIndexBuffer.c ├── ConcurrentIndexBuffer.h ├── ConcurrentIndexMap.c ├── ConcurrentIndexMap.h ├── ConcurrentPool.h ├── ConcurrentPoolTemplate.h ├── ConcurrentQueue.c ├── ConcurrentQueue.h ├── ConcurrentSharedResource.h ├── ConcurrentSharedResourceTemplate.h ├── ConcurrentSwapBuffer.h ├── ConcurrentSwapBufferTemplate.h ├── ConcurrentTree.c ├── ConcurrentTree.h ├── ConsecutiveIDGenerator.c ├── ConsecutiveIDGenerator.h ├── Container.h ├── ContainerTypes.h ├── CustomFormatSpecifiers.c ├── CustomFormatSpecifiers.h ├── CustomInputFilters.c ├── CustomInputFilters.h ├── Data.c ├── Data.h ├── DataBuffer.c ├── DataBuffer.h ├── DataContainer.c ├── DataContainer.h ├── DataInterface.h ├── DataMemoryTemplate.h ├── DataTypes.h ├── DebugAllocator.c ├── DebugAllocator.h ├── DebugTypes.c ├── DebugTypes.h ├── Decimal.h ├── Dictionary.c ├── Dictionary.h ├── DictionaryEnumerator.h ├── DictionaryHashMap.c ├── DictionaryHashMap.h ├── DictionaryInterface.h ├── Enumerable.c ├── Enumerable.h ├── Enumerator.h ├── EpochGarbageCollector.c ├── EpochGarbageCollector.h ├── Extensions.h ├── Extrema.h ├── ExtremaTemplate.h ├── File.c ├── File.h ├── FileHandle.c ├── FileHandle.h ├── FileSystem.c ├── FileSystem.h ├── FileSystem_Private.h ├── Generic1.h ├── Generic2.h ├── Generic3.h ├── Generic4.h ├── Generics.h ├── Hacks.h ├── HardwareInfo.c ├── HardwareInfo.h ├── Hash.c ├── Hash.h ├── HashMap.c ├── HashMap.h ├── HashMapEnumerator.h ├── HashMapInterface.h ├── HashMapSeparateChainingArray.c ├── HashMapSeparateChainingArray.h ├── HashMapSeparateChainingArrayDataOrientedAll.c ├── HashMapSeparateChainingArrayDataOrientedAll.h ├── HashMapSeparateChainingArrayDataOrientedHash.c ├── HashMapSeparateChainingArrayDataOrientedHash.h ├── LazyGarbageCollector.c ├── LazyGarbageCollector.h ├── LinkedList.c ├── LinkedList.h ├── List.c ├── List.h ├── Logging.c ├── Logging.h ├── Logging_Private.h ├── Maths.h ├── Matrix.h ├── Matrix4.h ├── Memory.h ├── MemoryAllocation.c ├── MemoryAllocation.h ├── MemoryTemplate.h ├── MemoryZone.c ├── MemoryZone.h ├── Numeric.h ├── NumericTemplate.h ├── OrderedCollection.c ├── OrderedCollection.h ├── Ownership.h ├── Path.c ├── Path.h ├── PathComponent.c ├── PathComponent.h ├── Platform.h ├── PoolAllocator.c ├── PoolAllocator.h ├── Pragmas.h ├── ProcessInfo.c ├── ProcessInfo.h ├── Queue.c ├── Queue.h ├── Random.c ├── Random.h ├── Range.h ├── RangeBase.h ├── RangeBaseTemplate.h ├── RangeTemplate.h ├── Reflect.c ├── Reflect.h ├── ReflectStream.c ├── ReflectStream.h ├── ReflectedTypes.c ├── ReflectedTypes.h ├── Swap.h ├── SystemInfo.c ├── SystemInfo.h ├── SystemPath.m ├── Task.c ├── Task.h ├── TaskQueue.c ├── TaskQueue.h ├── Template.h ├── TypeCallbacks.c ├── TypeCallbacks.h ├── Types.h ├── ValidateMaximum.c ├── ValidateMaximum.h ├── ValidateMinimum.c ├── ValidateMinimum.h ├── Vector.h ├── Vector2D.h ├── Vector3D.h ├── Vector4D.h └── en.lproj │ └── InfoPlist.strings ├── CommonCTests ├── AlignedAllocatorTests.m ├── AllocatorTests.h ├── AllocatorTests.m ├── ArrayTests.m ├── BigIntTests.m ├── BitSetsTests.m ├── BitTricksTests.h ├── BitTricksTests.m ├── CollectionArrayTests.m ├── CollectionFastArrayTests.m ├── CollectionListTests.m ├── CollectionTests.h ├── CollectionTests.m ├── CommonCTests-Info.plist ├── CompileTimeSortTests.m ├── ConcurrentBufferTests.m ├── ConcurrentCircularBufferTests.m ├── ConcurrentGarbageCollectorTests.m ├── ConcurrentIndexBuffer.m ├── ConcurrentIndexMapTests.m ├── ConcurrentPoolTests.m ├── ConcurrentQueueTests.m ├── ConcurrentSharedResourceTests.m ├── ConcurrentSwapBufferTests.m ├── ConsecutiveIDGeneratorTests.m ├── ContainerTests.m ├── DataBufferTests.m ├── DataContainerTests.m ├── DataTests.h ├── DataTests.m ├── DecimalTests.m ├── DictionaryHashMapTests.m ├── DictionaryTests.h ├── DictionaryTests.m ├── EnumTests.m ├── EnumerableTests.m ├── FileHandleTests.h ├── FileHandleTests.m ├── FileSystemTests.h ├── FileSystemTests.m ├── FileTests.h ├── FileTests.m ├── HashMapSeparateChainingArrayDataOrientedAllTests.m ├── HashMapSeparateChainingArrayDataOrientedHash.m ├── HashMapSeparateChainingArrayTests.m ├── HashMapTests.h ├── HashMapTests.m ├── LinkedListTests.m ├── ListTests.m ├── LoggingTests.h ├── LoggingTests.m ├── MemoryAllocationTests.h ├── MemoryAllocationTests.m ├── MemoryTemplateTests.m ├── MemoryZoneTests.m ├── OrderedCollectionTests.h ├── OrderedCollectionTests.m ├── PathTests.m ├── PoolAllocatorTests.m ├── QueueTests.m ├── RandomTests.m ├── RangeTests.m ├── ReflectTests.m ├── StringTests.m ├── TaskQueueTests.m ├── TaskTests.m ├── TemplateTests.m ├── Vector2DAVXTests.m ├── Vector2DSSE2Tests.m ├── Vector2DSSE3Tests.m ├── Vector2DSSE4_1Tests.m ├── Vector2DSSE4_2Tests.m ├── Vector2DSSETests.m ├── Vector2DSSSE3Tests.m ├── Vector2DTests.m ├── Vector3DTests.m ├── Vector4DTests.m ├── Vectorized2DAVXTests.m ├── Vectorized2DSSE2Tests.m ├── Vectorized2DSSE3Tests.m ├── Vectorized2DSSE4_1Tests.m ├── Vectorized2DSSE4_2Tests.m ├── Vectorized2DSSETests.m ├── Vectorized2DSSSE3Tests.m ├── Vectorized2DTests.m ├── Vectorized3DAVXTests.m ├── Vectorized3DSSE2Tests.m ├── Vectorized3DSSE3Tests.m ├── Vectorized3DSSE4_1Tests.m ├── Vectorized3DSSE4_2Tests.m ├── Vectorized3DSSETests.m ├── Vectorized3DSSSE3Tests.m ├── Vectorized3DTests.m ├── Vectorized4DAVXTests.m ├── Vectorized4DSSE2Tests.m ├── Vectorized4DSSE3Tests.m ├── Vectorized4DSSE4_1Tests.m ├── Vectorized4DSSE4_2Tests.m ├── Vectorized4DSSETests.m ├── Vectorized4DSSSE3Tests.m ├── Vectorized4DTests.m ├── VirtualFileHandleTests.m ├── VirtualFileSystemTests.m └── en.lproj │ └── InfoPlist.strings ├── LICENSE ├── README.md ├── gen_container_types.rb ├── gen_container_types.sh ├── generic_imp.rb ├── generic_n.rb └── meson.build /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | 4 | # Xcode 5 | # 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | *.xccheckout 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | *.xcuserstate 22 | 23 | # CocoaPods 24 | # 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | # Pods/ 30 | -------------------------------------------------------------------------------- /CommonC-iOS/CommonC-iOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommonC-iOS.h 3 | // CommonC-iOS 4 | // 5 | // Created by Stefan Johnson on 4/02/2016. 6 | // Copyright © 2016 Stefan Johnson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for CommonC-iOS. 12 | FOUNDATION_EXPORT double CommonC_iOSVersionNumber; 13 | 14 | //! Project version string for CommonC-iOS. 15 | FOUNDATION_EXPORT const unsigned char CommonC_iOSVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /CommonC-iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CommonC-iOSTests/CommonC_iOSTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommonC_iOSTests.m 3 | // CommonC-iOSTests 4 | // 5 | // Created by Stefan Johnson on 4/02/2016. 6 | // Copyright © 2016 Stefan Johnson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CommonC_iOSTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CommonC_iOSTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CommonC-iOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CommonC.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CommonC.xcodeproj/project.xcworkspace/xcshareddata/CommonC.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++AD8EE52", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++AD8EE52" : 0, 8 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++39EE8C6" : 0, 9 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++5D12257" : 0 10 | }, 11 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "3AB2F6C2-38FD-4537-9C95-087563FF3C5B", 12 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 13 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++AD8EE52" : "CommonC\/", 14 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++39EE8C6" : "", 15 | "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++5D12257" : "" 16 | }, 17 | "DVTSourceControlWorkspaceBlueprintNameKey" : "CommonC", 18 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 19 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "CommonC.xcodeproj", 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 21 | { 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/ScrimpyCat\/Common.git", 23 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 24 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++39EE8C6" 25 | }, 26 | { 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/ScrimpyCat\/CommonC.git", 28 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 29 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++5D12257" 30 | }, 31 | { 32 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/ScrimpyCat\/CommonC.git", 33 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 34 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "33A65E4BDC0B64170459B0F2D4EEA4545A76C379+++AD8EE52" 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /CommonC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CommonC/Alignment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Alignment_h 27 | #define CommonC_Alignment_h 28 | 29 | #define CC_ALIGN(x, alignment) (((x) + (alignment) - 1) & ~((alignment) - 1)) 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /CommonC/Assertion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #undef CCAssertLog 28 | 29 | #if CC_NO_ASSERT 30 | 31 | #define CCAssertLog(e, ...) (void)0 32 | 33 | #else 34 | 35 | #include 36 | #include 37 | 38 | #define CCAssertLog(e, ...) (void)(CC_LIKELY(e)? 0 : (CCLog(CCLogOptionOutputAll, CCTagError, CC_LOG_IDENTIFIER, __FILE__, __func__, __LINE__, "Assertion failed: (" #e "). " __VA_ARGS__), abort())) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /CommonC/Assertion_Private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "Logging_Private.h" 27 | #include "Assertion.h" 28 | -------------------------------------------------------------------------------- /CommonC/Base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Base_h 27 | #define CommonC_Base_h 28 | 29 | #include 30 | 31 | #if CC_PLATFORM_APPLE 32 | #import 33 | #endif 34 | 35 | #if !defined(CC_EXCLUDE_CSTD_HEADERS) 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #ifndef TRUE 48 | #define TRUE true 49 | #endif 50 | 51 | #ifndef FALSE 52 | #define FALSE false 53 | #endif 54 | 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /CommonC/BitSets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_BitSets_h 27 | #define CommonC_BitSets_h 28 | 29 | #include 30 | 31 | /*! 32 | * @define CCBits 33 | * @brief Create an array of bits. 34 | * @param type The base type for the array. 35 | * @param count The number of bits needing to be stored. 36 | */ 37 | #define CCBits(type, count) typeof((type[CC_ALIGN(count, (sizeof(type) * 8)) / (sizeof(type) * 8)]){}) 38 | 39 | /*! 40 | * @define CC_BITS_INIT_SET 41 | * @brief Sets the entire array of bits. 42 | * @warning This should only be used with the variable declared by @b CCBits. 43 | */ 44 | #define CC_BITS_INIT_SET(set) memset(set, -1, sizeof(set)) 45 | 46 | /*! 47 | * @define CC_BITS_INIT_SET 48 | * @brief Clears the entire array of bits. 49 | * @warning This should only be used with the variable declared by @b CCBits. 50 | */ 51 | #define CC_BITS_INIT_CLEAR(set) memset(set, 0, sizeof(set)) 52 | 53 | /*! 54 | * @define CC_BITS_COPY 55 | * @brief Copies the entire array of bits from the src to dst. 56 | * @warning This should only be used with the variables declared by @b CCBits. 57 | */ 58 | #define CC_BITS_COPY(dst, src) _Static_assert(sizeof(src) == sizeof(dst), "Src and Dst must be the same size"); memcpy(dst, src, sizeof(dst)) 59 | 60 | /*! 61 | * @define CC_BITS_BLOCK_SIZE 62 | * @brief Get the size of one block (number of bits in a block) for the array of bits. 63 | */ 64 | #define CC_BITS_BLOCK_SIZE(set) (sizeof(*set) * 8) 65 | 66 | #define Tbase uint8_t 67 | #include 68 | 69 | #define Tbase uint16_t 70 | #include 71 | 72 | #define Tbase uint32_t 73 | #include 74 | 75 | #define Tbase uint64_t 76 | #include 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /CommonC/Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Buffer_h 27 | #define CommonC_Buffer_h 28 | 29 | #include 30 | #include 31 | 32 | typedef struct { 33 | void *ptr; 34 | ptrdiff_t offset; 35 | size_t size; 36 | CCDataHint hint; 37 | } CCBufferMap; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /CommonC/CallbackAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_CallbackAllocator_h 27 | #define CommonC_CallbackAllocator_h 28 | 29 | #include 30 | #include 31 | 32 | typedef CC_ENUM(CCCallbackAllocatorEvent, uint8_t) { 33 | CCCallbackAllocatorEventAllocatePre, 34 | CCCallbackAllocatorEventAllocatePost, 35 | CCCallbackAllocatorEventReallocatePre, 36 | CCCallbackAllocatorEventReallocatePost, 37 | CCCallbackAllocatorEventDeallocatePre 38 | }; 39 | 40 | typedef void (*CCCallbackAllocatorFunction)(CCCallbackAllocatorEvent Event, void *Ptr, size_t *Size); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /CommonC/CircularEnumerable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "CircularEnumerable.h" 27 | 28 | void *CCCircularEnumerableHandler(CCEnumerator *Enumerator, CCEnumerableAction Action) 29 | { 30 | switch (Action) 31 | { 32 | case CCEnumerableActionHead: 33 | Enumerator->state.circular.index = Enumerator->state.circular.start; 34 | return Enumerator->state.circular.count ? (Enumerator->state.circular.ptr + ((Enumerator->state.circular.index % Enumerator->state.circular.max) * Enumerator->state.circular.stride)) : NULL; 35 | 36 | case CCEnumerableActionTail: 37 | Enumerator->state.circular.index = (Enumerator->state.circular.count - 1) + Enumerator->state.circular.start; 38 | return Enumerator->state.circular.count ? (Enumerator->state.circular.ptr + ((Enumerator->state.circular.index % Enumerator->state.circular.max) * Enumerator->state.circular.stride)) : NULL; 39 | 40 | default: 41 | break; 42 | } 43 | 44 | return NULL; 45 | } 46 | -------------------------------------------------------------------------------- /CommonC/CircularEnumerable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_CircularEnumerable_h 27 | #define CommonC_CircularEnumerable_h 28 | 29 | #include 30 | #include 31 | 32 | 33 | /*! 34 | * @brief Create an enumerable for a circular buffer of values. 35 | * @param Ptr A pointer to the base of the buffer. 36 | * @param Stride The size of the value. 37 | * @param Count The number of values. 38 | * @param Start The index to start from. 39 | * @param Max The maximum size of the buffer. 40 | * @return The enumerable. 41 | */ 42 | static CC_FORCE_INLINE CCEnumerable CCCircularEnumerableCreate(void *Ptr, size_t Stride, size_t Count, size_t Start, size_t Max); 43 | 44 | void *CCCircularEnumerableHandler(CCEnumerator *Enumerator, CCEnumerableAction Action); 45 | 46 | #pragma mark - 47 | 48 | static CC_FORCE_INLINE CCEnumerable CCCircularEnumerableCreate(void *Ptr, size_t Stride, size_t Count, size_t Start, size_t Max) 49 | { 50 | CCAssertLog(Count <= Max, "Count should not exceed Max"); 51 | CCAssertLog(Start < Max, "Start must not be out of bounds"); 52 | 53 | return (CCEnumerable){ 54 | .handler = CCCircularEnumerableHandler, 55 | .enumerator = { 56 | .ref = Ptr, 57 | .state = { 58 | .circular = { 59 | .ptr = Ptr, 60 | .count = Count, 61 | .stride = Stride, 62 | .index = Start, 63 | .max = Max, 64 | .start = Start 65 | }, 66 | .type = CCEnumeratorFormatCircular 67 | } 68 | } 69 | }; 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /CommonC/CollectionArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCCollectionArray 28 | * CCCollectionArray is an interface for an array backed collection implementation. This interface can 29 | * also be used for ordered collections. 30 | * 31 | * For immutable collections, this type is the fastest. For mutable collections, performance may vary. 32 | * 33 | * Fast Operations: 34 | * - Enumerating. 35 | * - Replacing entries. 36 | * - Inserting items to the collection. Note: this assumes no copying of contents when reallocating. 37 | * 38 | * Slow Operations: 39 | * - Finding items in the collection. 40 | * 41 | * 42 | * Fast Ordered Operations: 43 | * - Removing the item at the end of the list. 44 | * - Index lookup. 45 | * 46 | * Slow Ordered Operations: 47 | * - Prepending items or inserting inside the collection. 48 | * - Removing items at the beginning of the list or inside the list. 49 | */ 50 | #ifndef CommonC_CollectionArray_h 51 | #define CommonC_CollectionArray_h 52 | 53 | #include 54 | 55 | extern const CCCollectionInterface * const CCCollectionArray; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /CommonC/CollectionFastArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCCollectionFastArray 28 | * CCCollectionFastArray is an interface for an array backed ordered collection implementation. This interface can 29 | * only be used for ordered collections. Use cases that rely on persistent @b CCCollectionEntry references will not 30 | * work. The purpose of this collection is to provide a fast ordered collection implementation. Due to this, the 31 | * implementation will never be used by the implicit @b CCCollectionCreate function. Instead usage is explicit and 32 | * therefore must use the @b CCCollectionCreateWithImplementation function. 33 | * 34 | * @b CCCollectionEntry are valid only temporarily. If any mutation happens, there is not guarantee they will be valid. 35 | * As an entry reference is just the current index of the element. 36 | * 37 | * For ordered collections, with appending/replacing and collection destruction operations, this type is the fastest. 38 | * 39 | * Fast Ordered Operations: 40 | * - Enumerating 41 | * - Replacing entries. 42 | * - Removing the item at the end of the collection. 43 | * - Removing all items in the collection. 44 | * - Index lookup. 45 | * - Destruction of the collection. 46 | * 47 | * Slow Ordered Operations: 48 | * - Prepending items or inserting inside the collection. 49 | * - Removing items at the beginning of the list or inside the list. 50 | * - Finding items in the collection. 51 | */ 52 | #ifndef CommonC_CollectionFastArray_h 53 | #define CommonC_CollectionFastArray_h 54 | 55 | #include 56 | 57 | extern const CCCollectionInterface * const CCCollectionFastArray; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /CommonC/CollectionList.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCCollectionList 28 | * CCCollectionList is an interface for a linked list backed collection implementation. This interface 29 | * can also be used for ordered collections. 30 | * 31 | * For mutable collections with lots of inserting and removing this is ideal. 32 | * 33 | * Fast Operations: 34 | * - Replacing entries. 35 | * - Inserting items to the collection. 36 | * 37 | * Slow Operations: 38 | * - Finding items in the collection. 39 | * 40 | * 41 | * Fast Ordered Operations: 42 | * - Removing items. 43 | * - Inserting items. 44 | * 45 | * Slow Ordered Operations: 46 | * - Index lookup. 47 | */ 48 | #ifndef CommonC_CollectionList_h 49 | #define CommonC_CollectionList_h 50 | 51 | #include 52 | 53 | extern const CCCollectionInterface * const CCCollectionList; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /CommonC/CommonC-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | NSHumanReadableCopyright 26 | Copyright © 2013 Stefan Johnson. All rights reserved. 27 | NSPrincipalClass 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /CommonC/CommonC-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CommonC' target in the 'CommonC' project 3 | // -------------------------------------------------------------------------------- /CommonC/CommonC.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "Common.h" 28 | 29 | 30 | /* 31 | Design notes: 32 | 33 | Exposed functions: 34 | - Everything must use prefix CC. 35 | - Macros that are more than just a function wrapper (add additional code) must use prefix CC_. 36 | - Functions or macros wrapping functions (i.e. using generics) must use the prefix CC. 37 | 38 | - Function naming conventions should use CamelCase. 39 | - Macro naming conventions should use CAPITALS and underscore, lowercase is valid when it's wrapping or imitating a function. 40 | - Functions that provide a callback mechanism should support both function pointers and blocks (an Apple C extension). Functions that do this should also use 41 | generics to provide the same interface to both. 42 | */ 43 | -------------------------------------------------------------------------------- /CommonC/ConcurrentArray.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "ConcurrentArray.h" 28 | #include "MemoryAllocation.h" 29 | #include "Assertion.h" 30 | #include 31 | #include 32 | 33 | /* 34 | CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE enforces standard compliant usage of atomic types. This however will 35 | result in all operations requiring CAS-loops. 36 | */ 37 | #define CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 0 38 | 39 | #if !CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 40 | #if !CC_HARDWARE_PTR_64 && !CC_HARDWARE_PTR_32 41 | #undef CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 42 | #define CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 1 43 | #endif 44 | #endif 45 | 46 | typedef struct { 47 | void *element; 48 | uintptr_t tag; 49 | } CCConcurrentArrayBufferPointer; 50 | 51 | typedef struct { 52 | CCConcurrentArray array; 53 | _Atomic(size_t) count; 54 | _Atomic(CCConcurrentArrayBufferPointer) buffer[]; 55 | } CCConcurrentArrayData; 56 | 57 | typedef struct { 58 | #if CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 59 | #if CC_HARDWARE_PTR_64 60 | uint64_t mutate; 61 | #else 62 | uint32_t mutate; 63 | #endif 64 | #else 65 | #if CC_HARDWARE_PTR_64 66 | _Atomic(uint64_t) mutate; 67 | #else 68 | _Atomic(uint32_t) mutate; 69 | #endif 70 | #endif 71 | CCConcurrentArrayData *data; 72 | } CCConcurrentArrayDataPointer; 73 | 74 | #if !CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE 75 | #if CC_HARDWARE_PTR_64 76 | _Static_assert(sizeof(_Atomic(CCConcurrentArrayDataPointer)) == 16, "Native types are not atomic, please set CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE"); 77 | #elif CC_HARDWARE_PTR_32 78 | _Static_assert(sizeof(_Atomic(CCConcurrentArrayDataPointer)) == 8, "Native types are not atomic, please set CC_CONCURRENT_ARRAY_STRICT_COMPLIANCE"); 79 | #endif 80 | #endif 81 | 82 | typedef struct CCConcurrentArrayInfo { 83 | CCAllocatorType allocator; 84 | size_t size, chunkSize; 85 | _Atomic(CCConcurrentArrayDataPointer) pointer; 86 | CCConcurrentGarbageCollector gc; 87 | } CCConcurrentArrayInfo; 88 | -------------------------------------------------------------------------------- /CommonC/ConcurrentBuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "ConcurrentBuffer.h" 28 | #include "MemoryAllocation.h" 29 | #include "Assertion.h" 30 | #include 31 | 32 | typedef struct CCConcurrentBufferInfo { 33 | CCConcurrentBufferDataDestructor destructor; 34 | _Atomic(void*) data; 35 | } CCConcurrentBufferInfo; 36 | 37 | static void CCConcurrentBufferDestructor(CCConcurrentBuffer Buffer) 38 | { 39 | if (Buffer->destructor) 40 | { 41 | Buffer->destructor(atomic_load_explicit(&Buffer->data, memory_order_relaxed)); 42 | } 43 | } 44 | 45 | CCConcurrentBuffer CCConcurrentBufferCreate(CCAllocatorType Allocator, CCConcurrentBufferDataDestructor Destructor) 46 | { 47 | CCConcurrentBuffer Buffer = CCMalloc(Allocator, sizeof(CCConcurrentBufferInfo), NULL, CC_DEFAULT_ERROR_CALLBACK); 48 | 49 | if (Buffer) 50 | { 51 | *Buffer = (CCConcurrentBufferInfo){ 52 | .destructor = Destructor, 53 | .data = ATOMIC_VAR_INIT(NULL) 54 | }; 55 | 56 | CCMemorySetDestructor(Buffer, (CCMemoryDestructorCallback)CCConcurrentBufferDestructor); 57 | } 58 | 59 | return Buffer; 60 | } 61 | 62 | void CCConcurrentBufferDestroy(CCConcurrentBuffer Buffer) 63 | { 64 | CCAssertLog(Buffer, "Buffer must not be null"); 65 | 66 | CC_SAFE_Free(Buffer); 67 | } 68 | 69 | void CCConcurrentBufferWriteData(CCConcurrentBuffer Buffer, void *Data) 70 | { 71 | CCAssertLog(Buffer, "Buffer must not be null"); 72 | 73 | void *Ptr = atomic_exchange_explicit(&Buffer->data, Data, memory_order_acq_rel); 74 | if ((Buffer->destructor) && (Ptr)) 75 | { 76 | Buffer->destructor(Ptr); 77 | } 78 | } 79 | 80 | void *CCConcurrentBufferWriteDataSwap(CCConcurrentBuffer Buffer, void *Data) 81 | { 82 | CCAssertLog(Buffer, "Buffer must not be null"); 83 | 84 | return atomic_exchange_explicit(&Buffer->data, Data, memory_order_acq_rel); 85 | } 86 | 87 | void *CCConcurrentBufferReadData(CCConcurrentBuffer Buffer) 88 | { 89 | return CCConcurrentBufferWriteDataSwap(Buffer, NULL); 90 | } 91 | 92 | CCConcurrentBufferDataDestructor CCConcurrentBufferGetDataDestructor(CCConcurrentBuffer Buffer) 93 | { 94 | CCAssertLog(Buffer, "Buffer must not be null"); 95 | 96 | return Buffer->destructor; 97 | } 98 | -------------------------------------------------------------------------------- /CommonC/ConcurrentGarbageCollector.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "ConcurrentGarbageCollector.h" 28 | #include "MemoryAllocation.h" 29 | #include "Assertion.h" 30 | 31 | typedef struct CCConcurrentGarbageCollectorInfo { 32 | const CCConcurrentGarbageCollectorInterface *interface; 33 | CCAllocatorType allocator; 34 | void *internal; 35 | } CCConcurrentGarbageCollectorInfo; 36 | 37 | 38 | static void CCConcurrentGarbageCollectorDestructor(CCConcurrentGarbageCollector GC) 39 | { 40 | GC->interface->destroy(GC->internal); 41 | } 42 | 43 | CCConcurrentGarbageCollector CCConcurrentGarbageCollectorCreate(CCAllocatorType Allocator, const CCConcurrentGarbageCollectorInterface *Interface) 44 | { 45 | CCConcurrentGarbageCollector GC = CCMalloc(Allocator, sizeof(CCConcurrentGarbageCollectorInfo), NULL, CC_DEFAULT_ERROR_CALLBACK); 46 | if (GC) 47 | { 48 | *GC = (CCConcurrentGarbageCollectorInfo){ 49 | .interface = Interface, 50 | .allocator = Allocator, 51 | .internal = Interface->create(Allocator) 52 | }; 53 | 54 | if (!GC->internal) 55 | { 56 | CC_LOG_ERROR("Failed to create garbage collector: Implementation failure (%p)", Interface); 57 | CCFree(GC); 58 | GC = NULL; 59 | } 60 | 61 | else CCMemorySetDestructor(GC, (CCMemoryDestructorCallback)CCConcurrentGarbageCollectorDestructor); 62 | } 63 | 64 | else 65 | { 66 | CC_LOG_ERROR("Failed to create garbage collector: Failed to allocate memory of size (%zu)", sizeof(CCConcurrentGarbageCollectorInfo)); 67 | } 68 | 69 | return GC; 70 | } 71 | 72 | void CCConcurrentGarbageCollectorDestroy(CCConcurrentGarbageCollector GC) 73 | { 74 | CCAssertLog(GC, "GC must not be null"); 75 | 76 | CCFree(GC); 77 | } 78 | 79 | void CCConcurrentGarbageCollectorBegin(CCConcurrentGarbageCollector GC) 80 | { 81 | CCAssertLog(GC, "GC must not be null"); 82 | 83 | GC->interface->begin(GC->internal, GC->allocator); 84 | } 85 | 86 | void CCConcurrentGarbageCollectorEnd(CCConcurrentGarbageCollector GC) 87 | { 88 | CCAssertLog(GC, "GC must not be null"); 89 | 90 | GC->interface->end(GC->internal, GC->allocator); 91 | } 92 | 93 | void CCConcurrentGarbageCollectorManage(CCConcurrentGarbageCollector GC, void *Item, CCConcurrentGarbageCollectorReclaimer Reclaimer) 94 | { 95 | CCAssertLog(GC, "GC must not be null"); 96 | 97 | GC->interface->manage(GC->internal, Item, Reclaimer, GC->allocator); 98 | } 99 | -------------------------------------------------------------------------------- /CommonC/ConcurrentGarbageCollector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_ConcurrentGarbageCollector_h 27 | #define CommonC_ConcurrentGarbageCollector_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /*! 34 | * @brief The garbage collector. 35 | * @description Allows @b CCRetain. 36 | */ 37 | typedef struct CCConcurrentGarbageCollectorInfo *CCConcurrentGarbageCollector; 38 | 39 | 40 | #pragma mark - Creation / Destruction 41 | /*! 42 | * @brief Create a concurrent garbage collector. 43 | * @param Allocator The allocator to be used for the allocation. 44 | * @param Interface The implementation to be used. 45 | * @return A garbage collector, or NULL on failure. Must be destroyed to free the memory. 46 | */ 47 | CC_NEW CCConcurrentGarbageCollector CCConcurrentGarbageCollectorCreate(CCAllocatorType Allocator, const CCConcurrentGarbageCollectorInterface *Interface); 48 | 49 | /*! 50 | * @brief Destroy a garbage collector. 51 | * @warning All usage by other threads must have finish before final destruction. 52 | * @param GC The garbage collector to be destroyed. 53 | */ 54 | void CCConcurrentGarbageCollectorDestroy(CCConcurrentGarbageCollector CC_DESTROY(GC)); 55 | 56 | /*! 57 | * @brief Start collecting. 58 | * @description Any managed pointers added or accessed in this section is safe. 59 | * @param GC The garbage collector to be used. 60 | */ 61 | void CCConcurrentGarbageCollectorBegin(CCConcurrentGarbageCollector GC); 62 | 63 | /*! 64 | * @brief Stop collecting. 65 | * @param GC The garbage collector to be used. 66 | */ 67 | void CCConcurrentGarbageCollectorEnd(CCConcurrentGarbageCollector GC); 68 | 69 | /*! 70 | * @brief Add a pointer to be managed by the garbage collector. 71 | * @param GC The garbage collector to be used. 72 | * @param Item The item to be managed. 73 | * @param Reclaimer The function to be called when the item can be reclaimed (destroyed). 74 | */ 75 | void CCConcurrentGarbageCollectorManage(CCConcurrentGarbageCollector GC, void *Item, CCConcurrentGarbageCollectorReclaimer Reclaimer); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /CommonC/ConcurrentIDGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_ConcurrentIDGenerator_h 27 | #define CommonC_ConcurrentIDGenerator_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /*! 34 | * @brief The concurrent ID generator. 35 | * @description Allows @b CCRetain. 36 | */ 37 | typedef struct CCConcurrentIDGeneratorInfo *CCConcurrentIDGenerator; 38 | 39 | 40 | #pragma mark - Creation / Destruction 41 | /*! 42 | * @brief Create a concurrent ID generator. 43 | * @param Allocator The allocator to be used for the allocation. 44 | * @param Count The number of IDs this generator should manage. 45 | * @param Interface The implementation to be used. 46 | * @return An ID generator, or NULL on failure. Must be destroyed to free the memory. 47 | */ 48 | CC_NEW CCConcurrentIDGenerator CCConcurrentIDGeneratorCreate(CCAllocatorType Allocator, size_t Count, const CCConcurrentIDGeneratorInterface *Interface); 49 | 50 | /*! 51 | * @brief Destroy an ID generator. 52 | * @param Generator The ID generator to be destroyed. 53 | */ 54 | void CCConcurrentIDGeneratorDestroy(CCConcurrentIDGenerator CC_DESTROY(Generator)); 55 | 56 | #pragma mark - Retrieve/Recycle 57 | /*! 58 | * @brief Obtain an ID from the ID generator. 59 | * @performance This function will wait until it has assigned an ID. 60 | * @param Generator The ID generator to get the ID from. 61 | * @return The ID that has been assigned. This ID must be recycled in order for it to become available 62 | * again. 63 | */ 64 | uintptr_t CCConcurrentIDGeneratorAssign(CCConcurrentIDGenerator Generator); 65 | 66 | /*! 67 | * @brief Try obtain an ID from the ID generator. 68 | * @description This will return if no ID is available. 69 | * @param Generator The ID generator to get the ID from. 70 | * @param ID The pointer to where the assigned ID should be stored. This ID must be recycled in order 71 | * for it to become available again. This must not be NULL. 72 | * 73 | * @return Whether an ID was assigned (TRUE), or not (FALSE). 74 | */ 75 | _Bool CCConcurrentIDGeneratorTryAssign(CCConcurrentIDGenerator Generator, uintptr_t *ID); 76 | 77 | /*! 78 | * @brief Recycle an ID to the ID generator. 79 | * @param Generator The ID generator to recycle the ID to. 80 | * @param ID The ID to be recycled. 81 | */ 82 | void CCConcurrentIDGeneratorRecycle(CCConcurrentIDGenerator Generator, uintptr_t ID); 83 | 84 | #pragma mark - Info 85 | 86 | /*! 87 | * @brief Get the max ID this generator may assign. 88 | * @param Generator The ID generator to get the max ID from. 89 | * @return The max ID that can be assigned. 90 | */ 91 | uintptr_t CCConcurrentIDGeneratorGetMaxID(CCConcurrentIDGenerator Generator); 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /CommonC/ConcurrentTree.c: -------------------------------------------------------------------------------- 1 | // 2 | // ConcurrentTree.c 3 | // CommonC 4 | // 5 | // Created by Stefan Johnson on 8/4/18. 6 | // Copyright © 2018 Stefan Johnson. All rights reserved. 7 | // 8 | 9 | #include "ConcurrentTree.h" 10 | -------------------------------------------------------------------------------- /CommonC/ConcurrentTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // ConcurrentTree.h 3 | // CommonC 4 | // 5 | // Created by Stefan Johnson on 8/4/18. 6 | // Copyright © 2018 Stefan Johnson. All rights reserved. 7 | // 8 | 9 | #ifndef ConcurrentTree_h 10 | #define ConcurrentTree_h 11 | 12 | #include 13 | 14 | #endif /* ConcurrentTree_h */ 15 | -------------------------------------------------------------------------------- /CommonC/ConsecutiveIDGenerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCConsecutiveIDGenerator 28 | * CCConsecutiveIDGenerator is an interface for a consecutive (0 to Count-1) ID generator. 29 | * This ID generator is lock-free and is ideally meant for when you need a consecutive ID 30 | * (index) and have a known amount of possible accessors (which should be relatively small). 31 | * Those accessors can then retrieve or recycle as frequently or infrequently 32 | * as they want. 33 | * 34 | * This ID creation pattern is not suited for small pools where IDs are not recycled frequently, 35 | * but lots of threads are attempting to retrieve an ID, as this will result in many threads 36 | * being starved. Nor is it suited for situations where a large number of IDs needs to be 37 | * distributed, as this will result in retrieval time taking too long (if those IDs are not being 38 | * recycled frequently enough). 39 | * 40 | * Allows for many producer-consumer access. 41 | */ 42 | #ifndef CommonC_ConcurrentIDPool_h 43 | #define CommonC_ConcurrentIDPool_h 44 | 45 | #include 46 | 47 | /*! 48 | * @brief A lockfree consecutive ID generator. 49 | * @description The base ID will start at 0 and go up to (Count - 1). Due to this if the 50 | * Count = 2^8 then the ID will be one that can fit within an uint8_t. 51 | * 52 | * @performance Assigning is lock-free and has a worst case of O(n + n/8). While recycling 53 | * is a wait-free O(1) operation. 54 | */ 55 | extern const CCConcurrentIDGeneratorInterface * const CCConsecutiveIDGenerator; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /CommonC/ContainerTypes.h: -------------------------------------------------------------------------------- 1 | //This file is automatically generated, modifications will be lost! 2 | #define CC_CONTAINER_DECLARE_PRESET_CCArray() \ 3 | CC_CONTAINER_DECLARE(CCArray, CCArray); \ 4 | CC_CONTAINER_DECLARE(CCArray, CC_CONTAINER(CCArray, uintmax_t)); \ 5 | CC_CONTAINER_DECLARE(CCArray, uint8_t); 6 | 7 | #define CC_CONTAINER_DECLARE_PRESET_CCCollection() \ 8 | CC_CONTAINER_DECLARE(CCCollection, CCCollectionEntry); \ 9 | CC_CONTAINER_DECLARE(CCCollection, FSPath); 10 | 11 | #define CC_CONTAINER_DECLARE_PRESET_CCConcurrentBuffer() 12 | 13 | #define CC_CONTAINER_DECLARE_PRESET_CCConcurrentIndexMap() 14 | 15 | #define CC_CONTAINER_DECLARE_PRESET_CCConcurrentQueue() 16 | 17 | #define CC_CONTAINER_DECLARE_PRESET_CCData() 18 | 19 | #define CC_CONTAINER_DECLARE_PRESET_CCDictionary() \ 20 | CC_CONTAINER_DECLARE(CCDictionary, CCString, FSVirtualNode); \ 21 | CC_CONTAINER_DECLARE(CCDictionary, CCString, uint32_t); 22 | 23 | #define CC_CONTAINER_DECLARE_PRESET_CCHashMap() 24 | 25 | #define CC_CONTAINER_DECLARE_PRESET_CCLinkedList() \ 26 | CC_CONTAINER_DECLARE(CCLinkedList, CCArray); 27 | 28 | #define CC_CONTAINER_DECLARE_PRESET_CCList() \ 29 | CC_CONTAINER_DECLARE(CCList, uint64_t); 30 | 31 | #define CC_CONTAINER_DECLARE_PRESET_CCOrderedCollection() \ 32 | CC_CONTAINER_DECLARE(CCOrderedCollection, CCString); \ 33 | CC_CONTAINER_DECLARE(CCOrderedCollection, FSPath); \ 34 | CC_CONTAINER_DECLARE(CCOrderedCollection, FSPathComponent); 35 | 36 | #define CC_CONTAINER_DECLARE_PRESET_CCQueue() 37 | -------------------------------------------------------------------------------- /CommonC/CustomFormatSpecifiers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #pragma mark Documentation 28 | /* 29 | Some useful custom format specifier filters. These are not added by default and must manually be added. 30 | 31 | CCBinaryFormatSpecifier: Adds the specifier "%B", which will display the binary form of the integer. The format will display the full number of bits for the 32 | specified length modifier. If the alternate form is used ('#' flag is present), it will display only up to the highest set bit. 33 | */ 34 | 35 | #pragma mark - 36 | 37 | #ifndef CommonC_CustomFormatSpecifiers_h 38 | #define CommonC_CustomFormatSpecifiers_h 39 | 40 | #include 41 | #include 42 | 43 | 44 | #pragma mark - Functions 45 | size_t CCBinaryFormatSpecifier(const CCLogData *LogData, const CCLogSpecifierData *Data); //"%B" : Follows standard for options usage. 46 | size_t CCArrayFormatSpecifier(const CCLogData *LogData, const CCLogSpecifierData *Data); //"%[count{separator}]format_specifier" : Count can either be a value or * (size_t value in arg), separator is optional can be the text or * (char * value in arg), and then the standard format specifier 47 | size_t CCDeletionFormatSpecifier(const CCLogData *LogData, const CCLogSpecifierData *Data); //"%{count}DEL" : Deletes one character from the current buffer, or n characters if the optional count value is used or * (size_t value in arg) 48 | size_t CCStringFormatSpecifier(const CCLogData *LogData, const CCLogSpecifierData *Data); //%S : Prints a string of CCString type. 49 | size_t CCCharFormatSpecifier(const CCLogData *LogData, const CCLogSpecifierData *Data); //%C : Prints a character of CCChar type. 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /CommonC/CustomInputFilters.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include 28 | #include "Logging_Private.h" 29 | #include "CustomInputFilters.h" 30 | #include "MemoryAllocation.h" 31 | 32 | static size_t PathCount = 0; 33 | static struct { char *path; size_t length; } *Paths = NULL; 34 | void CCFileFilterInputAddPath(const char *Path) 35 | { 36 | CC_SAFE_Realloc(Paths, sizeof(typeof(*Paths)) * ++PathCount, 37 | PathCount--; 38 | CC_LOG_ERROR("Failed to add path: %s", Path); 39 | return; 40 | ); 41 | 42 | const size_t Length = strlen(Path); 43 | CC_SAFE_Malloc(Paths[PathCount - 1].path, sizeof(char) * (Length + 1), 44 | PathCount--; 45 | CC_LOG_ERROR("Failed to add path: %s", Path); 46 | return; 47 | ); 48 | 49 | strcpy(Paths[PathCount - 1].path, Path); 50 | Paths[PathCount - 1].length = Length; 51 | } 52 | 53 | size_t CCFileFilterInput(const CCLogData *LogData, const CCLogInputData *Data) 54 | { 55 | for (size_t Loop = 0; Loop < PathCount; Loop++) 56 | { 57 | const size_t Index = (PathCount - 1) - Loop; 58 | const size_t Length = Paths[Index].length; 59 | if (!strncmp(Paths[Index].path, LogData->filename, Length)) 60 | { 61 | CCLogv(*LogData->option, LogData->tag, LogData->identifier, LogData->filename + Length, LogData->functionName, LogData->line, Data->format, *Data->args); 62 | *LogData->option = CCLogOptionNone; 63 | break; 64 | } 65 | } 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /CommonC/CustomInputFilters.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #pragma mark Documentation 28 | /* 29 | Some useful custom input filters. These are not added by default and must manually be added. 30 | 31 | CCFileFilterInput: Adds a simple filename filter. It uses the current list of paths added to CCFileFilterInputAddPath to filter the current filename. 32 | One thing to watchout for is that this is a very naive filter, it simply takes the first match and removes that part. If you happen 33 | to have two paths that would both be true for the current filename, after the first one removes its portion the other one may no 34 | longer be true and so won't remove its portion. The order of precedence for these paths is in the reverse order they were added. 35 | So the last filter added has precedence over all previously added paths. 36 | */ 37 | 38 | #pragma mark - 39 | 40 | #ifndef CommonC_CustomInputFilters_h 41 | #define CommonC_CustomInputFilters_h 42 | 43 | #include 44 | #include 45 | 46 | 47 | #pragma mark - Functions 48 | void CCFileFilterInputAddPath(const char *Path); 49 | size_t CCFileFilterInput(const CCLogData *LogData, const CCLogInputData *Data); //Strips the filename path for filepaths added using CCFileFilterInputAddPath() 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /CommonC/DataBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_DataBuffer_h 27 | #define CommonC_DataBuffer_h 28 | 29 | #include 30 | #include 31 | 32 | /*! 33 | * @typedef CCDataBufferHint 34 | * @brief Hints specific to CCDataBuffer. 35 | */ 36 | CC_EXTENSIBLE_FLAG_ENUM(uint32_t) { 37 | ///Mask for hints for a data container. 38 | CCDataBufferHintMask = 0xff00, 39 | CCDataBufferHintFree = (1 << 8), 40 | CCDataBufferHintCopy = (1 << 9) | CCDataBufferHintFree 41 | }; 42 | 43 | typedef CCDataHint CCDataBufferHint; 44 | 45 | typedef struct { 46 | const void *buffer; 47 | size_t size; 48 | } CCDataBufferInit; 49 | 50 | extern const CCDataInterface * const CCDataBuffer; 51 | 52 | /*! 53 | * @brief Create a data container for regular heap memory. 54 | * @param Allocator The allocator to be used for the allocations. 55 | * @param Hint The hints for the intended usage of this data container. 56 | * 57 | * @b CCDataBufferHintCopy indicates that the input @p Buffer should be copied. 58 | * 59 | * @b CCDataBufferHintFree indicates that the input @p Buffer should be freed on destroy. 60 | * 61 | * Otherwise will just hold a weak reference to the input @p Buffer. 62 | * 63 | * @param Size The size of the @p Buffer. 64 | * @param Buffer The buffer to be stored in the container, must not be NULL. See @p Hint for behaviour. 65 | * @param Hash An optional hashing function to be performed instead of the default for the internal 66 | * implementation. 67 | * 68 | * @param Destructor An optional destructor to perform any custom cleanup on destroy. 69 | * @return A data buffer, or NULL on failure. Must be destroyed to free the memory. 70 | */ 71 | CC_NEW CCData CCDataBufferCreate(CCAllocatorType Allocator, CCDataBufferHint Hint, size_t Size, const void *Buffer, CCDataBufferHash Hash, CCDataBufferDestructor Destructor); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /CommonC/DataTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_DataTypes_h 27 | #define CommonC_DataTypes_h 28 | 29 | #include 30 | 31 | /*! 32 | * @typedef CCDataHint 33 | * @brief Hints for the indended usage of the data container. 34 | */ 35 | typedef CC_EXTENSIBLE_FLAG_ENUM(CCDataHint, int) { 36 | ///Mask for hints for a data container. 37 | CCDataHintMask = 0xff, 38 | CCDataHintResize = (1 << 0), 39 | CCDataHintRead = (1 << 1), 40 | CCDataHintWrite = (1 << 2), 41 | CCDataHintReadWrite = CCDataHintRead | CCDataHintWrite 42 | }; 43 | 44 | /*! 45 | * @brief The data. 46 | * @description Allows @b CCRetain. 47 | */ 48 | typedef struct CCDataInfo *CCData; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /CommonC/DebugTypes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include 28 | #include "DebugTypes.h" 29 | #include "Logging_Private.h" 30 | 31 | static void *ErrorLog(CCFunctionData *FunctionData, void *Data) 32 | { 33 | CCLog(CCLogOptionOutputAll, CCTagError, CC_LOG_IDENTIFIER, FunctionData->filename, FunctionData->functionName, FunctionData->line, "%s", FunctionData->info); 34 | return NULL; 35 | } 36 | 37 | static void *ErrorLogAndExit(CCFunctionData *FunctionData, void *Data) 38 | { 39 | CCLog(CCLogOptionOutputAll, CCTagError, CC_LOG_IDENTIFIER, FunctionData->filename, FunctionData->functionName, FunctionData->line, "%s", FunctionData->info); 40 | exit(0); 41 | return NULL; 42 | } 43 | 44 | 45 | 46 | 47 | const CCErrorCallback CCErrorLog = ErrorLog; 48 | const CCErrorCallback CCErrorLogAndExit = ErrorLogAndExit; 49 | 50 | 51 | -------------------------------------------------------------------------------- /CommonC/DebugTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_DebugTypes_h 27 | #define CommonC_DebugTypes_h 28 | 29 | typedef void *CCFunctionIndicator; //Will be the function pointer 30 | 31 | typedef struct { 32 | CCFunctionIndicator indicator; 33 | const char *info; 34 | const char *filename, *functionName; 35 | int line; 36 | } CCFunctionData; 37 | 38 | typedef void *(*CCErrorCallback)(CCFunctionData *FunctionData, void *Data); 39 | 40 | #if __BLOCKS__ 41 | typedef void *(^CCErrorCallbackBlock)(CCFunctionData *FunctionData, void *Data); 42 | #endif 43 | 44 | 45 | extern const CCErrorCallback CCErrorLog; 46 | extern const CCErrorCallback CCErrorLogAndExit; 47 | 48 | 49 | #ifndef CC_DEFAULT_ERROR_CALLBACK 50 | #define CC_DEFAULT_ERROR_CALLBACK CCErrorLog 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /CommonC/DictionaryHashMap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCDictionaryHashMap 28 | * CCDictionaryHashMap is an interface for an separately chained hashmap backed dictionary implementation. 29 | * 30 | * Fast Operations: 31 | * - Lookup. 32 | * - Insertion. 33 | * 34 | * Moderate Operations: 35 | * - Enumerating of keys. 36 | * - Enumerating of values. 37 | */ 38 | #ifndef CommonC_DictionaryHashMap_h 39 | #define CommonC_DictionaryHashMap_h 40 | 41 | #include 42 | 43 | extern const CCDictionaryInterface CCDictionaryHashMapInterface; 44 | 45 | #define CCDictionaryHashMap &CCDictionaryHashMapInterface 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /CommonC/Enumerable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "Enumerable.h" 28 | 29 | void *CCEnumerableHandler(CCEnumerator *Enumerator, CCEnumerableAction Action) 30 | { 31 | switch (Action) 32 | { 33 | case CCEnumerableActionHead: 34 | Enumerator->state.batch.index = 0; 35 | return Enumerator->state.batch.count ? Enumerator->state.batch.ptr : NULL; 36 | 37 | case CCEnumerableActionTail: 38 | Enumerator->state.batch.index = Enumerator->state.batch.count - 1; 39 | return Enumerator->state.batch.count ? (Enumerator->state.batch.ptr + (Enumerator->state.batch.index * Enumerator->state.batch.stride)) : NULL; 40 | 41 | default: 42 | break; 43 | } 44 | 45 | return NULL; 46 | } 47 | -------------------------------------------------------------------------------- /CommonC/Enumerator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Enumerator_h 27 | #define CommonC_Enumerator_h 28 | 29 | #include 30 | #include 31 | 32 | typedef CC_EXTENSIBLE_FLAG_ENUM(CCEnumeratorFormat, uint32_t) { 33 | CCEnumeratorFormatMask = 3, 34 | CCEnumeratorFormatInternal = 0, 35 | CCEnumeratorFormatFixedBatch, 36 | CCEnumeratorFormatBatch, 37 | CCEnumeratorFormatCircular 38 | }; 39 | 40 | typedef struct { 41 | union { 42 | struct { 43 | void *ptr; 44 | uintptr_t extra[5]; 45 | } internal; 46 | struct { 47 | void *ptr[4]; 48 | size_t count, index; 49 | } fixedBatch; 50 | struct { 51 | void *ptr; 52 | size_t count, stride, index; 53 | uintptr_t extra[2]; 54 | } batch; 55 | struct { 56 | void *ptr; 57 | size_t count, stride, index; 58 | size_t max, start; 59 | } circular; 60 | }; 61 | CCEnumeratorFormat type; //Bits not covered by CCEnumeratorFormatMask may be used to store extra information. 62 | } CCEnumeratorState; 63 | 64 | typedef struct { 65 | void *ref; 66 | uint32_t option; 67 | CCEnumeratorState state; 68 | } CCEnumerator; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /CommonC/EpochGarbageCollector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCEpochGarbageCollector 28 | * CCEpochGarbageCollector is an interface for an epoch based memory reclamation based garbage collector. 29 | * This collector is lock-free and allows for a decent reclamation strategy, without sacrificing too much 30 | * performance. It can handle highly contested situations quite well, albeit at the expense of requiring 31 | * some CAS-loops. 32 | */ 33 | #ifndef CommonC_EpochGarbageCollector_h 34 | #define CommonC_EpochGarbageCollector_h 35 | 36 | #include 37 | 38 | extern const CCConcurrentGarbageCollectorInterface * const CCEpochGarbageCollector; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /CommonC/ExtremaTemplate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #define CCMin_T(t) CC_TEMPLATE_REF(CCMin, t, t, t) 29 | #define CCMax_T(t) CC_TEMPLATE_REF(CCMax, t, t, t) 30 | #define CCClamp_T(t) CC_TEMPLATE_REF(CCClamp, t, t, t, t) 31 | 32 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCMin, (const T a, const T b)); 33 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCMax, (const T a, const T b)); 34 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCClamp, (const T Val, const T Min, const T Max)); 35 | 36 | #pragma mark - 37 | 38 | #ifndef CC_MIN 39 | #define CC_MIN(a, b) (CCNumericLessThan(a, b) ? (a) : (b)) 40 | #endif 41 | 42 | #ifndef CC_MAX 43 | #define CC_MAX(a, b) (CCNumericGreaterThan(a, b) ? (a) : (b)) 44 | #endif 45 | 46 | #ifndef CC_CLAMP 47 | #define CC_CLAMP(val, min, max) CCMin_T(T)(CCMax_T(T)(val, min), max) 48 | #endif 49 | 50 | 51 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCMin, (const T a, const T b)) 52 | { 53 | return CC_MIN(a, b); 54 | } 55 | 56 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCMax, (const T a, const T b)) 57 | { 58 | return CC_MAX(a, b); 59 | } 60 | 61 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCClamp, (const T Val, const T Min, const T Max)) 62 | { 63 | return CC_CLAMP(Val, Min, Max); 64 | } 65 | 66 | #undef CC_MIN 67 | #undef CC_MAX 68 | #undef CC_CLAMP 69 | -------------------------------------------------------------------------------- /CommonC/File.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #include "File.h" 28 | #include 29 | #include "Platform.h" 30 | #include "Types.h" 31 | 32 | #if CC_PLATFORM_POSIX_COMPLIANT 33 | #include 34 | #endif 35 | 36 | 37 | const char *CCLastComponent(const char *Path, size_t *Length, char Separator) 38 | { 39 | /* 40 | Doesn't attempt to achieve any validity in the path, simply finds the last component following these rules: 41 | Path structure: /blah/last (where "last" is the last component if the Separator is '/') 42 | 43 | If it can locate a last component with great flexibility (e.g "////last////", "last", "/////last", etc. will all show "last" as the last component) the last 44 | component. Then it will return the starting point of it, and if it has a fixed length (won't end with a null terminator because there's '/') it will set the 45 | length to that value. Otherwise length will be set to 0 to indicate till null terminator. 46 | 47 | If it cannot locate a last component that is because it is either a NULL pointer, points to a null terminator, or only contains '/' then it returns NULL. 48 | */ 49 | 50 | if (!Path) return NULL; 51 | 52 | *Length = 0; 53 | 54 | const char *LastComponent = strrchr(Path, Separator); 55 | if (!LastComponent) return *Path != 0 ? Path : NULL; 56 | else if (LastComponent[1] != 0) return LastComponent + 1; 57 | 58 | while ((--LastComponent > Path) && (*LastComponent == Separator)); 59 | 60 | const char *End = LastComponent; 61 | 62 | while ((--LastComponent > Path) && (*LastComponent != Separator)); 63 | 64 | if (LastComponent < Path) return NULL; 65 | 66 | 67 | *Length = End - (LastComponent == Path? LastComponent - 1 : LastComponent++); 68 | 69 | return LastComponent; 70 | } 71 | -------------------------------------------------------------------------------- /CommonC/File.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_File_h 27 | #define CommonC_File_h 28 | 29 | #include 30 | 31 | const char *CCLastComponent(const char *Path, size_t *Length, char Separator); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /CommonC/HardwareInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_HardwareInfo_h 27 | #define CommonC_HardwareInfo_h 28 | 29 | #include 30 | 31 | typedef struct { 32 | /// The model name of the CPU. Empty if one could not be found. 33 | char model[256]; 34 | struct { 35 | /// The number of available physical cores. Zero if it could not be found. 36 | size_t physical; 37 | /// The number of available logical cores. Zero if it could not be found. 38 | size_t logical; 39 | } cores; 40 | /// The maximum amount of memory available to the CPU. Zero if it could not be found. 41 | size_t memory; 42 | } CCHardwareCPU; 43 | 44 | typedef struct { 45 | /// The model name of the GPU. Empty if one could not be found. 46 | char model[256]; 47 | /// The number of available cores. Zero if it could not be found. 48 | size_t cores; 49 | /// The maximum amount of VRAM available to the GPU. Zero if it could not be found. 50 | size_t vram; 51 | } CCHardwareGPU; 52 | 53 | /*! 54 | * @brief Get information on the available CPUs. 55 | * @param Processors A pointer to where to store the CPU information. 56 | * @param Count A pointer to the number of CPUs that can be stored. This will also be set to the number actually 57 | * found. 58 | * 59 | * @return Whether or not the information was successfully retrieved. 60 | */ 61 | _Bool CCHardwareGetCPUs(CCHardwareCPU *Processors, size_t *Count); 62 | 63 | /*! 64 | * @brief Get information on the available GPUs. 65 | * @param Processors A pointer to where to store the GPU information. 66 | * @param Count A pointer to the number of GPUs that can be stored. This will also be set to the number actually 67 | * found. 68 | * 69 | * @return Whether or not the information was successfully retrieved. 70 | */ 71 | _Bool CCHardwareGetGPUs(CCHardwareGPU *Processors, size_t *Count); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /CommonC/Hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Hash_h 27 | #define CommonC_Hash_h 28 | 29 | #include 30 | #include 31 | 32 | /*! 33 | * @brief An implementation of Jenkins's one-at-a-time hash 34 | * @see https://en.wikipedia.org/wiki/Jenkins_hash_function#one-at-a-time 35 | * @param Data The data to obtain the hash for. 36 | * @return The hash. 37 | */ 38 | uint32_t CCHashJenkins32(CCData Data); 39 | 40 | /*! 41 | * @brief An implementation of Murmur3 hash 42 | * @see https://en.wikipedia.org/wiki/MurmurHash#Algorithm 43 | * @param Data The data to obtain the hash for. 44 | * @return The hash. 45 | */ 46 | uint32_t CCHashMurmur32(CCData Data); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /CommonC/LazyGarbageCollector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /*! 27 | * @header CCLazyGarbageCollector 28 | * CCLazyGarbageCollector is an interface for a lazy memory reclamation strategy garbage collector. 29 | * This collector is lock-free and is ideally meant for low-contest situations, as the memory is only 30 | * reclaimed when no threads have the GC enabled. 31 | */ 32 | #ifndef CommonC_LazyGarbageCollector_h 33 | #define CommonC_LazyGarbageCollector_h 34 | 35 | #include 36 | 37 | extern const CCConcurrentGarbageCollectorInterface * const CCLazyGarbageCollector; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /CommonC/Logging_Private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Logging_Private_h 27 | #define CommonC_Logging_Private_h 28 | 29 | #undef CC_LOG_IDENTIFIER 30 | #define CC_LOG_IDENTIFIER "io.scrimpycat.common" 31 | #include "Logging.h" 32 | 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /CommonC/Matrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Matrix_h 27 | #define CommonC_Matrix_h 28 | 29 | #include 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /CommonC/PathComponent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_DEFAULT_ALLOCATOR CC_ALIGNED_ALLOCATOR(8) 27 | 28 | #define CC_QUICK_COMPILE 29 | #include "PathComponent.h" 30 | #include "MemoryAllocation.h" 31 | #include "Logging.h" 32 | #include 33 | 34 | FSPathComponent FSPathComponentCreate(FSPathComponentType Type, const char *String) 35 | { 36 | FSPathComponent Component = Type; 37 | 38 | if (String) 39 | { 40 | char *Str; 41 | CC_SAFE_Malloc(Str, sizeof(char) * (strlen(String) + 1), 42 | CC_LOG_ERROR("Failed to create path component due to allocation failure. Allocation size: %zu", sizeof(char) * (strlen(String) + 1)); 43 | return (FSPathComponent)FSPathComponentTypeInvalid; 44 | ); 45 | 46 | strcpy(Str, String); 47 | 48 | Component |= (FSPathComponent)Str; 49 | } 50 | 51 | return Component; 52 | } 53 | 54 | void FSPathComponentDestroy(FSPathComponent Component) 55 | { 56 | void *Ptr = (void*)FSPathComponentGetString(Component); 57 | CC_SAFE_Free(Ptr); 58 | } 59 | 60 | FSPathComponent FSPathComponentCopy(FSPathComponent Component) 61 | { 62 | return FSPathComponentCreate(FSPathComponentGetType(Component), FSPathComponentGetString(Component)); 63 | } 64 | -------------------------------------------------------------------------------- /CommonC/PathComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_PathComponent_h 27 | #define CommonC_PathComponent_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | typedef CC_ENUM(FSPathComponentType, uint8_t) { 34 | FSPathComponentTypeInvalid, 35 | FSPathComponentTypeVolume, 36 | FSPathComponentTypeRoot, 37 | FSPathComponentTypeRelativeRoot, 38 | FSPathComponentTypeDirectory, 39 | FSPathComponentTypeRelativeParentDirectory, 40 | FSPathComponentTypeFile, 41 | FSPathComponentTypeExtension, 42 | FSPathComponentTypeMask = 7 43 | }; 44 | 45 | typedef uintptr_t FSPathComponent; 46 | 47 | 48 | /*! 49 | * @brief Create a path component. 50 | * @param Type The type of the component. 51 | * @param String The name of the component. Only used for components of type: FSPathComponentTypeDirectory, 52 | * FSPathComponentTypeFile, FSPathComponentTypeExtension. But may be used for other component types. 53 | * 54 | * @return The component, or FSPathComponentTypeInvalid on failure. Must be destroyed to free the memory. 55 | */ 56 | CC_NEW FSPathComponent FSPathComponentCreate(FSPathComponentType Type, const char *String); 57 | 58 | /*! 59 | * @brief Destroy a path component. 60 | * @param Component The component to be destroyed. 61 | */ 62 | void FSPathComponentDestroy(FSPathComponent CC_DESTROY(Component)); 63 | 64 | /*! 65 | * @brief Copy a path component. 66 | * @param Component the component to be copied. 67 | * @return The component, or FSPathComponentTypeInvalid on failure. Must be destroyed to free the memory. 68 | */ 69 | CC_NEW FSPathComponent FSPathComponentCopy(FSPathComponent Component); 70 | 71 | /*! 72 | * @brief Get the name of a path component. 73 | * @param Component The path component. 74 | * @return The string, or NULL if it does not have one. 75 | */ 76 | static inline const char *FSPathComponentGetString(FSPathComponent Component); 77 | 78 | /*! 79 | * @brief Get the type of a path component. 80 | * @param Component The path component. 81 | * @return The type. 82 | */ 83 | static inline FSPathComponentType FSPathComponentGetType(FSPathComponent Component); 84 | 85 | 86 | static inline const char *FSPathComponentGetString(FSPathComponent Component) 87 | { 88 | return (char*)(Component & ~FSPathComponentTypeMask); 89 | } 90 | 91 | static inline FSPathComponentType FSPathComponentGetType(FSPathComponent Component) 92 | { 93 | return Component & FSPathComponentTypeMask; 94 | } 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /CommonC/PoolAllocator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "PoolAllocator.h" 27 | #include "MemoryAllocation.h" 28 | 29 | CCPoolAllocator CCPoolAllocatorCreate(CCAllocatorType Allocator, size_t Size, size_t Alignment, size_t Max) 30 | { 31 | const size_t BlockSize = CC_ALIGN(Size + sizeof(CCPoolAllocatorHeader), Alignment); 32 | 33 | CCPoolAllocator Pool = CCMalloc(Allocator, sizeof(CCPoolAllocatorInfo) + (sizeof(size_t) * Max) + (BlockSize * Max), NULL, CC_DEFAULT_ERROR_CALLBACK); 34 | if (Pool) 35 | { 36 | *Pool = (CCPoolAllocatorInfo){ 37 | .blockSize = BlockSize, 38 | .count = 0, 39 | .max = Max, 40 | .pool = (void*)CC_ALIGN((uintptr_t)((uint8_t*)Pool + sizeof(CCPoolAllocatorInfo) + (sizeof(size_t) * Max) + sizeof(CCPoolAllocatorHeader)), Alignment) - sizeof(CCPoolAllocatorHeader), 41 | .available = { 42 | .count = 0, 43 | .indexes = (void*)((uint8_t*)Pool + sizeof(CCPoolAllocatorInfo)) 44 | } 45 | }; 46 | } 47 | 48 | return Pool; 49 | } 50 | 51 | void CCPoolAllocatorDestroy(CCPoolAllocator Pool) 52 | { 53 | CCAssertLog(Pool, "Pool must not be null"); 54 | 55 | CCFree(Pool); 56 | } 57 | -------------------------------------------------------------------------------- /CommonC/Pragmas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | /* 27 | No guarantee to portability with these defines. If unsupported it will just lack that functionality. 28 | 29 | Pragmas: 30 | CC_PRAGMA: _Pragma operator 31 | CC_WARN: Compiler warning message 32 | CC_ERROR: Compiler error message (note if this pragma is unavailable it will not define CC_ERROR) 33 | */ 34 | 35 | #ifndef CommonC_Pragmas_h 36 | #define CommonC_Pragmas_h 37 | 38 | #include 39 | 40 | 41 | #define CC_PRAGMA(...) _Pragma(#__VA_ARGS__) 42 | 43 | #if CC_COMPILER_CLANG || CC_COMPILER_GCC 44 | #define CC_WARNING(...) CC_PRAGMA(GCC warning __VA_ARGS__) 45 | #define CC_ERROR(...) CC_PRAGMA(GCC error __VA_ARGS__) 46 | #else 47 | #define CC_WARNING(...) 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /CommonC/ProcessInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_ProcessInfo_h 27 | #define CommonC_ProcessInfo_h 28 | 29 | #include 30 | #include 31 | 32 | #if CC_PLATFORM_POSIX_COMPLIANT 33 | 34 | #include 35 | #include 36 | 37 | #define CC_PATH_NAME_LENGTH_MAX PATH_MAX 38 | 39 | #else 40 | 41 | #define CC_PATH_NAME_LENGTH_MAX 1024 42 | 43 | #endif 44 | 45 | typedef uintptr_t CCPid; 46 | 47 | 48 | CCPid CCProcessCurrent(void); 49 | const char *CCProcessCurrentPath(void); 50 | const char *CCProcessCurrentName(void); 51 | const char *CCProcessCurrentStrippedName(void); 52 | const char *CCHostCurrentName(void); 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /CommonC/Random.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "Random.h" 27 | 28 | CCRandomState_xorshift CCRandomGlobalState_xorshift = 1; 29 | 30 | uint32_t CCRandom_xorshift(CCRandomState_xorshift *State) 31 | { 32 | *State ^= *State << 13; 33 | *State ^= *State >> 17; 34 | *State ^= *State << 5; 35 | 36 | return *State; 37 | } 38 | 39 | uint32_t CCRandomMax_xorshift(void) 40 | { 41 | return UINT32_MAX; 42 | } 43 | 44 | void CCRandomSeed_xorshift(CCRandomState_xorshift *State, uint32_t Seed) 45 | { 46 | *State = Seed ? Seed : 1; 47 | } 48 | 49 | CCRandomState_xorwow CCRandomGlobalState_xorwow = { 270369, 67634689, 2647435461, 307599695, 2398689233 }; 50 | 51 | uint32_t CCRandom_xorwow(CCRandomState_xorwow *State) 52 | { 53 | uint32_t t = State->d; 54 | const uint32_t s = State->a; 55 | State->d = State->c; 56 | State->c = State->b; 57 | State->b = s; 58 | 59 | t ^= t >> 2; 60 | t ^= t << 1; 61 | t ^= s ^ (s << 4); 62 | State->a = t; 63 | 64 | State->counter += 362437; 65 | 66 | return t + State->counter; 67 | } 68 | 69 | uint32_t CCRandomMax_xorwow(void) 70 | { 71 | return UINT32_MAX; 72 | } 73 | 74 | void CCRandomSeed_xorwow(CCRandomState_xorwow *State, uint32_t Seed) 75 | { 76 | CCRandomState_xorshift Xorshift; 77 | CCRandomSeed_xorshift(&Xorshift, Seed); 78 | 79 | *State = (CCRandomState_xorwow){ 80 | .a = CCRandom_xorshift(&Xorshift), 81 | .b = CCRandom_xorshift(&Xorshift), 82 | .c = CCRandom_xorshift(&Xorshift), 83 | .d = CCRandom_xorshift(&Xorshift), 84 | .counter = CCRandom_xorshift(&Xorshift) 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /CommonC/RangeBaseTemplate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #define CCRangeMake_T(t) CC_TEMPLATE_REF(CCRangeMake, PRIVATE(CCRange(Ttype), range), t, t) 29 | 30 | #undef CCRange 31 | 32 | CC_TEMPLATE(static CC_FORCE_INLINE PRIVATE(CCRange(Ttype), range), CCRangeMake, (const T Start, const T Length)); 33 | 34 | #pragma mark - 35 | 36 | CC_TEMPLATE(static CC_FORCE_INLINE PRIVATE(CCRange(Ttype), range), CCRangeMake, (const T Start, const T Length)) 37 | { 38 | return (CC_RANGE(Ttype)){ .start = Start, .length = Length }; 39 | 40 | } 41 | 42 | #define CCRange(type) CC_RANGE(type) 43 | -------------------------------------------------------------------------------- /CommonC/RangeTemplate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2025, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | 28 | #define CCRangeContainsRange_T(t) CC_TEMPLATE_REF(CCRangeContains, _Bool, t, t) 29 | #define CCRangeIntersectRange_T(t) CC_TEMPLATE_REF(CCRangeIntersects, _Bool, t, t) 30 | #define CCRangeGetIntersection_T(t) CC_TEMPLATE_REF(CCRangeGetIntersection, t, t, t) 31 | 32 | #undef CCRange 33 | 34 | CC_TEMPLATE(static CC_FORCE_INLINE _Bool, CCRangeContains, (const T Range, const T InnerRange)); 35 | CC_TEMPLATE(static CC_FORCE_INLINE _Bool, CCRangeIntersects, (const T RangeA, const T RangeB)); 36 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCRangeGetIntersection, (const T RangeA, const T RangeB)); 37 | 38 | #pragma mark - 39 | 40 | #ifndef CC_RANGE_VALUE_LESS_THAN 41 | #define CC_RANGE_VALUE_LESS_THAN(a, b) CCNumericLessThan((a), (b)) 42 | #endif 43 | 44 | #ifndef CC_RANGE_VALUE_GREATER_THAN 45 | #define CC_RANGE_VALUE_GREATER_THAN(a, b) CCNumericGreaterThan((a), (b)) 46 | #endif 47 | 48 | #ifndef CC_RANGE_VALUE_LESS_THAN_EQUAL 49 | #define CC_RANGE_VALUE_LESS_THAN_EQUAL(a, b) CCNumericLessThanEqual((a), (b)) 50 | #endif 51 | 52 | #ifndef CC_RANGE_VALUE_GREATER_THAN_EQUAL 53 | #define CC_RANGE_VALUE_GREATER_THAN_EQUAL(a, b) CCNumericGreaterThanEqual((a), (b)) 54 | #endif 55 | 56 | #ifndef CC_RANGE_VALUE_ADD 57 | #define CC_RANGE_VALUE_ADD(a, b) CCNumericAdd((a), (b)) 58 | #endif 59 | 60 | #ifndef CC_RANGE_VALUE_SUB 61 | #define CC_RANGE_VALUE_SUB(a, b) CCNumericSubtract((a), (b)) 62 | #endif 63 | 64 | #ifndef CC_RANGE_VALUE_MAX 65 | #define CC_RANGE_VALUE_MAX(a, b) CCMax((a), (b)) 66 | #endif 67 | 68 | #ifndef CC_RANGE_VALUE_MIN 69 | #define CC_RANGE_VALUE_MIN(a, b) CCMin((a), (b)) 70 | #endif 71 | 72 | CC_TEMPLATE(static CC_FORCE_INLINE _Bool, CCRangeContains, (const T Range, const T InnerRange)) 73 | { 74 | return CC_RANGE_VALUE_LESS_THAN_EQUAL(Range.start, InnerRange.start) && CC_RANGE_VALUE_GREATER_THAN_EQUAL(CC_RANGE_VALUE_ADD(Range.start, Range.length), CC_RANGE_VALUE_ADD(InnerRange.start, InnerRange.length)); 75 | } 76 | 77 | CC_TEMPLATE(static CC_FORCE_INLINE _Bool, CCRangeIntersects, (const T RangeA, const T RangeB)) 78 | { 79 | return CC_RANGE_VALUE_LESS_THAN_EQUAL(RangeA.start, CC_RANGE_VALUE_ADD(RangeB.start, RangeB.length)) && CC_RANGE_VALUE_GREATER_THAN_EQUAL(CC_RANGE_VALUE_ADD(RangeA.start, RangeA.length), RangeB.start); 80 | } 81 | 82 | CC_TEMPLATE(static CC_FORCE_INLINE T, CCRangeGetIntersection, (const T RangeA, const T RangeB)) 83 | { 84 | const Ttype Start = CC_RANGE_VALUE_MAX(RangeA.start, RangeB.start); 85 | 86 | return CCRangeMake(Start, CC_RANGE_VALUE_SUB(CC_RANGE_VALUE_MIN(CC_RANGE_VALUE_ADD(RangeA.start, RangeA.length), CC_RANGE_VALUE_ADD(RangeB.start, RangeB.length)), Start)); 87 | } 88 | 89 | #define CCRange(type) CC_RANGE(type) 90 | -------------------------------------------------------------------------------- /CommonC/Swap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Swap_h 27 | #define CommonC_Swap_h 28 | 29 | #include 30 | 31 | /*! 32 | * @brief Swap the byte order for the data. 33 | * @param Data The data to be re-arranged. 34 | * @param Size The size of the data. 35 | */ 36 | static inline void CCSwap(void *Data, size_t Size); 37 | 38 | #pragma mark - 39 | 40 | static inline void CCSwap(void *Data, size_t Size) 41 | { 42 | for (size_t Loop = 0, Count = Size / 2; Loop < Count; Loop++) 43 | { 44 | const uint8_t Temp = ((uint8_t*)Data)[Loop]; 45 | ((uint8_t*)Data)[Loop] = ((uint8_t*)Data)[Size - Loop - 1]; 46 | ((uint8_t*)Data)[Size - Loop - 1] = Temp; 47 | } 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /CommonC/SystemInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_SystemInfo_h 27 | #define CommonC_SystemInfo_h 28 | 29 | #include 30 | #include 31 | 32 | #if CC_PLATFORM_OS_X 33 | #define CC_PLATFORM_APPLE_RUNTIME_VERSION_MIN_REQUIRED(osx, ios) (CCSystemVersionLiteral() >= (osx)) 34 | #elif CC_PLATFORM_IOS 35 | #define CC_PLATFORM_APPLE_RUNTIME_VERSION_MIN_REQUIRED(osx, ios) (CCSystemVersionLiteral() >= (ios)) 36 | #endif 37 | 38 | 39 | void CCSystemVersion(uint32_t *Major, uint32_t *Minor, uint32_t *BugFix); 40 | uint32_t CCSystemVersionLiteral(void); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /CommonC/ValidateMaximum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_ValidateMaximum_h 27 | #define CommonC_ValidateMaximum_h 28 | 29 | #include 30 | 31 | 32 | #define CC_REFLECT_VALIDATE_MAXIMUM(type_, max_, success_, failure_) ((CCReflectMaximumValidator){ .validator = CC_REFLECT_VALIDATOR(type_, CCReflectValidateMaximum, success_, failure_), .max = max_ }) 33 | 34 | typedef struct { 35 | CCReflectValidator validator; 36 | CCReflectValue max; 37 | } CCReflectMaximumValidator; 38 | 39 | _Bool CCReflectValidateMaximum(CCReflectType Type, const void *Data, CCReflectType Validator); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /CommonC/ValidateMinimum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_ValidateMinimum_h 27 | #define CommonC_ValidateMinimum_h 28 | 29 | #include 30 | 31 | 32 | #define CC_REFLECT_VALIDATE_MINIMUM(type_, min_, success_, failure_) ((CCReflectMinimumValidator){ .validator = CC_REFLECT_VALIDATOR(type_, CCReflectValidateMinimum, success_, failure_), .min = min_ }) 33 | 34 | typedef struct { 35 | CCReflectValidator validator; 36 | CCReflectValue min; 37 | } CCReflectMinimumValidator; 38 | 39 | _Bool CCReflectValidateMinimum(CCReflectType Type, const void *Data, CCReflectType Validator); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /CommonC/Vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef CommonC_Vector_h 27 | #define CommonC_Vector_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #define T CCVector2D 34 | #define CC_NUMERIC_EQUAL CCVector2Equal 35 | #define CC_NUMERIC_LESS_THAN CCVector2LessThan 36 | #define CC_NUMERIC_GREATER_THAN CCVector2GreaterThan 37 | #define CC_NUMERIC_LESS_THAN_EQUAL CCVector2LessThanEqual 38 | #define CC_NUMERIC_GREATER_THAN_EQUAL CCVector2GreaterThanEqual 39 | #define CC_NUMERIC_ADD CCVector2Add 40 | #define CC_NUMERIC_SUB CCVector2Sub 41 | #define CC_NUMERIC_MUL CCVector2Mul 42 | #define CC_NUMERIC_DIV CCVector2Div 43 | #include 44 | 45 | #define T CCVector2D 46 | #define CC_MIN CCVector2Min 47 | #define CC_MAX CCVector2Max 48 | #define CC_CLAMP CCVector2Clamp 49 | #include 50 | 51 | #define T CCVector3D 52 | #define CC_NUMERIC_EQUAL CCVector3Equal 53 | #define CC_NUMERIC_LESS_THAN CCVector3LessThan 54 | #define CC_NUMERIC_GREATER_THAN CCVector3GreaterThan 55 | #define CC_NUMERIC_LESS_THAN_EQUAL CCVector3LessThanEqual 56 | #define CC_NUMERIC_GREATER_THAN_EQUAL CCVector3GreaterThanEqual 57 | #define CC_NUMERIC_ADD CCVector3Add 58 | #define CC_NUMERIC_SUB CCVector3Sub 59 | #define CC_NUMERIC_MUL CCVector3Mul 60 | #define CC_NUMERIC_DIV CCVector3Div 61 | #include 62 | 63 | #define T CCVector3D 64 | #define CC_MIN CCVector3Min 65 | #define CC_MAX CCVector3Max 66 | #define CC_CLAMP CCVector3Clamp 67 | #include 68 | 69 | #define T CCVector4D 70 | #define CC_NUMERIC_EQUAL CCVector4Equal 71 | #define CC_NUMERIC_LESS_THAN CCVector4LessThan 72 | #define CC_NUMERIC_GREATER_THAN CCVector4GreaterThan 73 | #define CC_NUMERIC_LESS_THAN_EQUAL CCVector4LessThanEqual 74 | #define CC_NUMERIC_GREATER_THAN_EQUAL CCVector4GreaterThanEqual 75 | #define CC_NUMERIC_ADD CCVector4Add 76 | #define CC_NUMERIC_SUB CCVector4Sub 77 | #define CC_NUMERIC_MUL CCVector4Mul 78 | #define CC_NUMERIC_DIV CCVector4Div 79 | #include 80 | 81 | #define T CCVector4D 82 | #define CC_MIN CCVector4Min 83 | #define CC_MAX CCVector4Max 84 | #define CC_CLAMP CCVector4Clamp 85 | #include 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /CommonC/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CommonCTests/AlignedAllocatorTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import "MemoryAllocation.h" 28 | #import "Alignment.h" 29 | 30 | @interface AlignedAllocatorTests : XCTestCase 31 | 32 | @end 33 | 34 | @implementation AlignedAllocatorTests 35 | 36 | -(void) testAlignment 37 | { 38 | int *Ptr = CCMalloc(CC_ALIGNED_ALLOCATOR(64), sizeof(int), NULL, NULL); 39 | *Ptr = 0x636261; 40 | 41 | XCTAssertEqual((uintptr_t)Ptr, CC_ALIGN((uintptr_t)Ptr, 64), @"allocated memory should be aligned"); 42 | 43 | Ptr = CCRealloc(CC_ALIGNED_ALLOCATOR(64), Ptr, sizeof(int) * 1024, NULL, NULL); 44 | 45 | XCTAssertEqual((uintptr_t)Ptr, CC_ALIGN((uintptr_t)Ptr, 64), @"allocated memory should be aligned"); 46 | XCTAssertEqual(*Ptr, 0x636261, @"should preserve the old data"); 47 | 48 | CCFree(Ptr); 49 | 50 | Ptr = CCMalloc(CC_ALIGNED_ALLOCATOR(16384), sizeof(int), NULL, NULL); 51 | *Ptr = 0x636261; 52 | 53 | XCTAssertEqual((uintptr_t)Ptr, CC_ALIGN((uintptr_t)Ptr, 16384), @"allocated memory should be aligned"); 54 | 55 | Ptr = CCRealloc(CC_ALIGNED_ALLOCATOR(16384), Ptr, sizeof(int) * 1024, NULL, NULL); 56 | 57 | XCTAssertEqual((uintptr_t)Ptr, CC_ALIGN((uintptr_t)Ptr, 16384), @"allocated memory should be aligned"); 58 | XCTAssertEqual(*Ptr, 0x636261, @"should preserve the old data"); 59 | 60 | CCFree(Ptr); 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /CommonCTests/AllocatorTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface AllocatorTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/BitTricksTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface BitTricksTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/CollectionArrayTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "CollectionArray.h" 29 | #import "OrderedCollectionTests.h" 30 | 31 | @interface CollectionArrayTests : OrderedCollectionTests 32 | 33 | @end 34 | 35 | @implementation CollectionArrayTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCCollectionArray; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/CollectionFastArrayTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "CollectionFastArray.h" 29 | #import "OrderedCollectionTests.h" 30 | 31 | @interface CollectionFastArrayTests : OrderedCollectionTests 32 | 33 | @end 34 | 35 | @implementation CollectionFastArrayTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCCollectionFastArray; 41 | } 42 | 43 | -(void) testCollectionFinding {} 44 | 45 | -(void) testCollectionRemoval {} 46 | 47 | -(void) testRemoval {} 48 | 49 | -(void) testIndexedInserting {} 50 | 51 | -(void) testIndexedRemoving {} 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /CommonCTests/CollectionListTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "CollectionList.h" 29 | #import "OrderedCollectionTests.h" 30 | 31 | @interface CollectionListTests : OrderedCollectionTests 32 | 33 | @end 34 | 35 | @implementation CollectionListTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCCollectionList; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/CollectionTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #import 28 | #import 29 | #import "CollectionInterface.h" 30 | 31 | @interface CollectionTests : XCTestCase 32 | 33 | @property const CCCollectionInterface *interface; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /CommonCTests/CommonCTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CommonCTests/CompileTimeSortTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #define CC_QUICK_COMPILE 27 | #import 28 | #import "Extensions.h" 29 | #import "Hacks.h" 30 | 31 | @interface CompileTimeSortTests : XCTestCase 32 | 33 | @end 34 | 35 | @implementation CompileTimeSortTests 36 | 37 | uint64_t x[3] = { CC_UNIQUE_SORT(99, 18, 64) }; 38 | uint64_t y[2] = { CC_UNIQUE_SORT(2, 0) }; 39 | uint64_t u[3] = { CC_UNIQUE_SORT(99, 64, 64) }; 40 | 41 | - (void)testExample 42 | { 43 | XCTAssertEqual(x[0], 18, @"Should sort"); 44 | XCTAssertEqual(x[1], 64, @"Should sort"); 45 | XCTAssertEqual(x[2], 99, @"Should sort"); 46 | 47 | XCTAssertEqual(y[0], 0, @"Should sort"); 48 | XCTAssertEqual(y[1], 2, @"Should sort"); 49 | 50 | XCTAssertEqual(u[0], 64, @"Should remove duplicates"); 51 | XCTAssertEqual(u[1], 99, @"Should remove duplicates"); 52 | XCTAssertEqual(u[2], 0, @"Should remove duplicates"); 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /CommonCTests/ConcurrentIndexBuffer.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import "ConcurrentIndexBuffer.h" 28 | 29 | @interface ConcurrentIndexBuffer : XCTestCase 30 | 31 | @end 32 | 33 | @implementation ConcurrentIndexBuffer 34 | 35 | -(void) testReadWithoutWrite 36 | { 37 | CCConcurrentIndexBuffer IndexBuffer = CCConcurrentIndexBufferCreate(CC_STD_ALLOCATOR, 3); 38 | 39 | XCTAssertFalse(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &(size_t){ 0 }), @"Should return false no index was staged"); 40 | XCTAssertFalse(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &(size_t){ 0 }), @"Should return false no index was staged"); 41 | 42 | CCConcurrentIndexBufferDestroy(IndexBuffer); 43 | } 44 | 45 | -(void) testReadWithWrite 46 | { 47 | CCConcurrentIndexBuffer IndexBuffer = CCConcurrentIndexBufferCreate(CC_STD_ALLOCATOR, 3); 48 | 49 | size_t Index = CCConcurrentIndexBufferWriteAcquire(IndexBuffer), ReadIndex; 50 | XCTAssertFalse(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &ReadIndex), @"Should return false no index was staged"); 51 | 52 | CCConcurrentIndexBufferStage(IndexBuffer, Index); 53 | XCTAssertTrue(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &ReadIndex), @"Should return true when index is staged"); 54 | XCTAssertEqual(Index, ReadIndex, @"Index should match the last staged"); 55 | 56 | CCConcurrentIndexBufferDiscard(IndexBuffer, ReadIndex); 57 | XCTAssertFalse(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &ReadIndex), @"Should return false no index was staged"); 58 | 59 | Index = CCConcurrentIndexBufferWriteAcquire(IndexBuffer); 60 | CCConcurrentIndexBufferDiscard(IndexBuffer, Index); 61 | XCTAssertFalse(CCConcurrentIndexBufferReadAcquire(IndexBuffer, &ReadIndex), @"Should return false no index was staged"); 62 | 63 | CCConcurrentIndexBufferDestroy(IndexBuffer); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /CommonCTests/ConcurrentSwapBufferTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | #define Titem int 29 | #include "ConcurrentSwapBuffer.h" 30 | 31 | #define Titem float 32 | #include "ConcurrentSwapBuffer.h" 33 | 34 | @interface ConcurrentSwapBufferTests : XCTestCase 35 | 36 | @end 37 | 38 | @implementation ConcurrentSwapBufferTests 39 | 40 | -(void) testSwappingBuffers 41 | { 42 | CCConcurrentSwapBuffer(int) Swap = CC_CONCURRENT_SWAP_BUFFER_INIT; 43 | 44 | memset(Swap.buffer, 0, sizeof(int) * 3); 45 | 46 | int *Future = CCConcurrentSwapBufferGetFuture(&Swap); 47 | 48 | *Future = 1; 49 | 50 | Future = CCConcurrentSwapBufferGetFuture(&Swap); 51 | 52 | *Future = 2; 53 | 54 | CCConcurrentSwapBufferApply(&Swap); 55 | 56 | Future = CCConcurrentSwapBufferGetFuture(&Swap); 57 | 58 | *Future = 3; 59 | 60 | const int *Read = CCConcurrentSwapBufferRead(&Swap); 61 | 62 | XCTAssertEqual(*Read, 2, @"Shouold get the correct buffer"); 63 | 64 | Read = CCConcurrentSwapBufferRead(&Swap); 65 | 66 | XCTAssertEqual(*Read, 2, @"Shouold get the correct buffer"); 67 | 68 | CCConcurrentSwapBufferApply(&Swap); 69 | 70 | Read = CCConcurrentSwapBufferRead(&Swap); 71 | 72 | XCTAssertEqual(*Read, 3, @"Shouold get the correct buffer"); 73 | 74 | 75 | 76 | CCConcurrentSwapBuffer(float) SwapF = CC_CONCURRENT_SWAP_BUFFER_INIT; 77 | 78 | memset(SwapF.buffer, 0, sizeof(float) * 3); 79 | 80 | float *FutureF = CCConcurrentSwapBufferGetFuture(&SwapF); 81 | 82 | *FutureF = 1.0f; 83 | 84 | FutureF = CCConcurrentSwapBufferGetFuture(&SwapF); 85 | 86 | *FutureF = 2.0f; 87 | 88 | CCConcurrentSwapBufferApply(&SwapF); 89 | 90 | FutureF = CCConcurrentSwapBufferGetFuture(&SwapF); 91 | 92 | *FutureF = 3.0f; 93 | 94 | const float *ReadF = CCConcurrentSwapBufferRead(&SwapF); 95 | 96 | XCTAssertEqual(*ReadF, 2.0f, @"Shouold get the correct buffer"); 97 | 98 | ReadF = CCConcurrentSwapBufferRead(&SwapF); 99 | 100 | XCTAssertEqual(*ReadF, 2.0f, @"Shouold get the correct buffer"); 101 | 102 | CCConcurrentSwapBufferApply(&SwapF); 103 | 104 | ReadF = CCConcurrentSwapBufferRead(&SwapF); 105 | 106 | XCTAssertEqual(*ReadF, 3.0f, @"Shouold get the correct buffer"); 107 | } 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /CommonCTests/ContainerTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import "Container.h" 28 | 29 | @interface ContainerTests : XCTestCase 30 | 31 | @end 32 | 33 | @implementation ContainerTests 34 | 35 | CC_CONTAINER_DECLARE(int32_t, int8_t); 36 | CC_CONTAINER_DECLARE(int32_t, int8_t, int16_t); 37 | CC_CONTAINER_DECLARE(int16_t, CC_CONTAINER(int32_t, int8_t)); 38 | 39 | typedef int8_t int32_t_int16_t; 40 | 41 | -(void) testExample 42 | { 43 | XCTAssertEqual(sizeof(CC_CONTAINER(int32_t, int8_t)), sizeof(int32_t), @"Should be the same size as the original"); 44 | XCTAssertEqual(sizeof(CC_CONTAINER(int32_t, int16_t)), sizeof(int8_t), @"Should be the size of the explicit alias"); 45 | #define CC_CONTAINER_TYPE_DISABLE 46 | XCTAssertEqual(sizeof(CC_CONTAINER(int32_t, int16_t)), sizeof(int32_t), @"Should not reference the alias"); 47 | #undef CC_CONTAINER_TYPE_DISABLE 48 | 49 | XCTAssertEqual(sizeof(int32_t_int8_t), sizeof(int32_t), @"Should create an alias"); 50 | XCTAssertEqual(sizeof(int32_t_int8_t_int16_t), sizeof(int32_t), @"Should create an alias"); 51 | XCTAssertEqual(sizeof(int16_t_int32_t_int8_t), sizeof(int16_t), @"Should create an alias"); 52 | 53 | XCTAssertEqual(sizeof(CC_CONTAINER(int16_t, CC_CONTAINER(int32_t, int8_t))), sizeof(int16_t), @"Should handle nesting"); 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /CommonCTests/DataBufferTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import "DataTests.h" 27 | #import "DataBuffer.h" 28 | #import "MemoryAllocation.h" 29 | 30 | @interface DataBufferTests : DataTests 31 | 32 | @end 33 | 34 | @implementation DataBufferTests 35 | 36 | -(const CCDataInterface*) interface 37 | { 38 | return CCDataBuffer; 39 | } 40 | 41 | -(CCData) createDataOfSize: (size_t)size WithHint: (CCDataHint)hint 42 | { 43 | return CCDataBufferCreate(CC_STD_ALLOCATOR, hint | CCDataBufferHintFree, size, CCMalloc(CC_STD_ALLOCATOR, size, NULL, CC_DEFAULT_ERROR_CALLBACK), NULL, NULL); 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /CommonCTests/DataTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #import 28 | #import 29 | #import "DataInterface.h" 30 | 31 | @interface DataTests : XCTestCase 32 | 33 | @property const CCDataInterface *interface; 34 | 35 | -(CCData) createDataOfSize: (size_t)size WithHint: (CCDataHint)hint; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /CommonCTests/DictionaryHashMapTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "DictionaryHashMap.h" 29 | #import "DictionaryTests.h" 30 | 31 | @interface DictionaryHashMapTests : DictionaryTests 32 | 33 | @end 34 | 35 | @implementation DictionaryHashMapTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCDictionaryHashMap; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/DictionaryTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #import 28 | #import 29 | #import "DictionaryInterface.h" 30 | 31 | @interface DictionaryTests : XCTestCase 32 | 33 | @property const CCDictionaryInterface *interface; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /CommonCTests/FileHandleTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface FileHandleTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/FileSystemTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface FileSystemTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/FileTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface FileTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/HashMapSeparateChainingArrayDataOrientedAllTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "HashMapSeparateChainingArrayDataOrientedAll.h" 29 | #import "HashMapTests.h" 30 | 31 | @interface HashMapSeparateChainingArrayDataOrientedAllTests : HashMapTests 32 | 33 | @end 34 | 35 | @implementation HashMapSeparateChainingArrayDataOrientedAllTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCHashMapSeparateChainingArrayDataOrientedAll; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/HashMapSeparateChainingArrayDataOrientedHash.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "HashMapSeparateChainingArrayDataOrientedHash.h" 29 | #import "HashMapTests.h" 30 | 31 | @interface HashMapSeparateChainingArrayDataOrientedHashTests : HashMapTests 32 | 33 | @end 34 | 35 | @implementation HashMapSeparateChainingArrayDataOrientedHashTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCHashMapSeparateChainingArrayDataOrientedHash; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/HashMapSeparateChainingArrayTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #import 28 | #import "HashMapSeparateChainingArray.h" 29 | #import "HashMapTests.h" 30 | 31 | @interface HashMapSeparateChainingArrayTests : HashMapTests 32 | 33 | @end 34 | 35 | @implementation HashMapSeparateChainingArrayTests 36 | 37 | -(void) setUp 38 | { 39 | [super setUp]; 40 | self.interface = CCHashMapSeparateChainingArray; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /CommonCTests/HashMapTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #import 28 | #import 29 | #import "HashMapInterface.h" 30 | 31 | @interface HashMapTests : XCTestCase 32 | 33 | @property const CCHashMapInterface *interface; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /CommonCTests/LoggingTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface LoggingTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/LoggingTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import "LoggingTests.h" 27 | #import "Logging.h" 28 | 29 | 30 | @implementation LoggingTests 31 | 32 | -(void) testCCLog 33 | { 34 | /* 35 | Log to file, check if log is structured correctly. 36 | */ 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CommonCTests/MemoryAllocationTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | 28 | @interface MemoryAllocationTests : XCTestCase 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /CommonCTests/OrderedCollectionTests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | 27 | #import "CollectionTests.h" 28 | 29 | @interface OrderedCollectionTests : CollectionTests 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /CommonCTests/RandomTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import 27 | #define CC_RANDOM_XORSHIFT 1 28 | #import "Random.h" 29 | 30 | @interface RandomTests : XCTestCase 31 | 32 | @end 33 | 34 | @implementation RandomTests 35 | 36 | -(void) testGlobalState 37 | { 38 | uint32_t Values[4]; 39 | 40 | Values[0] = CCRandom(); 41 | Values[1] = CCRandom(); 42 | 43 | typeof(CCRandomState) State = CCRandomState; 44 | Values[2] = CCRandom(); 45 | Values[3] = CCRandom(); 46 | 47 | XCTAssertEqual(Values[0], 270369, @"Should be reproducible"); 48 | XCTAssertEqual(Values[1], 67634689, @"Should be reproducible"); 49 | XCTAssertEqual(Values[2], 2647435461, @"Should be reproducible"); 50 | XCTAssertEqual(Values[3], 307599695, @"Should be reproducible"); 51 | 52 | CCRandomState = State; 53 | 54 | XCTAssertEqual(Values[2], CCRandom(), @"Should return to earlier stage"); 55 | XCTAssertEqual(Values[3], CCRandom(), @"Should return to earlier stage"); 56 | 57 | 58 | CCRandomSeed(3); 59 | Values[0] = CCRandom(); 60 | Values[1] = CCRandom(); 61 | 62 | State = CCRandomState; 63 | Values[2] = CCRandom(); 64 | Values[3] = CCRandom(); 65 | 66 | XCTAssertEqual(Values[0], 811107, @"Should be reproducible"); 67 | XCTAssertEqual(Values[1], 201886211, @"Should be reproducible"); 68 | XCTAssertEqual(Values[2], 3025432647, @"Should be reproducible"); 69 | XCTAssertEqual(Values[3], 1909268553, @"Should be reproducible"); 70 | 71 | CCRandomState = State; 72 | 73 | XCTAssertEqual(Values[2], CCRandom(), @"Should return to earlier stage"); 74 | XCTAssertEqual(Values[3], CCRandom(), @"Should return to earlier stage"); 75 | 76 | 77 | CCRandomSeed(0); 78 | 79 | XCTAssertEqual(CCRandom(), 270369, @"Should be reproducible"); 80 | XCTAssertEqual(CCRandom(), 67634689, @"Should be reproducible"); 81 | XCTAssertEqual(CCRandom(), 2647435461, @"Should be reproducible"); 82 | XCTAssertEqual(CCRandom(), 307599695, @"Should be reproducible"); 83 | 84 | CCRandomState = State; 85 | CCData Data = CCRandomGetState(); 86 | 87 | XCTAssertEqual(Values[2], CCRandom(), @"Should return to earlier stage"); 88 | XCTAssertEqual(Values[3], CCRandom(), @"Should return to earlier stage"); 89 | 90 | CCRandomSetState(Data); 91 | 92 | XCTAssertEqual(Values[2], CCRandom(), @"Should return to earlier stage"); 93 | XCTAssertEqual(Values[3], CCRandom(), @"Should return to earlier stage"); 94 | 95 | CCDataDestroy(Data); 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /CommonCTests/VirtualFileHandleTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import "FileHandleTests.h" 27 | #import "Path.h" 28 | #import "FileSystem.h" 29 | 30 | @interface VirtualFileHandleTests : FileHandleTests 31 | 32 | @end 33 | 34 | @implementation VirtualFileHandleTests 35 | { 36 | FSPath path; 37 | } 38 | 39 | -(void) setUp 40 | { 41 | path = FSPathCreate("//[MEMORY]/private/tmp/"); 42 | FSPathSetCurrent(path); 43 | 44 | FSManagerCreate(path, TRUE); 45 | 46 | [super setUp]; 47 | } 48 | 49 | -(void) tearDown 50 | { 51 | [super tearDown]; 52 | 53 | FSPathSetCurrent(NULL); 54 | FSPathDestroy(path); 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /CommonCTests/VirtualFileSystemTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Stefan Johnson 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this list 9 | * of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 11 | * list of conditions and the following disclaimer in the documentation and/or other 12 | * materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #import "FileSystemTests.h" 27 | #import "Path.h" 28 | #import "FileSystem.h" 29 | 30 | @interface VirtualFileSystemTests : FileSystemTests 31 | 32 | @end 33 | 34 | @implementation VirtualFileSystemTests 35 | { 36 | FSPath path; 37 | } 38 | 39 | -(void) setUp 40 | { 41 | path = FSPathCreate("//[MEMORY]/private/tmp/"); 42 | FSPathSetCurrent(path); 43 | 44 | FSManagerCreate(path, TRUE); 45 | 46 | [super setUp]; 47 | } 48 | 49 | -(void) tearDown 50 | { 51 | [super tearDown]; 52 | 53 | FSPathSetCurrent(NULL); 54 | FSPathDestroy(path); 55 | } 56 | 57 | -(void) testCurrentPath 58 | { 59 | XCTAssertTrue(!strcmp(FSPathGetPathString(FSPathCurrent()), "//[MEMORY]/private/tmp/"), @"Correctly picks up current directory"); 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /CommonCTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 - 2016, Stefan Johnson 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list 8 | of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this 10 | list of conditions and the following disclaimer in the documentation and/or other 11 | materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CommonC 2 | ======= 3 | 4 | The CommonC framework contains a collection of utilities for C programs. This is a separation from the [Common](https://github.com/ScrimpyCat/Common) project. 5 | 6 | 7 | The feature set so far includes: 8 | 9 | * Platform and hardware feature detection. 10 | * Common compiler extensions. 11 | * Memory allocator - To conveniently select allocators, reference counted memory, a stack based allocator, and exposes them for use in CoreFoundation (CFAllocatorRef). _Note: this is in need of a rewrite as it's just a very simple interface._ 12 | * Logging - a simple logging interface that supports different system logging mechanisms (such as ASL, OSL), and ability to add custom format specifiers or other filtering behaviours. 13 | * Assertions - convenient assert and log on failure. 14 | * System information - query some basic system/process information. 15 | * File system - a portable file system interface with convenient path manipulation. 16 | * Vector and matrix maths - SIMD optimized when supported. 17 | * Random distributions - multiple implementations, and convenient distribution choices. 18 | * Bit manipulation 19 | * Data - a generic data container. 20 | * Maps - different map implementations such as generic hashmap and dictionary interfaces. 21 | * Collections - different collection implementations such as arrays, linked lists, or generic collection and ordered collection interfaces. 22 | * Strings - optimized immutable strings for UTF-8 and ASCII encodings. Avoids allocations where possible with tagged variants or temporary strings. 23 | * Enumerators - simple enumerating interfaces for maps, collections, and strings. 24 | * Enumerables - a generic enumerating interface. 25 | * Queues - single threaded and lock-free (many producer-consumer) concurrent FIFO queues. 26 | * Garbage Collectors - for safe memory reclamation in lock-free algorithms. 27 | * Unique IDs - for obtaining and managing IDs. 28 | * Big integers - simple operations for handling infinite sized integers. 29 | 30 | 31 | ## Build 32 | 33 | This project is intended to be compiled with clang using C11 with extensions. 34 | 35 | ### Mac/iOS 36 | 37 | Use the xcode project. 38 | 39 | ### Linux 40 | 41 | Use meson to generate the build: 42 | ```bash 43 | mkdir build && CC=clang meson build 44 | ``` 45 | 46 | ## Configuration 47 | 48 | A list of globally defineable options to change the behaviour of the library (requires recompilation). For more details of each see their file reference. 49 | 50 | * `CC_CONSECUTIVE_ID_GENERATOR_STRICT_COMPLIANCE` - ConsecutiveIDGenerator.c (disable some optimisation) 51 | * `CC_CONCURRENT_INDEX_MAP_STRICT_COMPLIANCE` - ConcurrentIndexMap.c (disable some optimisation) 52 | * `CC_STRING_TAGGED_NUL_CHAR_ALWAYS_0` - CCString.c (disable some optimisation) 53 | * `CC_STRING_TAGGED_HASH_CACHE` - CCString.c (disable some optimisation) 54 | * `CC_NO_ASSERT` - Assertion.c (remove all assertions) 55 | * `CC_EXCLUDE_ASL_LOGGER` - Logging.c (exclude system logger) 56 | * `CC_EXCLUDE_OSL_LOGGER` - Logging.c (exclude system logger) 57 | * `CC_EXCLUDE_SYSLOG_LOGGER` - Logging.c (exclude system logger) 58 | * `CC_ALLOCATORS_MAX` - Allocator.c (increase max allocator list size) 59 | -------------------------------------------------------------------------------- /gen_container_types.rb: -------------------------------------------------------------------------------- 1 | if ARGV.count < 1 2 | puts 'Pass in the output/input directory followed by any additional input directories' 3 | puts '[--preset] in/out [in, ...]' 4 | exit 5 | end 6 | 7 | if ARGV[0] == '--preset' and ARGV.count >= 2 8 | preset = true 9 | inputs = ARGV[1..-1].join(',') 10 | output = ARGV[1] 11 | else 12 | preset = false 13 | inputs = ARGV.join(',') 14 | output = ARGV[0] 15 | end 16 | 17 | containers = [] 18 | 19 | Dir["{#{inputs}}/**/*.h"].each { |file| 20 | src = File.read(file) 21 | src.scan(/^\s*?#define\s*?CC_(.*?)\s*?\(.*?\)\s*?CC_CONTAINER\(/).each { |define| 22 | containers << 'CC_' + define[0] 23 | containers << 'CC' + define[0].split('_').map { |s| s.capitalize }.join 24 | } 25 | } 26 | 27 | private_types = {} 28 | 29 | match_line = /^\s*[^#\n].*$/ 30 | match = /(#{containers.join('|')})(\((?>[\w\s,]+|\g<2>)*\))/ 31 | 32 | if containers.count > 0 33 | Dir["#{output}/**/*.{c,m}"].each { |file| 34 | src = File.read(file) 35 | src.scan(match_line).each { |line| 36 | line.scan(match).each { |type| 37 | if type[0].include? '_' 38 | container = type[0].split('_').map { |s| s.capitalize }.join 39 | container = container[0..2].upcase + container[3..-1] 40 | else 41 | container = type[0] 42 | end 43 | elements = type[1][1..-2] 44 | inner_types = elements.split(',').map { |s| (s[/[^\(\)]+$/] || s[/^[^\(\)]*/]).strip } 45 | elements = elements.split(',').map { |s| s.include?('(') ? s.gsub(/(\w+)\(/, 'CC_CONTAINER(\1, ') : s }.join(',') 46 | (private_types[container] = private_types[container] || []) << ["CC_CONTAINER_DECLARE(#{container}, #{elements});", inner_types] 47 | } 48 | } 49 | } 50 | end 51 | 52 | types = {} 53 | 54 | if containers.count > 0 55 | Dir["{#{inputs}}/**/*.h"].each { |file| 56 | src = File.read(file) 57 | src.scan(match_line).each { |line| 58 | line.scan(match).each { |type| 59 | if type[0].include? '_' 60 | container = type[0].split('_').map { |s| s.capitalize }.join 61 | container = container[0..2].upcase + container[3..-1] 62 | else 63 | container = type[0] 64 | end 65 | elements = type[1][1..-2] 66 | elements = elements.split(',').map { |s| s.include?('(') ? s.gsub(/(\w+)\(/, 'CC_CONTAINER(\1, ') : s }.join(',') 67 | (types[container] = types[container] || []) << "CC_CONTAINER_DECLARE(#{container}, #{elements});" 68 | } 69 | } 70 | private_types.each_key { |k| 71 | private_types[k].map { |e| 72 | e[1].select! { |s| !src.match(/(^|\s)#{Regexp.quote(s)}([^\w]|$)/) } 73 | } 74 | } 75 | } 76 | end 77 | 78 | types.merge!(private_types) { |k, a, b| a << b.select { |e| e[1].count == 0 } } 79 | 80 | if preset 81 | containers.each { |type| 82 | if type.include? '_' 83 | container = type.split('_').map { |s| s.capitalize }.join 84 | container = container[0..2].upcase + container[3..-1] 85 | else 86 | container = type 87 | end 88 | 89 | types[container] = types[container] || [] 90 | } 91 | 92 | declarations = types.to_a.map { |e| "#define CC_CONTAINER_DECLARE_PRESET_#{e[0]}()#{e[1].count > 0 ? " \\\n" : ''}" + e[1].flatten.uniq.sort.join(" \\\n") }.sort.join("\n\n") 93 | else 94 | declarations = types.to_a.map { |e| e[1].flatten.uniq.sort.join("\n") }.sort.join("\n") 95 | end 96 | 97 | src = """ 98 | //This file is automatically generated, modifications will be lost! 99 | #{declarations} 100 | """.lstrip 101 | 102 | File.write("#{output}/ContainerTypes.h", src) 103 | -------------------------------------------------------------------------------- /gen_container_types.sh: -------------------------------------------------------------------------------- 1 | ruby gen_container_types.rb --preset CommonC 2 | -------------------------------------------------------------------------------- /generic_n.rb: -------------------------------------------------------------------------------- 1 | param_count = 1 2 | max_imps = 20 3 | max_types = 10 4 | include_header = true 5 | params = [] 6 | 7 | input = nil 8 | ARGV.each { |e| 9 | if input != nil 10 | case input 11 | when :param_count 12 | param_count = e.to_i 13 | when :max_imps 14 | max_imps = e.to_i 15 | when :max_types 16 | max_types = e.to_i 17 | when :param 18 | params << e 19 | end 20 | 21 | input = nil 22 | elsif e.start_with? '-' 23 | case e 24 | when '--param-count' 25 | input = :param_count 26 | when '-pc' 27 | input = :param_count 28 | when '--max-imps' 29 | input = :max_imps 30 | when '-mi' 31 | input = :max_imps 32 | when '--max-types' 33 | input = :max_types 34 | when '-mt' 35 | input = :max_types 36 | when '--include_header' 37 | include_header = true 38 | when '-ih' 39 | include_header = true 40 | when '--exclude_header' 41 | include_header = false 42 | when '-eh' 43 | include_header = false 44 | when '--param' 45 | input = :param 46 | when '-p' 47 | input = :param 48 | end 49 | end 50 | } 51 | 52 | if params.count == 0 53 | if param_count == 1 54 | params = [:T] 55 | else 56 | params = [:Tx, :Ty, :Tz, :Tw] 57 | end 58 | end 59 | 60 | params = params[0, param_count] 61 | 62 | if include_header 63 | puts "#include " 64 | puts "" 65 | end 66 | 67 | params.each { |p| 68 | max_imps.times { |i| 69 | puts "#define CC_TYPE_CC_GENERIC_#{p}#{i}(...) CC_GENERIC_#{p}(#{i})" 70 | } 71 | max_imps.times { |i| 72 | max_types.times { |t| 73 | puts "#define CC_TYPE_#{t}_CC_GENERIC_#{p}#{i} CC_TYPE_CC_GENERIC_#{p}#{i}," 74 | } 75 | } 76 | puts "" 77 | } 78 | 79 | params.each { |p| 80 | max_imps.times { |i| 81 | puts "#define CC_PRESERVE_CC_TYPE_CC_GENERIC_#{p}#{i} CC_TYPE_CC_GENERIC_#{p}#{i}" 82 | } 83 | puts "" 84 | } 85 | 86 | params.each { |p| 87 | max_imps.times { |i| 88 | puts "#define CC_TYPE_DECL_CC_GENERIC_#{p}#{i}(...) CC_GENERIC_#{p}(#{i}), __VA_ARGS__" 89 | } 90 | max_imps.times { |i| 91 | max_types.times { |t| 92 | puts "#define CC_TYPE_DECL_#{t}_CC_GENERIC_#{p}#{i} CC_TYPE_DECL_CC_GENERIC_#{p}#{i}," 93 | } 94 | } 95 | puts "" 96 | } 97 | 98 | params.each { |p| 99 | puts "#define CC_GENERIC_#{p}(n) CC_GENERIC_#{p}_(CC_GENERIC_TYPE, n)" 100 | puts "#define CC_GENERIC_#{p}_(t, n) CC_GENERIC_#{p}__(t, n)" 101 | puts "#define CC_GENERIC_#{p}__(t, n) t##_#{p}##n" 102 | puts "" 103 | } 104 | 105 | max_imps.times { |i| 106 | if i == 0 107 | puts "#if !defined(CC_GENERIC_COUNT) || CC_GENERIC_COUNT == #{i}" 108 | else 109 | puts "#elif CC_GENERIC_COUNT == #{i}" 110 | end 111 | 112 | params.each { |p| 113 | puts "typedef CC_TYPE_DECL(#{p}) CC_GENERIC_#{p}(#{i});" 114 | } 115 | params.each { |p| 116 | puts "#undef #{p}" 117 | } 118 | params.each { |p| 119 | puts "#define #{p} CC_GENERIC_#{p}#{i}" 120 | } 121 | 122 | puts "" 123 | puts "#undef CC_GENERIC_COUNT" 124 | puts "#define CC_GENERIC_COUNT #{i + 1}" 125 | puts "" 126 | } 127 | 128 | puts "#else" 129 | puts "#error Add additional cases" 130 | puts "#endif" 131 | puts "" 132 | puts "#include CC_GENERIC_TEMPLATE" 133 | puts "" 134 | puts "#ifndef CC_GENERIC_PRESERVE_TYPE" 135 | params.each { |p| 136 | puts "#undef #{p}" 137 | } 138 | puts "#endif" 139 | puts "" 140 | puts "#ifndef CC_GENERIC_PRESERVE_HEADER" 141 | puts "#undef CC_GENERIC_TEMPLATE" 142 | puts "#endif" 143 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('CommonC', 'c', 2 | default_options: ['c_std=gnu11'] 3 | ) 4 | 5 | if meson.is_subproject() == false 6 | add_global_arguments([ 7 | '-Wno-logical-not-parentheses', 8 | '-Wno-missing-braces', 9 | '-Wno-multichar', 10 | '-Wno-unknown-pragmas', 11 | ], 12 | language: 'c' 13 | ) 14 | endif 15 | 16 | src = [ 17 | 'CommonC/Allocator.c', 18 | 'CommonC/Array.c', 19 | 'CommonC/BigInt.c', 20 | 'CommonC/CCString.c', 21 | 'CommonC/Collection.c', 22 | 'CommonC/CollectionArray.c', 23 | 'CommonC/CollectionFastArray.c', 24 | 'CommonC/CollectionList.c', 25 | 'CommonC/CommonC.c', 26 | 'CommonC/ConcurrentBuffer.c', 27 | 'CommonC/ConcurrentGarbageCollector.c', 28 | 'CommonC/ConcurrentIDGenerator.c', 29 | 'CommonC/ConcurrentIndexBuffer.c', 30 | 'CommonC/ConcurrentIndexMap.c', 31 | 'CommonC/ConcurrentQueue.c', 32 | 'CommonC/ConsecutiveIDGenerator.c', 33 | 'CommonC/CustomFormatSpecifiers.c', 34 | 'CommonC/CustomInputFilters.c', 35 | 'CommonC/Data.c', 36 | 'CommonC/DataBuffer.c', 37 | 'CommonC/DataContainer.c', 38 | 'CommonC/DebugAllocator.c', 39 | 'CommonC/DebugTypes.c', 40 | 'CommonC/Dictionary.c', 41 | 'CommonC/DictionaryHashMap.c', 42 | 'CommonC/Enumerable.c', 43 | 'CommonC/EpochGarbageCollector.c', 44 | 'CommonC/File.c', 45 | 'CommonC/FileHandle.c', 46 | 'CommonC/FileSystem.c', 47 | 'CommonC/Hash.c', 48 | 'CommonC/HashMap.c', 49 | 'CommonC/HashMapSeparateChainingArray.c', 50 | 'CommonC/HashMapSeparateChainingArrayDataOrientedAll.c', 51 | 'CommonC/HashMapSeparateChainingArrayDataOrientedHash.c', 52 | 'CommonC/LazyGarbageCollector.c', 53 | 'CommonC/LinkedList.c', 54 | 'CommonC/List.c', 55 | 'CommonC/Logging.c', 56 | 'CommonC/MemoryAllocation.c', 57 | 'CommonC/OrderedCollection.c', 58 | 'CommonC/Path.c', 59 | 'CommonC/PathComponent.c', 60 | 'CommonC/ProcessInfo.c', 61 | 'CommonC/Queue.c', 62 | 'CommonC/Random.c', 63 | 'CommonC/SystemInfo.c', 64 | 'CommonC/Task.c', 65 | 'CommonC/TaskQueue.c', 66 | 'CommonC/TypeCallbacks.c', 67 | ] 68 | 69 | deps = [] 70 | 71 | if host_machine.system() == 'darwin' 72 | add_languages('objc') 73 | src += [ 74 | 'CommonC/CFAllocator.c', 75 | 'CommonC/SystemPath.m', 76 | ] 77 | deps += [dependency('Foundation')] 78 | endif 79 | 80 | lib = library('CommonC', src, 81 | include_directories: include_directories('CommonC'), 82 | dependencies: deps 83 | ) 84 | 85 | commonc = declare_dependency( 86 | include_directories: include_directories('CommonC'), 87 | link_with: lib 88 | ) 89 | --------------------------------------------------------------------------------