diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index b590784..b84e54e 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -1,6 +1,3 @@ -# This workflow will build a Swift project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift - name: Swift on: @@ -10,15 +7,53 @@ on: branches: ["main"] jobs: - build: + macos-build: + name: macOS runs-on: macos-26 - + strategy: + matrix: + swift: ["6.2"] steps: + - id: swift-version + run: | + MAJOR=$(echo "${{ matrix.swift }}" | cut -d. -f1) + MINOR=$(echo "${{ matrix.swift }}" | cut -d. -f2) + echo "major=$MAJOR" >> $GITHUB_OUTPUT + echo "minor=$MINOR" >> $GITHUB_OUTPUT - uses: actions/checkout@v4 - uses: ./.github/actions/checkout-swift-headers with: path: Checkouts/swift - swift-version-major: 6 - swift-version-minor: 2 + swift-version-major: ${{ steps.swift-version.outputs.major }} + swift-version-minor: ${{ steps.swift-version.outputs.minor }} - name: Build run: swift build + + linux-build: + name: Linux + runs-on: ubuntu-latest + strategy: + matrix: + swift: ["6.2"] + container: + image: swift:${{ matrix.swift }}-jammy + steps: + - name: Install dependencies + run: | + apt-get update + apt-get install -y libssl-dev + - name: Swift version + id: swift-version + run: | + MAJOR=$(echo "${{ matrix.swift }}" | cut -d. -f1) + MINOR=$(echo "${{ matrix.swift }}" | cut -d. -f2) + echo "major=$MAJOR" >> $GITHUB_OUTPUT + echo "minor=$MINOR" >> $GITHUB_OUTPUT + - uses: actions/checkout@v4 + - uses: ./.github/actions/checkout-swift-headers + with: + path: Checkouts/swift + swift-version-major: ${{ steps.swift-version.outputs.major }} + swift-version-minor: ${{ steps.swift-version.outputs.minor }} + - name: Build + run: swift build -Xcc -Wno-elaborated-enum-base diff --git a/Package.swift b/Package.swift index 848c855..dc7480a 100644 --- a/Package.swift +++ b/Package.swift @@ -22,7 +22,20 @@ let package = Package( dependencies: dependencies, targets: [ .target( - name: "Utilities" + name: "Platform", + cSettings: [ + .define("_GNU_SOURCE", .when(platforms: [.linux])) + ] + ), + .target( + name: "SwiftCorelibsCoreFoundation" + ), + .target( + name: "Utilities", + dependencies: [ + "Platform", + .target(name: "SwiftCorelibsCoreFoundation", condition: .when(platforms: [.linux])), + ] ), .testTarget( name: "UtilitiesTests", @@ -67,9 +80,19 @@ let package = Package( ), .target( name: "ComputeCxx", - dependencies: ["Utilities", "ComputeCxxSwiftSupport"], + dependencies: [ + "Platform", + "Utilities", + "ComputeCxxSwiftSupport", + .target(name: "SwiftCorelibsCoreFoundation", condition: .when(platforms: [.linux])), + ], + cSettings: [ + .unsafeFlags(["-Wno-elaborated-enum-base"]) + ], cxxSettings: [ .headerSearchPath(""), + .headerSearchPath("internalInclude"), + .define("_GNU_SOURCE", .when(platforms: [.linux])), .unsafeFlags([ "-Wno-elaborated-enum-base", "-static", diff --git a/Sources/Compute/Attribute/AnyAttribute.swift b/Sources/Compute/Attribute/AnyAttribute.swift index 1c9e32f..f989ff9 100644 --- a/Sources/Compute/Attribute/AnyAttribute.swift +++ b/Sources/Compute/Attribute/AnyAttribute.swift @@ -103,3 +103,7 @@ extension AnyAttribute: @retroactive CustomStringConvertible { extension AnyAttribute: @retroactive Equatable {} extension AnyAttribute: @retroactive Hashable {} + +extension AnyAttribute { + public typealias _ObjectiveCType = Self.RawValue // Fixes compiler crash +} diff --git a/Sources/Compute/Attribute/AttributeType.swift b/Sources/Compute/Attribute/AttributeType.swift index 45967be..c1ad0ef 100644 --- a/Sources/Compute/Attribute/AttributeType.swift +++ b/Sources/Compute/Attribute/AttributeType.swift @@ -51,6 +51,7 @@ extension _AttributeType { vtable.pointee.self_destroy = { attributeType, body in attributeType.pointee.attributeBody._destroySelf(body) } +#if os(macOS) vtable.pointee.self_description = { attributeType, body in let description: String if let selfType = attributeType.pointee.self_id.type @@ -60,15 +61,31 @@ extension _AttributeType { } else { description = attributeType.pointee.self_id.description } - return Unmanaged.passRetained(description as NSString) - .autorelease() + return Unmanaged.passRetained(description as CFString).autorelease() } vtable.pointee.value_description = { attributeType, value in let valueType = attributeType.pointee.value_id.type let description = String._describing(value, of: valueType) - return Unmanaged.passRetained(description as NSString) - .autorelease() + return Unmanaged.passRetained(description as CFString).autorelease() } +#else + vtable.pointee.copy_self_description = { attributeType, body in + let description: String + if let selfType = attributeType.pointee.self_id.type + as? any CustomStringConvertible.Type + { + description = String._describing(body, of: selfType) + } else { + description = attributeType.pointee.self_id.description + } + return Unmanaged.passRetained(description.cfString) + } + vtable.pointee.copy_value_description = { attributeType, value in + let valueType = attributeType.pointee.value_id.type + let description = String._describing(value, of: valueType) + return Unmanaged.passRetained(description.cfString) + } +#endif vtable.pointee.update_default = { attributeType, body in attributeType.pointee.attributeBody._updateDefault(body) } diff --git a/Sources/Compute/Runtime/Metadata.swift b/Sources/Compute/Runtime/Metadata.swift index bc2fd9c..7d0366a 100644 --- a/Sources/Compute/Runtime/Metadata.swift +++ b/Sources/Compute/Runtime/Metadata.swift @@ -1,5 +1,4 @@ import ComputeCxx -import Foundation extension Metadata { @@ -45,7 +44,11 @@ extension Metadata { extension Metadata: @retroactive CustomStringConvertible { public var description: String { - return __AGTypeDescription(self) as String + #if os(macOS) + return __AGTypeDescription(self) as String + #else + return String(__AGTypeCopyDescription(self)) + #endif } } diff --git a/Sources/Compute/Utility/FoundationExtensions/String+CFString.swift b/Sources/Compute/Utility/FoundationExtensions/String+CFString.swift new file mode 100644 index 0000000..a7efc33 --- /dev/null +++ b/Sources/Compute/Utility/FoundationExtensions/String+CFString.swift @@ -0,0 +1,33 @@ +import Foundation + +extension String { + init(_ cfString: CFString) { + if let ptr = CFStringGetCStringPtr(cfString, CFStringBuiltInEncodings.UTF8.rawValue) { + self.init(cString: ptr) + return + } + + let length = CFStringGetLength(cfString) + let maxSize = CFStringGetMaximumSizeForEncoding(length, CFStringBuiltInEncodings.UTF8.rawValue) + 1 + + let buffer = UnsafeMutablePointer.allocate(capacity: maxSize) + defer { buffer.deallocate() } + + guard CFStringGetCString(cfString, buffer, maxSize, CFStringBuiltInEncodings.UTF8.rawValue) else { + self = "" + return + } + self.init(cString: buffer) + } + + var cfString: CFString { + guard let cString = self.cString(using: .utf8), + let cfString = CFStringCreateWithCString(nil, cString, CFStringBuiltInEncodings.UTF8.rawValue) + else { + let utf8 = Array(self.utf8) + return CFStringCreateWithBytes(nil, utf8, utf8.count, CFStringBuiltInEncodings.UTF8.rawValue, false) + } + return cfString + } + +} diff --git a/Sources/ComputeCxx/Array/ArrayRef.h b/Sources/ComputeCxx/Array/ArrayRef.h index d0b34c0..ecf1b35 100644 --- a/Sources/ComputeCxx/Array/ArrayRef.h +++ b/Sources/ComputeCxx/Array/ArrayRef.h @@ -1,9 +1,10 @@ #pragma once -#include #include -CF_ASSUME_NONNULL_BEGIN +#include + +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -62,4 +63,4 @@ template class ArrayRef { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeData/Node/IndirectNode.h b/Sources/ComputeCxx/Attribute/AttributeData/Node/IndirectNode.h index 22d98bb..bde7adc 100644 --- a/Sources/ComputeCxx/Attribute/AttributeData/Node/IndirectNode.h +++ b/Sources/ComputeCxx/Attribute/AttributeData/Node/IndirectNode.h @@ -1,14 +1,13 @@ #pragma once -#include - #include "Attribute/AttributeData/Edge/OutputEdge.h" #include "Attribute/AttributeID/AttributeID.h" #include "Attribute/AttributeID/RelativeAttributeID.h" #include "Attribute/AttributeID/WeakAttributeID.h" +#include "ComputeCxx/AGBase.h" #include "Data/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -92,4 +91,4 @@ class MutableIndirectNode : public IndirectNode { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeData/Node/Node.h b/Sources/ComputeCxx/Attribute/AttributeData/Node/Node.h index 2a70b69..7ae0bd7 100644 --- a/Sources/ComputeCxx/Attribute/AttributeData/Node/Node.h +++ b/Sources/ComputeCxx/Attribute/AttributeData/Node/Node.h @@ -1,16 +1,15 @@ #pragma once -#include - #include "Attribute/AttributeData/Edge/InputEdge.h" #include "Attribute/AttributeData/Edge/OutputEdge.h" #include "Attribute/AttributeID/RelativeAttributeID.h" #include "ComputeCxx/AGAttribute.h" +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGGraph.h" #include "Data/Pointer.h" #include "Data/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -179,4 +178,4 @@ class Node { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeID/AttributeID.h b/Sources/ComputeCxx/Attribute/AttributeID/AttributeID.h index 39b6cce..1d9d713 100644 --- a/Sources/ComputeCxx/Attribute/AttributeID/AttributeID.h +++ b/Sources/ComputeCxx/Attribute/AttributeID/AttributeID.h @@ -1,16 +1,15 @@ #pragma once -#include #include #include -#include #include "ComputeCxx/AGAttribute.h" +#include "ComputeCxx/AGBase.h" #include "Data/Page.h" #include "Data/Pointer.h" #include "Data/Zone.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -69,7 +68,7 @@ class AttributeID { public: static constexpr uint32_t KindMask = 0x3; - explicit constexpr AttributeID(nullptr_t = nullptr) : _value(0) {}; + explicit constexpr AttributeID(std::nullptr_t = nullptr) : _value(0) {}; explicit AttributeID(data::ptr node) : _value(node.offset() | Kind::Node) {}; explicit AttributeID(data::ptr indirect_node) : _value(indirect_node.offset() | Kind::IndirectNode) {}; @@ -132,4 +131,4 @@ class AttributeID { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeID/OffsetAttributeID.h b/Sources/ComputeCxx/Attribute/AttributeID/OffsetAttributeID.h index 3ae86f9..cc34624 100644 --- a/Sources/ComputeCxx/Attribute/AttributeID/OffsetAttributeID.h +++ b/Sources/ComputeCxx/Attribute/AttributeID/OffsetAttributeID.h @@ -1,11 +1,10 @@ #pragma once -#include -#include +#include "ComputeCxx/AGBase.h" #include "AttributeID.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -25,4 +24,4 @@ class OffsetAttributeID { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeID/RelativeAttributeID.h b/Sources/ComputeCxx/Attribute/AttributeID/RelativeAttributeID.h index 640f035..78a1aec 100644 --- a/Sources/ComputeCxx/Attribute/AttributeID/RelativeAttributeID.h +++ b/Sources/ComputeCxx/Attribute/AttributeID/RelativeAttributeID.h @@ -10,7 +10,7 @@ class RelativeAttributeID { uint16_t _value; public: - explicit constexpr RelativeAttributeID(nullptr_t = nullptr) : _value(0) {}; + explicit constexpr RelativeAttributeID(std::nullptr_t = nullptr) : _value(0) {}; explicit constexpr RelativeAttributeID(uint16_t value) : _value(value) {}; constexpr RelativeAttributeID(AttributeID attribute) : _value(((attribute & ~AttributeID::KindMask) - attribute.page_ptr().offset()) | attribute.kind()) {}; diff --git a/Sources/ComputeCxx/Attribute/AttributeID/WeakAttributeID.h b/Sources/ComputeCxx/Attribute/AttributeID/WeakAttributeID.h index c814043..5d46f59 100644 --- a/Sources/ComputeCxx/Attribute/AttributeID/WeakAttributeID.h +++ b/Sources/ComputeCxx/Attribute/AttributeID/WeakAttributeID.h @@ -1,12 +1,10 @@ #pragma once -#include -#include - #include "AttributeID.h" +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGWeakAttribute.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -35,4 +33,4 @@ class WeakAttributeID { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Attribute/AttributeType/AttributeType.h b/Sources/ComputeCxx/Attribute/AttributeType/AttributeType.h index 8d4093b..2118955 100644 --- a/Sources/ComputeCxx/Attribute/AttributeType/AttributeType.h +++ b/Sources/ComputeCxx/Attribute/AttributeType/AttributeType.h @@ -1,15 +1,14 @@ #pragma once -#include - #include "Attribute/AttributeData/Node/Node.h" #include "Comparison/LayoutDescriptor.h" +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGAttribute.h" #include "ComputeCxx/AGAttributeType.h" #include "ComputeCxx/AGComparison.h" #include "Swift/Metadata.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -96,6 +95,7 @@ class AttributeType { body_metadata().vw_destroy(static_cast(body)); } +#if TARGET_OS_MAC CFStringRef _Nullable self_description(void *body) const { if (auto self_description = vtable().self_description) { return self_description(reinterpret_cast(this), body); @@ -109,8 +109,23 @@ class AttributeType { } return nullptr; } +#else + CFStringRef _Nullable copy_self_description(void *body) const { + if (auto copy_self_description = vtable().copy_self_description) { + return copy_self_description(reinterpret_cast(this), body); + } + return nullptr; + } + + CFStringRef _Nullable copy_value_description(void *value) const { + if (auto copy_value_description = vtable().copy_value_description) { + return copy_value_description(reinterpret_cast(this), value); + } + return nullptr; + } +#endif }; } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Closure/ClosureFunction.h b/Sources/ComputeCxx/Closure/ClosureFunction.h index 1138573..5586555 100644 --- a/Sources/ComputeCxx/Closure/ClosureFunction.h +++ b/Sources/ComputeCxx/Closure/ClosureFunction.h @@ -1,9 +1,8 @@ #pragma once -#include #include -#include "ComputeCxx/AGSwiftSupport.h" +#include "ComputeCxx/AGBase.h" namespace AG { diff --git a/Sources/ComputeCxx/Comparison/AGComparison-Private.h b/Sources/ComputeCxx/Comparison/AGComparison-Private.h index bf90a98..2a9050a 100644 --- a/Sources/ComputeCxx/Comparison/AGComparison-Private.h +++ b/Sources/ComputeCxx/Comparison/AGComparison-Private.h @@ -1,10 +1,9 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGComparison.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN typedef struct AGComparisonStateStorage { const void *destination; @@ -13,4 +12,4 @@ typedef struct AGComparisonStateStorage { AGTypeID field_type; } AGComparisonStateStorage; -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Comparison/Builder.h b/Sources/ComputeCxx/Comparison/Builder.h index 418cdf9..7455dac 100644 --- a/Sources/ComputeCxx/Comparison/Builder.h +++ b/Sources/ComputeCxx/Comparison/Builder.h @@ -1,13 +1,14 @@ #pragma once -#include +#include +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGComparison.h" #include "LayoutDescriptor.h" #include "Swift/MetadataVisitor.h" #include "Vector/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace LayoutDescriptor { @@ -110,11 +111,11 @@ class Builder : public swift::metadata_visitor { }; private: - static os_unfair_lock _lock; + static platform_lock _lock; static size_t _avail; static unsigned char *_buffer; - static void lock() { os_unfair_lock_lock(&_lock); }; - static void unlock() { os_unfair_lock_unlock(&_lock); }; + static void lock() { platform_lock_lock(&_lock); }; + static void unlock() { platform_lock_unlock(&_lock); }; AGComparisonMode _current_comparison_mode; HeapMode _heap_mode; @@ -157,4 +158,4 @@ class Builder : public swift::metadata_visitor { } // namespace LayoutDescriptor } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Comparison/Compare.h b/Sources/ComputeCxx/Comparison/Compare.h index f01d448..1c71a47 100644 --- a/Sources/ComputeCxx/Comparison/Compare.h +++ b/Sources/ComputeCxx/Comparison/Compare.h @@ -2,10 +2,11 @@ #include "LayoutDescriptor.h" +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGComparison.h" #include "Vector/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace LayoutDescriptor { @@ -67,4 +68,4 @@ class Compare { } // namespace LayoutDescriptor } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp b/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp index ae98802..faa2259 100644 --- a/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp +++ b/Sources/ComputeCxx/Comparison/LayoutDescriptor.cpp @@ -1,8 +1,11 @@ #include "LayoutDescriptor.h" -#include +#include #include +#include +#include +#include #include #include "Builder.h" @@ -46,7 +49,7 @@ class TypeDescriptorCache { }; private: - os_unfair_lock _lock; + platform_lock _lock; util::UntypedTable _table; vector _async_queue; void *_field_0xf0; @@ -59,20 +62,20 @@ class TypeDescriptorCache { double _sync_total_seconds; static TypeDescriptorCache *_shared_cache; - static dispatch_once_t _shared_once; + static platform_once_t _shared_once; public: - static void init_shared_cache(void *_Nullable context) { + static void init_shared_cache() { _shared_cache = new TypeDescriptorCache(); LayoutDescriptor::base_address += 1; }; static TypeDescriptorCache &shared_cache() { - dispatch_once_f(&_shared_once, nullptr, init_shared_cache); + platform_once(&_shared_once, init_shared_cache); return *_shared_cache; }; - void lock() { os_unfair_lock_lock(&_lock); }; - void unlock() { os_unfair_lock_unlock(&_lock); }; + void lock() { platform_lock_lock(&_lock); }; + void unlock() { platform_lock_unlock(&_lock); }; vector> &modes() { return _modes; }; @@ -81,11 +84,20 @@ class TypeDescriptorCache { ValueLayout fetch(const swift::metadata &type, AGComparisonOptions options, LayoutDescriptor::HeapMode heap_mode, uint32_t priority); + + ValueLayout insert_sync(void *key, const swift::metadata &type, AGComparisonMode comparison_mode, + LayoutDescriptor::HeapMode heap_mode); + +#if TARGET_OS_MAC + void insert_async(void *key, const swift::metadata &type, AGComparisonMode comparison_mode, + LayoutDescriptor::HeapMode heap_mode, uint32_t priority); + static void drain_queue(void *cache); +#endif }; TypeDescriptorCache *TypeDescriptorCache::_shared_cache = nullptr; -dispatch_once_t TypeDescriptorCache::_shared_once = 0; +platform_once_t TypeDescriptorCache::_shared_once = 0; void *TypeDescriptorCache::make_key(const swift::metadata *type, AGComparisonMode comparison_mode, LayoutDescriptor::HeapMode heap_mode) { @@ -115,6 +127,7 @@ ValueLayout TypeDescriptorCache::fetch(const swift::metadata &type, AGComparison _cache_miss_count += 1; unlock(); +#if TARGET_OS_MAC static bool async_layouts = []() { char *result = getenv("AG_ASYNC_LAYOUTS"); if (result) { @@ -124,29 +137,43 @@ ValueLayout TypeDescriptorCache::fetch(const swift::metadata &type, AGComparison }(); if ((options & AGComparisonOptionsFetchLayoutsSynchronously) || !async_layouts) { - // insert layout synchronously - double start_time = current_time(); - layout = LayoutDescriptor::make_layout(type, comparison_mode, heap_mode); - double end_time = current_time(); + return insert_sync(key, type, comparison_mode, heap_mode); + } - if (comparison_mode < 0) { - lock(); - } else { - double time = end_time - start_time; - if ((print_layouts() & 4) != 0) { - const char *name = type.name(false); - std::fprintf(stdout, "!! synchronous layout creation for %s: %g ms\n", name, time * 1000.0); - } - lock(); - _sync_total_seconds += time; - } + insert_async(key, type, comparison_mode, heap_mode, priority); + return nullptr; +#else + return insert_sync(key, type, comparison_mode, heap_mode); +#endif +} - _table.insert((void *)key, layout); - unlock(); - return layout; +ValueLayout TypeDescriptorCache::insert_sync(void *key, const swift::metadata &type, AGComparisonMode comparison_mode, + LayoutDescriptor::HeapMode heap_mode) { + double start_time = current_time(); + ValueLayout layout = LayoutDescriptor::make_layout(type, comparison_mode, heap_mode); + double end_time = current_time(); + + if (comparison_mode < 0) { + lock(); + } else { + double time = end_time - start_time; + if ((print_layouts() & 4) != 0) { + const char *name = type.name(false); + std::fprintf(stdout, "!! synchronous layout creation for %s: %g ms\n", name, time * 1000.0); + } + lock(); + _sync_total_seconds += time; } - // insert layout asynchronously + _table.insert((void *)key, layout); + unlock(); + return layout; +} + +#if TARGET_OS_MAC + +void TypeDescriptorCache::insert_async(void *key, const swift::metadata &type, AGComparisonMode comparison_mode, + LayoutDescriptor::HeapMode heap_mode, uint32_t priority) { lock(); _table.insert((void *)key, nullptr); @@ -165,7 +192,6 @@ ValueLayout TypeDescriptorCache::fetch(const swift::metadata &type, AGComparison } unlock(); - return nullptr; } void TypeDescriptorCache::drain_queue(void *context) { @@ -211,6 +237,8 @@ void TypeDescriptorCache::drain_queue(void *context) { cache->unlock(); } +#endif + } // namespace #pragma mark - LayoutDescriptor @@ -901,7 +929,7 @@ void print(std::string &output, ValueLayout layout) { #pragma mark - Builder -os_unfair_lock Builder::_lock = OS_UNFAIR_LOCK_INIT; +platform_lock Builder::_lock = PLATFORM_LOCK_INIT; size_t Builder::_avail = 0; unsigned char *Builder::_buffer = nullptr; diff --git a/Sources/ComputeCxx/Comparison/LayoutDescriptor.h b/Sources/ComputeCxx/Comparison/LayoutDescriptor.h index 085da42..c84ffe6 100644 --- a/Sources/ComputeCxx/Comparison/LayoutDescriptor.h +++ b/Sources/ComputeCxx/Comparison/LayoutDescriptor.h @@ -1,11 +1,11 @@ #pragma once -#include #include +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGComparison.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -82,4 +82,4 @@ void print(std::string &output, ValueLayout layout); } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Comparison/ValueLayout.h b/Sources/ComputeCxx/Comparison/ValueLayout.h index 0863370..dfb2eb9 100644 --- a/Sources/ComputeCxx/Comparison/ValueLayout.h +++ b/Sources/ComputeCxx/Comparison/ValueLayout.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace AG { namespace LayoutDescriptor { diff --git a/Sources/ComputeCxx/Data/Constants.h b/Sources/ComputeCxx/Data/Constants.h index 564374a..bf82ed9 100644 --- a/Sources/ComputeCxx/Data/Constants.h +++ b/Sources/ComputeCxx/Data/Constants.h @@ -1,9 +1,8 @@ #pragma once -#include -#include +#include "ComputeCxx/AGBase.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -14,4 +13,4 @@ constexpr uint32_t page_alignment_mask = page_size - 1; } // namespace data } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Data/Page.h b/Sources/ComputeCxx/Data/Page.h index e81e575..84d1ef3 100644 --- a/Sources/ComputeCxx/Data/Page.h +++ b/Sources/ComputeCxx/Data/Page.h @@ -1,11 +1,10 @@ #pragma once -#include -#include +#include "ComputeCxx/AGBase.h" #include "Pointer.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -57,4 +56,4 @@ class page_ptr_list { } // namespace data } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Data/Pointer.h b/Sources/ComputeCxx/Data/Pointer.h index 783a701..9809761 100644 --- a/Sources/ComputeCxx/Data/Pointer.h +++ b/Sources/ComputeCxx/Data/Pointer.h @@ -1,14 +1,14 @@ #pragma once -#include #include -#include #include +#include "ComputeCxx/AGBase.h" + #include "Constants.h" #include "Table.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -28,7 +28,7 @@ template class ptr { public: constexpr ptr(offset_type offset = 0) : _offset(offset) {}; - constexpr ptr(nullptr_t): _offset(0) {}; + constexpr ptr(std::nullptr_t): _offset(0) {}; void assert_valid() const { if (_offset >= table::shared().ptr_max_offset()) { @@ -62,8 +62,8 @@ template class ptr { bool operator==(const ptr &other) const noexcept { return _offset == other._offset; }; bool operator!=(const ptr &other) const noexcept { return _offset != other._offset; }; - bool operator==(nullptr_t) const noexcept { return _offset == 0; }; - bool operator!=(nullptr_t) const noexcept { return _offset != 0; }; + bool operator==(std::nullptr_t) const noexcept { return _offset == 0; }; + bool operator!=(std::nullptr_t) const noexcept { return _offset != 0; }; bool operator<(offset_type offset) const noexcept { return _offset < offset; }; bool operator<=(offset_type offset) const noexcept { return _offset <= offset; }; @@ -94,4 +94,4 @@ template class hash> { } // namespace std -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Data/Table.cpp b/Sources/ComputeCxx/Data/Table.cpp index 1f94423..063f9a5 100644 --- a/Sources/ComputeCxx/Data/Table.cpp +++ b/Sources/ComputeCxx/Data/Table.cpp @@ -2,11 +2,17 @@ #include #include -#include +#include +#if TARGET_OS_MAC #include -#include -#include +#else +#include #include +#endif + +#include +#include +#include #include "Errors/Errors.h" #include "Page.h" @@ -20,8 +26,8 @@ namespace data { table _shared_table_bytes; table &table::ensure_shared() { - static dispatch_once_t onceToken; - dispatch_once_f(&onceToken, nullptr, [](void *_Nullable context) { new (&_shared_table_bytes) table(); }); + static platform_once_t onceToken; + platform_once(&onceToken, []() { new (&_shared_table_bytes) table(); }); return _shared_table_bytes; } @@ -40,10 +46,26 @@ std::unique_ptr table::alloc_persistent(size_t table::table() { constexpr vm_size_t initial_size = 32 * pages_per_map * page_size; +#if TARGET_OS_MAC void *region = mmap(nullptr, initial_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (region == MAP_FAILED) { precondition_failure("memory allocation failure (%u bytes, %u)", initial_size, errno); } +#else + _vm_region_fd = memfd_create("AGGraphVMRegion", MFD_CLOEXEC); + if (_vm_region_fd < 0) { + precondition_failure("memfd_create failure (%u)", errno); + } + + if (ftruncate(_vm_region_fd, initial_size) != 0) { + precondition_failure("ftruncate failure (%u bytes, %u)", initial_size, errno); + } + + void *region = mmap(nullptr, initial_size, PROT_READ | PROT_WRITE, MAP_SHARED, _vm_region_fd, 0); + if (region == MAP_FAILED) { + precondition_failure("memory allocation failure (%u bytes, %u)", initial_size, errno); + } +#endif _vm_region_base_address = reinterpret_cast(region); _vm_region_size = initial_size; @@ -60,14 +82,17 @@ table::table() { } table::~table() { +#if !TARGET_OS_MAC + close(_vm_region_fd); +#endif if (_malloc_zone) { malloc_destroy_zone(_malloc_zone); } } -void table::lock() { os_unfair_lock_lock(&_lock); } +void table::lock() { platform_lock_lock(&_lock); } -void table::unlock() { os_unfair_lock_unlock(&_lock); } +void table::unlock() { platform_lock_unlock(&_lock); } #pragma mark - Region @@ -79,6 +104,7 @@ void table::grow_region() { precondition_failure("exhausted data space"); } +#if TARGET_OS_MAC void *new_region = mmap(nullptr, new_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (new_region == MAP_FAILED) { precondition_failure("memory allocation failure (%u bytes, %u)", new_size, errno); @@ -86,13 +112,22 @@ void table::grow_region() { vm_prot_t cur_protection = VM_PROT_NONE; vm_prot_t max_protection = VM_PROT_NONE; - kern_return_t error = - vm_remap(mach_task_self(), reinterpret_cast(&new_region), _vm_region_size, 0, - VM_FLAGS_OVERWRITE, mach_task_self(), reinterpret_cast(_vm_region_base_address), false, - &cur_protection, &max_protection, VM_INHERIT_NONE); - if (error) { - precondition_failure("vm_remap failure: 0x%x", error); + kern_return_t kr = vm_remap(mach_task_self(), reinterpret_cast(&new_region), _vm_region_size, 0, + VM_FLAGS_OVERWRITE, mach_task_self(), _vm_region_base_address, false, &cur_protection, + &max_protection, VM_INHERIT_NONE); + if (kr != KERN_SUCCESS) { + precondition_failure("vm_remap failure: 0x%x", kr); + } +#else + if (ftruncate(_vm_region_fd, new_size) != 0) { + precondition_failure("ftruncate failure (%u bytes, %u)", new_size, errno); + } + + void *new_region = mmap(nullptr, new_size, PROT_READ | PROT_WRITE, MAP_SHARED, _vm_region_fd, 0); + if (new_region == MAP_FAILED) { + precondition_failure("memory allocation failure (%u bytes, %u)", new_size, errno); } +#endif _remapped_regions.push_back({this->_vm_region_base_address, this->_vm_region_size}); @@ -240,7 +275,11 @@ void table::make_pages_reusable(uint32_t page_index, bool reusable) { void *mapped_pages_address = reinterpret_cast(_vm_region_base_address + ((page_index * page_size) & ~(mapped_pages_size - 1))); +#if TARGET_OS_MAC int advice = reusable ? MADV_FREE_REUSABLE : MADV_FREE_REUSE; +#else + int advice = reusable ? MADV_FREE : MADV_NORMAL; +#endif madvise(mapped_pages_address, mapped_pages_size, advice); static bool unmap_reusable = []() -> bool { diff --git a/Sources/ComputeCxx/Data/Table.h b/Sources/ComputeCxx/Data/Table.h index a9888e3..185980d 100644 --- a/Sources/ComputeCxx/Data/Table.h +++ b/Sources/ComputeCxx/Data/Table.h @@ -1,16 +1,16 @@ #pragma once -#include #include -#include -#include -#include -#include #include +#include +#include +#include + +#include "ComputeCxx/AGBase.h" #include "Vector/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -30,9 +30,12 @@ class table { static std::unique_ptr alloc_persistent(size_t size); private: +#if !TARGET_OS_MAC + int _vm_region_fd; +#endif vm_address_t _ptr_base; vm_address_t _vm_region_base_address; - os_unfair_lock _lock = OS_UNFAIR_LOCK_INIT; + platform_lock _lock = PLATFORM_LOCK_INIT; uint32_t _vm_region_size; uint32_t _ptr_max_offset; @@ -87,4 +90,4 @@ class table { } // namespace data } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Data/Vector.h b/Sources/ComputeCxx/Data/Vector.h index 5132cb3..d5ad375 100644 --- a/Sources/ComputeCxx/Data/Vector.h +++ b/Sources/ComputeCxx/Data/Vector.h @@ -1,11 +1,10 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "Pointer.h" #include "Zone.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -205,4 +204,4 @@ template void vector::push_back(zone *zone, T &&value) { } // namespace data } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Data/Zone.cpp b/Sources/ComputeCxx/Data/Zone.cpp index b08d0b1..4578465 100644 --- a/Sources/ComputeCxx/Data/Zone.cpp +++ b/Sources/ComputeCxx/Data/Zone.cpp @@ -1,11 +1,13 @@ #include "Zone.h" -#include +#include +#include + +#include #include "Errors/Errors.h" #include "Page.h" #include "Table.h" -#include namespace AG { namespace data { diff --git a/Sources/ComputeCxx/Data/Zone.h b/Sources/ComputeCxx/Data/Zone.h index 9686924..d09bedd 100644 --- a/Sources/ComputeCxx/Data/Zone.h +++ b/Sources/ComputeCxx/Data/Zone.h @@ -1,13 +1,12 @@ #pragma once -#include -#include +#include "ComputeCxx/AGBase.h" #include "Page.h" #include "Pointer.h" #include "Table.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace data { @@ -73,4 +72,4 @@ class zone { } // namespace data } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Errors/Errors.cpp b/Sources/ComputeCxx/Errors/Errors.cpp index 64a1066..557ad14 100644 --- a/Sources/ComputeCxx/Errors/Errors.cpp +++ b/Sources/ComputeCxx/Errors/Errors.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include "Graph/Graph.h" @@ -6,8 +7,8 @@ char *error_message = nullptr; namespace AG { -os_log_t error_log() { - static os_log_t log = os_log_create("dev.incrematic.compute", "error"); +platform_log_t error_log() { + static platform_log_t log = platform_log_create("dev.incrematic.compute", "error"); return log; } @@ -20,7 +21,7 @@ os_log_t error_log() { va_end(args); if (message != nullptr) { - os_log_error(error_log(), "precondition failure: %s", message); + platform_log_error(error_log(), "precondition failure: %s", message); Graph::trace_assertion_failure(true, "precondition failure: %s", message); if (error_message == nullptr) { asprintf(&error_message, "Compute precondition failure: %s.\n", message); @@ -40,7 +41,7 @@ void non_fatal_precondition_failure(const char *format, ...) { va_end(args); if (message != nullptr) { - os_log_fault(error_log(), "precondition failure: %s", message); + platform_log_fault(error_log(), "precondition failure: %s", message); free(message); } } diff --git a/Sources/ComputeCxx/Errors/Errors.h b/Sources/ComputeCxx/Errors/Errors.h index 8292e61..3e3b04a 100644 --- a/Sources/ComputeCxx/Errors/Errors.h +++ b/Sources/ComputeCxx/Errors/Errors.h @@ -1,8 +1,8 @@ #pragma once -#include +#include "ComputeCxx/AGBase.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -11,4 +11,4 @@ void non_fatal_precondition_failure(const char *format, ...); } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/AGDescription.mm b/Sources/ComputeCxx/Graph/AGDescription.mm index 4a04f24..e00dde7 100644 --- a/Sources/ComputeCxx/Graph/AGDescription.mm +++ b/Sources/ComputeCxx/Graph/AGDescription.mm @@ -1,6 +1,8 @@ #include "ComputeCxx/AGDescription.h" -const CFStringRef AGDescriptionFormat = CFSTR("format"); -const CFStringRef AGDescriptionMaxFrames = CFSTR("max-frames"); -const CFStringRef AGDescriptionIncludeValues = CFSTR("include-values"); -const CFStringRef AGDescriptionTruncationLimit = CFSTR("truncation-limit"); +#if TARGET_OS_MAC +const AGDescriptionOption AGDescriptionFormat = CFSTR("format"); +const AGDescriptionOption AGDescriptionMaxFrames = CFSTR("max-frames"); +const AGDescriptionOption AGDescriptionIncludeValues = CFSTR("include-values"); +const AGDescriptionOption AGDescriptionTruncationLimit = CFSTR("truncation-limit"); +#endif diff --git a/Sources/ComputeCxx/Graph/AGGraph-Private.h b/Sources/ComputeCxx/Graph/AGGraph-Private.h index 7b8e07f..9cebffc 100644 --- a/Sources/ComputeCxx/Graph/AGGraph-Private.h +++ b/Sources/ComputeCxx/Graph/AGGraph-Private.h @@ -1,16 +1,21 @@ #pragma once -#include +#include "ComputeCxx/AGBase.h" + +#if TARGET_OS_MAC +#include "CoreFoundationPrivate/CFRuntime.h" +#else +#include +#endif #include "ComputeCxx/AGGraph.h" #include "Graph/Context.h" -#include "Private/CFRuntime.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN struct AGGraphStorage { CFRuntimeBase base; AG::Graph::Context context; }; -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/AGGraph.cpp b/Sources/ComputeCxx/Graph/AGGraph.cpp index 19d85a2..8a39725 100644 --- a/Sources/ComputeCxx/Graph/AGGraph.cpp +++ b/Sources/ComputeCxx/Graph/AGGraph.cpp @@ -1,15 +1,20 @@ #include "AGGraph-Private.h" +#if TARGET_OS_MAC +#include "CoreFoundationPrivate/CFRuntime.h" #include -#include +#else +#include +#include +#endif #include +#include #include "Attribute/AttributeData/Node/IndirectNode.h" #include "Attribute/AttributeID/OffsetAttributeID.h" #include "Context.h" #include "Graph.h" -#include "Private/CFRuntime.h" #include "Trace/ExternalTrace.h" #include "UpdateStack.h" @@ -830,10 +835,13 @@ void AGGraphStartTracing2(AGGraphRef graph, AGTraceFlags trace_flags, CFArrayRef continue; } - char *subsystem; - if (CFStringGetCString((CFStringRef)value, subsystem, CFStringGetLength((CFStringRef)value), - kCFStringEncodingUTF8)) { + CFIndex length = CFStringGetLength((CFStringRef)value); + CFIndex bufferSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; + char *subsystem = (char *)malloc(bufferSize); + if (CFStringGetCString((CFStringRef)value, subsystem, bufferSize, kCFStringEncodingUTF8)) { subsystems_vector.push_back(std::unique_ptr(subsystem)); + } else { + free(subsystem); } } } @@ -943,7 +951,7 @@ void AGGraphAddNamedTraceEvent(AGGraphRef graph, uint32_t event_id, uint32_t eve namespace NamedEvents { -static os_unfair_lock lock = OS_UNFAIR_LOCK_INIT; +static platform_lock lock = PLATFORM_LOCK_INIT; static AG::vector, 0, uint32_t> *names; } // namespace NamedEvents @@ -951,11 +959,11 @@ static AG::vector, 0, uint32_t> *names; const char *AGGraphGetTraceEventName(uint32_t event_id) { const char *event_name = nullptr; - os_unfair_lock_lock(&NamedEvents::lock); + platform_lock_lock(&NamedEvents::lock); if (NamedEvents::names != nullptr && event_id < NamedEvents::names->size()) { event_name = (*NamedEvents::names)[event_id].second; } - os_unfair_lock_unlock(&NamedEvents::lock); + platform_lock_unlock(&NamedEvents::lock); return event_name; } @@ -963,17 +971,17 @@ const char *AGGraphGetTraceEventName(uint32_t event_id) { const char *AGGraphGetTraceEventSubsystem(uint32_t event_id) { const char *event_subsystem = nullptr; - os_unfair_lock_lock(&NamedEvents::lock); + platform_lock_lock(&NamedEvents::lock); if (NamedEvents::names != nullptr && event_id < NamedEvents::names->size()) { event_subsystem = (*NamedEvents::names)[event_id].first; } - os_unfair_lock_unlock(&NamedEvents::lock); + platform_lock_unlock(&NamedEvents::lock); return event_subsystem; } uint32_t AGGraphRegisterNamedTraceEvent(const char *event_name, const char *event_subsystem) { - os_unfair_lock_lock(&NamedEvents::lock); + platform_lock_lock(&NamedEvents::lock); if (!NamedEvents::names) { NamedEvents::names = new AG::vector, 0, uint32_t>(); @@ -987,15 +995,17 @@ uint32_t AGGraphRegisterNamedTraceEvent(const char *event_name, const char *even event_name = strdup(event_name); NamedEvents::names->push_back({event_subsystem, event_name}); - os_unfair_lock_unlock(&NamedEvents::lock); + platform_lock_unlock(&NamedEvents::lock); return event_id; } // MARK: Description +#if TARGET_OS_MAC void AGGraphArchiveJSON(const char *filename) { AG::Graph::write_to_file(nullptr, filename, false); } void AGGraphArchiveJSON2(const char *filename, bool exclude_values) { AG::Graph::write_to_file(nullptr, filename, exclude_values); } +#endif diff --git a/Sources/ComputeCxx/Graph/AGGraph.mm b/Sources/ComputeCxx/Graph/AGGraph.mm index 5afe0d0..3d55c80 100644 --- a/Sources/ComputeCxx/Graph/AGGraph.mm +++ b/Sources/ComputeCxx/Graph/AGGraph.mm @@ -1,5 +1,7 @@ #include "AGGraph-Private.h" +#if TARGET_OS_MAC + #import #include "Context.h" @@ -18,3 +20,5 @@ CFTypeRef AGGraphDescription(AGGraphRef graph, CFDictionaryRef options) { } return (__bridge CFTypeRef)AG::Graph::description(&graph_context->graph(), (__bridge NSDictionary *)options); } + +#endif diff --git a/Sources/ComputeCxx/Graph/Context.h b/Sources/ComputeCxx/Graph/Context.h index dbc099e..e3fbbfa 100644 --- a/Sources/ComputeCxx/Graph/Context.h +++ b/Sources/ComputeCxx/Graph/Context.h @@ -1,11 +1,16 @@ #pragma once -#include +#include "ComputeCxx/AGBase.h" + +#if TARGET_OS_MAC +#include "CoreFoundationPrivate/CFRuntime.h" +#else +#include +#endif #include "Graph.h" -#include "Private/CFRuntime.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN struct AGGraphStorage; @@ -70,4 +75,4 @@ class Graph::Context { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/Graph.cpp b/Sources/ComputeCxx/Graph/Graph.cpp index a562962..38174b6 100644 --- a/Sources/ComputeCxx/Graph/Graph.cpp +++ b/Sources/ComputeCxx/Graph/Graph.cpp @@ -1,11 +1,18 @@ #include "Graph.h" +#if TARGET_OS_MAC #include -#include +#else +#include +#endif +#include #include #include #include +#include +#include +#include #include "Attribute/AttributeData/Node/IndirectNode.h" #include "Attribute/AttributeData/Node/Node.h" @@ -24,7 +31,7 @@ namespace AG { Graph *Graph::_all_graphs = nullptr; -os_unfair_lock Graph::_all_graphs_lock = OS_UNFAIR_LOCK_INIT; +platform_lock Graph::_all_graphs_lock = PLATFORM_LOCK_INIT; pthread_key_t Graph::_current_update_key = 0; @@ -32,8 +39,8 @@ Graph::Graph() : _heap(nullptr, 0, 0), _interned_types(nullptr, nullptr, nullptr, nullptr, &_heap), _contexts_by_id(nullptr, nullptr, nullptr, nullptr, &_heap), _id(AGMakeUniqueID()) { - static dispatch_once_t make_keys; - dispatch_once_f(&make_keys, nullptr, [](void *context) { + static platform_once_t make_keys; + platform_once(&make_keys, []() { pthread_key_create(&Graph::_current_update_key, 0); Subgraph::make_current_subgraph_key(); }); @@ -249,14 +256,14 @@ uint32_t Graph::intern_type(const swift::metadata *metadata, ClosureFunctionVPbody_metadata().vw_size(); if (self_size >= 0x2000) { - os_log_info(misc_log(), "large attribute self: %u bytes, %s", uint(self_size), - type->body_metadata().name(false)); + platform_log_info(misc_log(), "large attribute self: %u bytes, %s", uint(self_size), + type->body_metadata().name(false)); } size_t value_size = type->value_metadata().vw_size(); if (value_size >= 0x2000) { - os_log_info(misc_log(), "large attribute value: %u bytes, %s -> %s", uint(value_size), - type->body_metadata().name(false), type->value_metadata().name(false)); + platform_log_info(misc_log(), "large attribute value: %u bytes, %s -> %s", uint(value_size), + type->body_metadata().name(false), type->value_metadata().name(false)); } return type_id; @@ -1002,7 +1009,7 @@ bool Graph::passed_deadline_slow() { return true; } - uint64_t time = mach_absolute_time(); + platform_time_t time = platform_absolute_time(); if (time < _deadline) { return false; } @@ -1808,10 +1815,10 @@ void Graph::start_tracing(AGTraceFlags trace_flags, std::span subs } add_trace(_trace_recorder); - static dispatch_once_t cleanup; - dispatch_once(&cleanup, ^{ - // TODO - }); + static platform_once_t cleanup; + platform_once(&cleanup, []() { + // TODO + }); } } diff --git a/Sources/ComputeCxx/Graph/Graph.h b/Sources/ComputeCxx/Graph/Graph.h index 70d22ac..3921e84 100644 --- a/Sources/ComputeCxx/Graph/Graph.h +++ b/Sources/ComputeCxx/Graph/Graph.h @@ -1,16 +1,17 @@ #pragma once -#include -#include +#include "ComputeCxx/AGBase.h" + #include -#include #include -#include +#if TARGET_OS_MAC #ifdef __OBJC__ #import #endif +#endif +#include #include #include #include @@ -22,7 +23,7 @@ #include "Swift/Metadata.h" #include "Vector/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -68,7 +69,7 @@ class Graph { private: static Graph *_Nullable _all_graphs; - static os_unfair_lock _all_graphs_lock; + static platform_lock _all_graphs_lock; Graph *_Nullable _next; Graph *_Nullable _previous; @@ -122,9 +123,9 @@ class Graph { uint64_t _change_count = 0; uint64_t _version = 0; - static void all_lock() { os_unfair_lock_lock(&_all_graphs_lock); }; - static bool all_try_lock() { return os_unfair_lock_trylock(&_all_graphs_lock); }; - static void all_unlock() { os_unfair_lock_unlock(&_all_graphs_lock); }; + static void all_lock() { platform_lock_lock(&_all_graphs_lock); }; + static bool all_try_lock() { return platform_lock_trylock(&_all_graphs_lock); }; + static void all_unlock() { platform_lock_unlock(&_all_graphs_lock); }; // Main handler @@ -427,6 +428,7 @@ class Graph { // MARK: Description +#if TARGET_OS_MAC #ifdef __OBJC__ NSString *description(data::ptr node); @@ -439,8 +441,9 @@ class Graph { #endif static void write_to_file(Graph *_Nullable graph, const char *_Nullable filename, bool exclude_values); +#endif }; } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/Graph.mm b/Sources/ComputeCxx/Graph/Graph.mm index 2c6a968..39ec395 100644 --- a/Sources/ComputeCxx/Graph/Graph.mm +++ b/Sources/ComputeCxx/Graph/Graph.mm @@ -1,5 +1,7 @@ #include "Graph.h" +#if TARGET_OS_MAC + #import #include #include @@ -177,6 +179,7 @@ int trap_cycles() { [array addObject:[NSString stringWithFormat:@"dirty = %d", node->is_dirty()]]; [array addObject:[NSString stringWithFormat:@"updating = %d", node->count()]]; // TODO: check is count and not bool +#if TARGET_OS_MAC if (auto selfDescription = type.vtable().self_description) { if (node->is_self_initialized()) { void *body = node->get_self(type); @@ -193,6 +196,26 @@ int trap_cycles() { } } } +#else + if (auto copySelfDescription = type.vtable().copy_self_description) { + if (node->is_self_initialized()) { + void *body = node->get_self(type); + if (auto desc = copySelfDescription(reinterpret_cast(&type), body)) { + [array addObject:[NSString stringWithFormat:@"self = %@", desc]]; + CFRelease(desc); + } + } + } + if (auto copyValueDescription = type.vtable().copy_value_description) { + if (node->is_value_initialized()) { + void *value = node->get_value(); + if (auto desc = copyValueDescription(reinterpret_cast(&type), value)) { + [array addObject:[NSString stringWithFormat:@"value = %@", desc]]; + CFRelease(desc); + } + } + } +#endif // TODO: test what actual deliminator is return [array componentsJoinedByString:@","]; @@ -330,6 +353,8 @@ int trap_cycles() { node_dict[@"id"] = @(node.offset()); const AttributeType &attribute_type = graph->attribute_type(type_id); + +#if TARGET_OS_MAC if (node->is_self_initialized()) { void *body = node->get_self(attribute_type); if (auto desc = attribute_type.self_description(body)) { @@ -343,6 +368,23 @@ int trap_cycles() { node_dict[@"value"] = escaped_string((__bridge NSString *)value_desc, truncation_limit); } } +#else + if (node->is_self_initialized()) { + void *body = node->get_self(attribute_type); + if (auto desc = attribute_type.copy_self_description(body)) { + node_dict[@"desc"] = escaped_string((__bridge NSString *)desc, truncation_limit); + CFRelease(desc); + } + } + + if (include_values && node->is_value_initialized()) { + void *value = node->get_value(); + if (auto value_desc = attribute_type.copy_value_description(value)) { + node_dict[@"value"] = escaped_string((__bridge NSString *)value_desc, truncation_limit); + CFRelease(value_desc); + } + } +#endif auto flags = node->flags(); if (flags) { @@ -1026,3 +1068,5 @@ int trap_cycles() { } } // namespace AG + +#endif diff --git a/Sources/ComputeCxx/Graph/KeyTable.h b/Sources/ComputeCxx/Graph/KeyTable.h index 4c00524..e925fbb 100644 --- a/Sources/ComputeCxx/Graph/KeyTable.h +++ b/Sources/ComputeCxx/Graph/KeyTable.h @@ -1,12 +1,11 @@ #pragma once -#include - #include +#include "ComputeCxx/AGBase.h" #include "Graph.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -28,4 +27,4 @@ class Graph::KeyTable { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/TraceRecorder.cpp b/Sources/ComputeCxx/Graph/TraceRecorder.cpp index 345d2c7..1f8548f 100644 --- a/Sources/ComputeCxx/Graph/TraceRecorder.cpp +++ b/Sources/ComputeCxx/Graph/TraceRecorder.cpp @@ -1,8 +1,6 @@ #include "TraceRecorder.h" #include -#include -#include #include #include "Attribute/AttributeData/Node/IndirectNode.h" @@ -17,14 +15,6 @@ namespace AG { -namespace { - -uint64_t uuid_hash(const uuid_t key) { return *key; } - -bool uuid_equal(const uuid_t a, const uuid_t b) { return uuid_compare(a, b) == 0; } - -} // namespace - Graph::TraceRecorder::TraceRecorder(Graph *graph, AGTraceFlags trace_flags, std::span subsystems) { // TODO: not implemented } diff --git a/Sources/ComputeCxx/Graph/TraceRecorder.h b/Sources/ComputeCxx/Graph/TraceRecorder.h index 37678a0..ab270f2 100644 --- a/Sources/ComputeCxx/Graph/TraceRecorder.h +++ b/Sources/ComputeCxx/Graph/TraceRecorder.h @@ -1,14 +1,12 @@ #pragma once -#include -#include - #include +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGGraph.h" #include "Trace/Trace.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -98,4 +96,4 @@ class Graph::TraceRecorder : public Trace { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/Tree/TreeElement.h b/Sources/ComputeCxx/Graph/Tree/TreeElement.h index 01c9d6c..704ca38 100644 --- a/Sources/ComputeCxx/Graph/Tree/TreeElement.h +++ b/Sources/ComputeCxx/Graph/Tree/TreeElement.h @@ -1,13 +1,12 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGTreeElement.h" #include "Data/Pointer.h" #include "Graph/Graph.h" #include "TreeValue.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -17,7 +16,7 @@ class metadata; class Graph::TreeElementID : public data::ptr { public: - explicit constexpr TreeElementID(nullptr_t = nullptr) : ptr(nullptr) {} + explicit constexpr TreeElementID(std::nullptr_t = nullptr) : ptr(nullptr) {} explicit TreeElementID(data::ptr tree_element) : ptr(tree_element.offset()) {}; @@ -48,4 +47,4 @@ static_assert(sizeof(Graph::TreeElement) == 0x20); } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/Tree/TreeValue.h b/Sources/ComputeCxx/Graph/Tree/TreeValue.h index 3006749..3a010c4 100644 --- a/Sources/ComputeCxx/Graph/Tree/TreeValue.h +++ b/Sources/ComputeCxx/Graph/Tree/TreeValue.h @@ -1,12 +1,11 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGTreeValue.h" #include "Data/Pointer.h" #include "Graph/Graph.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -42,4 +41,4 @@ static_assert(sizeof(Graph::TreeValue) == 0x18); } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Graph/UpdateStack.h b/Sources/ComputeCxx/Graph/UpdateStack.h index 4c4dccf..c0d9ff2 100644 --- a/Sources/ComputeCxx/Graph/UpdateStack.h +++ b/Sources/ComputeCxx/Graph/UpdateStack.h @@ -1,10 +1,9 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "Graph.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -60,4 +59,4 @@ class Graph::UpdateStack { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Log/Log.cpp b/Sources/ComputeCxx/Log/Log.cpp index efbd1be..db41c05 100644 --- a/Sources/ComputeCxx/Log/Log.cpp +++ b/Sources/ComputeCxx/Log/Log.cpp @@ -2,8 +2,8 @@ namespace AG { -os_log_t misc_log() { - static os_log_t log = os_log_create("dev.incrematic.compute", "misc"); +platform_log_t misc_log() { + static platform_log_t log = platform_log_create("dev.incrematic.compute", "misc"); return log; } diff --git a/Sources/ComputeCxx/Log/Log.h b/Sources/ComputeCxx/Log/Log.h index 3e6877c..05e4dcf 100644 --- a/Sources/ComputeCxx/Log/Log.h +++ b/Sources/ComputeCxx/Log/Log.h @@ -1,14 +1,15 @@ #pragma once -#include -#include +#include -CF_ASSUME_NONNULL_BEGIN +#include "ComputeCxx/AGBase.h" + +AG_ASSUME_NONNULL_BEGIN namespace AG { -os_log_t misc_log(); +platform_log_t misc_log(); } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Private/CFRuntime.h b/Sources/ComputeCxx/Private/CFRuntime.h deleted file mode 100644 index 8f4c42f..0000000 --- a/Sources/ComputeCxx/Private/CFRuntime.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2015 Apple Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ - -/* CFRuntime.h - Copyright (c) 1999-2014, Apple Inc. All rights reserved. - */ - -#if !defined(__COREFOUNDATION_CFRUNTIME__) -#define __COREFOUNDATION_CFRUNTIME__ 1 - -#include -#include -#include - -CF_EXTERN_C_BEGIN - -#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) - -// GC: until we link against ObjC must use indirect functions. Overridden in CFSetupFoundationBridging -CF_EXPORT bool kCFUseCollectableAllocator; -CF_EXPORT bool (*__CFObjCIsCollectable)(void *); - -CF_INLINE Boolean _CFAllocatorIsSystemDefault(CFAllocatorRef allocator) { - if (allocator == kCFAllocatorSystemDefault) return true; - if (NULL == allocator || kCFAllocatorDefault == allocator) { - return (kCFAllocatorSystemDefault == CFAllocatorGetDefault()); - } - return false; -} - -// is GC on? -#define CF_USING_COLLECTABLE_MEMORY (kCFUseCollectableAllocator) -// is GC on and is this the GC allocator? -#define CF_IS_COLLECTABLE_ALLOCATOR(allocator) (kCFUseCollectableAllocator && (NULL == (allocator) || kCFAllocatorSystemDefault == (allocator) || 0)) -// is this allocated by the collector? -#define CF_IS_COLLECTABLE(obj) (__CFObjCIsCollectable ? __CFObjCIsCollectable((void*)obj) : false) - -#else - -#define kCFUseCollectableAllocator 0 -#define __CFObjCIsCollectable 0 - -CF_INLINE Boolean _CFAllocatorIsSystemDefault(CFAllocatorRef allocator) { - if (allocator == kCFAllocatorSystemDefault) return true; - if (NULL == allocator || kCFAllocatorDefault == allocator) { - return (kCFAllocatorSystemDefault == CFAllocatorGetDefault()); - } - return false; -} - -#define CF_USING_COLLECTABLE_MEMORY 0 -#define CF_IS_COLLECTABLE_ALLOCATOR(allocator) 0 -#define CF_IS_COLLECTABLE(obj) 0 -#endif - -enum { - _kCFRuntimeNotATypeID = 0 -}; - -enum { // Version field constants - _kCFRuntimeScannedObject = (1UL << 0), - _kCFRuntimeResourcefulObject = (1UL << 2), // tells CFRuntime to make use of the reclaim field - _kCFRuntimeCustomRefCount = (1UL << 3), // tells CFRuntime to make use of the refcount field - _kCFRuntimeRequiresAlignment = (1UL << 4), // tells CFRuntime to make use of the requiredAlignment field -}; - -typedef struct __CFRuntimeClass { - CFIndex version; - const char *className; // must be a pure ASCII string, nul-terminated - void (*init)(CFTypeRef cf); - CFTypeRef (*copy)(CFAllocatorRef allocator, CFTypeRef cf); - void (*finalize)(CFTypeRef cf); - Boolean (*equal)(CFTypeRef cf1, CFTypeRef cf2); - CFHashCode (*hash)(CFTypeRef cf); - CFStringRef (*copyFormattingDesc)(CFTypeRef cf, CFDictionaryRef formatOptions); // return str with retain - CFStringRef (*copyDebugDesc)(CFTypeRef cf); // return str with retain - -#define CF_RECLAIM_AVAILABLE 1 - void (*reclaim)(CFTypeRef cf); // Or in _kCFRuntimeResourcefulObject in the .version to indicate this field should be used - -#define CF_REFCOUNT_AVAILABLE 1 - uint32_t (*refcount)(intptr_t op, CFTypeRef cf); // Or in _kCFRuntimeCustomRefCount in the .version to indicate this field should be used - // this field must be non-NULL when _kCFRuntimeCustomRefCount is in the .version field - // - if the callback is passed 1 in 'op' it should increment the 'cf's reference count and return 0 - // - if the callback is passed 0 in 'op' it should return the 'cf's reference count, up to 32 bits - // - if the callback is passed -1 in 'op' it should decrement the 'cf's reference count; if it is now zero, 'cf' should be cleaned up and deallocated (the finalize callback above will NOT be called unless the process is running under GC, and CF does not deallocate the memory for you; if running under GC, finalize should do the object tear-down and free the object memory); then return 0 - // remember to use saturation arithmetic logic and stop incrementing and decrementing when the ref count hits UINT32_MAX, or you will have a security bug - // remember that reference count incrementing/decrementing must be done thread-safely/atomically - // objects should be created/initialized with a custom ref-count of 1 by the class creation functions - // do not attempt to use any bits within the CFRuntimeBase for your reference count; store that in some additional field in your CF object - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#define CF_REQUIRED_ALIGNMENT_AVAILABLE 1 - uintptr_t requiredAlignment; // Or in _kCFRuntimeRequiresAlignment in the .version field to indicate this field should be used; the allocator to _CFRuntimeCreateInstance() will be ignored in this case; if this is less than the minimum alignment the system supports, you'll get higher alignment; if this is not an alignment the system supports (e.g., most systems will only support powers of two, or if it is too high), the result (consequences) will be up to CF or the system to decide - -} CFRuntimeClass; - -#define RADAR_5115468_FIXED 1 - -/* Note that CF runtime class registration and unregistration is not currently - * thread-safe, which should not currently be a problem, as long as unregistration - * is done only when valid to do so. - */ - -CF_EXPORT CFTypeID _CFRuntimeRegisterClass(const CFRuntimeClass * const cls); -/* Registers a new class with the CF runtime. Pass in a - * pointer to a CFRuntimeClass structure. The pointer is - * remembered by the CF runtime -- the structure is NOT - * copied. - * - * - version field must be zero currently. - * - className field points to a null-terminated C string - * containing only ASCII (0 - 127) characters; this field - * may NOT be NULL. - * - init field points to a function which classes can use to - * apply some generic initialization to instances as they - * are created; this function is called by both - * _CFRuntimeCreateInstance and _CFRuntimeInitInstance; if - * this field is NULL, no function is called; the instance - * has been initialized enough that the polymorphic funcs - * CFGetTypeID(), CFRetain(), CFRelease(), CFGetRetainCount(), - * and CFGetAllocator() are valid on it when the init - * function if any is called. - * - copy field should always be NULL. Generic copying of CF - * objects has never been defined (and is unlikely). - * - finalize field points to a function which destroys an - * instance when the retain count has fallen to zero; if - * this is NULL, finalization does nothing. Note that if - * the class-specific functions which create or initialize - * instances more fully decide that a half-initialized - * instance must be destroyed, the finalize function for - * that class has to be able to deal with half-initialized - * instances. The finalize function should NOT destroy the - * memory for the instance itself; that is done by the - * CF runtime after this finalize callout returns. - * - equal field points to an equality-testing function; this - * field may be NULL, in which case only pointer/reference - * equality is performed on instances of this class. - * Pointer equality is tested, and the type IDs are checked - * for equality, before this function is called (so, the - * two instances are not pointer-equal but are of the same - * class before this function is called). - * NOTE: the equal function must implement an immutable - * equality relation, satisfying the reflexive, symmetric, - * and transitive properties, and remains the same across - * time and immutable operations (that is, if equal(A,B) at - * some point, then later equal(A,B) provided neither - * A or B has been mutated). - * - hash field points to a hash-code-computing function for - * instances of this class; this field may be NULL in which - * case the pointer value of an instance is converted into - * a hash. - * NOTE: the hash function and equal function must satisfy - * the relationship "equal(A,B) implies hash(A) == hash(B)"; - * that is, if two instances are equal, their hash codes must - * be equal too. (However, the converse is not true!) - * - copyFormattingDesc field points to a function returning a - * CFStringRef with a human-readable description of the - * instance; if this is NULL, the type does not have special - * human-readable string-formats. - * - copyDebugDesc field points to a function returning a - * CFStringRef with a debugging description of the instance; - * if this is NULL, a simple description is generated. - * - * This function returns _kCFRuntimeNotATypeID on failure, or - * on success, returns the CFTypeID for the new class. This - * CFTypeID is what the class uses to allocate or initialize - * instances of the class. It is also returned from the - * conventional *GetTypeID() function, which returns the - * class's CFTypeID so that clients can compare the - * CFTypeID of instances with that of a class. - * - * The function to compute a human-readable string is very - * optional, and is really only interesting for classes, - * like strings or numbers, where it makes sense to format - * the instance using just its contents. - */ - -CF_EXPORT const CFRuntimeClass * _CFRuntimeGetClassWithTypeID(CFTypeID typeID); -/* Returns the pointer to the CFRuntimeClass which was - * assigned the specified CFTypeID. - */ - -CF_EXPORT void _CFRuntimeUnregisterClassWithTypeID(CFTypeID typeID); -/* Unregisters the class with the given type ID. It is - * undefined whether type IDs are reused or not (expect - * that they will be). - * - * Whether or not unregistering the class is a good idea or - * not is not CF's responsibility. In particular you must - * be quite sure all instances are gone, and there are no - * valid weak refs to such in other threads. - */ - -/* All CF "instances" start with this structure. Never refer to - * these fields directly -- they are for CF's use and may be added - * to or removed or change format without warning. Binary - * compatibility for uses of this struct is not guaranteed from - * release to release. - */ -typedef struct __CFRuntimeBase { - uintptr_t _cfisa; - uint8_t _cfinfo[4]; -#if __LP64__ - uint32_t _rc; -#endif -} CFRuntimeBase; - -#if __BIG_ENDIAN__ -#define INIT_CFRUNTIME_BASE(...) {0, {0, 0, 0, 0x80}} -#else -#define INIT_CFRUNTIME_BASE(...) {0, {0x80, 0, 0, 0}} -#endif - -CF_EXPORT CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CFIndex extraBytes, unsigned char *category); -/* Creates a new CF instance of the class specified by the - * given CFTypeID, using the given allocator, and returns it. - * If the allocator returns NULL, this function returns NULL. - * A CFRuntimeBase structure is initialized at the beginning - * of the returned instance. extraBytes is the additional - * number of bytes to allocate for the instance (BEYOND that - * needed for the CFRuntimeBase). If the specified CFTypeID - * is unknown to the CF runtime, this function returns NULL. - * No part of the new memory other than base header is - * initialized (the extra bytes are not zeroed, for example). - * All instances created with this function must be destroyed - * only through use of the CFRelease() function -- instances - * must not be destroyed by using CFAllocatorDeallocate() - * directly, even in the initialization or creation functions - * of a class. Pass NULL for the category parameter. - */ - -CF_EXPORT void _CFRuntimeSetInstanceTypeID(CFTypeRef cf, CFTypeID typeID); -/* This function changes the typeID of the given instance. - * If the specified CFTypeID is unknown to the CF runtime, - * this function does nothing. This function CANNOT be used - * to initialize an instance. It is for advanced usages such - * as faulting. You cannot change the CFTypeID of an object - * of a _kCFRuntimeCustomRefCount class, or to a - * _kCFRuntimeCustomRefCount class. - */ - -CF_EXPORT void _CFRuntimeInitStaticInstance(void *memory, CFTypeID typeID); -/* This function initializes a memory block to be a constant - * (unreleaseable) CF object of the given typeID. - * If the specified CFTypeID is unknown to the CF runtime, - * this function does nothing. The memory block should - * be a chunk of in-binary writeable static memory, and at - * least as large as sizeof(CFRuntimeBase) on the platform - * the code is being compiled for. The init function of the - * CFRuntimeClass is invoked on the memory as well, if the - * class has one. Static instances cannot be initialized to - * _kCFRuntimeCustomRefCount classes. - */ -#define CF_HAS_INIT_STATIC_INSTANCE 1 - -CF_EXTERN_C_END - -#endif /* ! __COREFOUNDATION_CFRUNTIME__ */ diff --git a/Sources/ComputeCxx/Subgraph/AGSubgraph-Private.h b/Sources/ComputeCxx/Subgraph/AGSubgraph-Private.h index 4bb8d74..82174c4 100644 --- a/Sources/ComputeCxx/Subgraph/AGSubgraph-Private.h +++ b/Sources/ComputeCxx/Subgraph/AGSubgraph-Private.h @@ -1,19 +1,24 @@ #pragma once -#include +#include "ComputeCxx/AGBase.h" + +#if TARGET_OS_MAC +#include "CoreFoundationPrivate/CFRuntime.h" +#else +#include +#endif #include "ComputeCxx/AGSubgraph.h" -#include "Private/CFRuntime.h" + +AG_ASSUME_NONNULL_BEGIN namespace AG { class Subgraph; } -CF_ASSUME_NONNULL_BEGIN - struct AGSubgraphStorage { CFRuntimeBase base; AG::Subgraph *_Nullable subgraph; }; -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Subgraph/AGSubgraph.cpp b/Sources/ComputeCxx/Subgraph/AGSubgraph.cpp index a8bd404..b7f001a 100644 --- a/Sources/ComputeCxx/Subgraph/AGSubgraph.cpp +++ b/Sources/ComputeCxx/Subgraph/AGSubgraph.cpp @@ -1,7 +1,8 @@ #include "AGSubgraph-Private.h" +#include + #include "Graph/Context.h" -#include "Private/CFRuntime.h" #include "Subgraph.h" namespace { @@ -345,10 +346,10 @@ void AGSubgraphEndTreeElement(AGAttribute value) { current_subgraph->end_tree(); } -static dispatch_once_t should_record_tree_once = 0; +static platform_once_t should_record_tree_once = 0; static bool should_record_tree = true; -void init_should_record_tree(void *context) { +void init_should_record_tree() { char *result = getenv("AG_TREE"); if (result) { should_record_tree = atoi(result) != 0; @@ -358,11 +359,11 @@ void init_should_record_tree(void *context) { } bool AGSubgraphShouldRecordTree() { - dispatch_once_f(&should_record_tree_once, nullptr, init_should_record_tree); + platform_once(&should_record_tree_once, init_should_record_tree); return should_record_tree; } void AGSubgraphSetShouldRecordTree() { - dispatch_once_f(&should_record_tree_once, nullptr, init_should_record_tree); + platform_once(&should_record_tree_once, init_should_record_tree); should_record_tree = true; } diff --git a/Sources/ComputeCxx/Subgraph/Subgraph.cpp b/Sources/ComputeCxx/Subgraph/Subgraph.cpp index a29c329..de1d2a8 100644 --- a/Sources/ComputeCxx/Subgraph/Subgraph.cpp +++ b/Sources/ComputeCxx/Subgraph/Subgraph.cpp @@ -1,5 +1,6 @@ #include "Subgraph.h" +#include #include #include diff --git a/Sources/ComputeCxx/Subgraph/Subgraph.h b/Sources/ComputeCxx/Subgraph/Subgraph.h index d920c3e..e6504a0 100644 --- a/Sources/ComputeCxx/Subgraph/Subgraph.h +++ b/Sources/ComputeCxx/Subgraph/Subgraph.h @@ -1,17 +1,16 @@ #pragma once -#include - #include "AGSubgraph-Private.h" #include "Attribute/AttributeID/AttributeID.h" #include "Closure/ClosureFunction.h" +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGUniqueID.h" #include "Data/Zone.h" #include "Graph/Graph.h" #include "Graph/Tree/TreeElement.h" #include "Vector/IndirectPointerVector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN struct AGSubgraphStorage; @@ -202,4 +201,4 @@ class Subgraph : public data::zone { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Swift/AGTuple.cpp b/Sources/ComputeCxx/Swift/AGTuple.cpp index 9466f38..0864bef 100644 --- a/Sources/ComputeCxx/Swift/AGTuple.cpp +++ b/Sources/ComputeCxx/Swift/AGTuple.cpp @@ -200,7 +200,7 @@ void AGTupleWithBuffer(AGTupleType tuple_type, size_t count, AGUnsafeMutableTuple tuple = {tuple_type, buffer}; function(context, tuple); } else { - void *buffer = malloc_type_malloc(buffer_size, 0x100004077774924); + void *buffer = malloc(buffer_size); if (buffer == nullptr) { AG::precondition_failure("memory allocation failure"); } diff --git a/Sources/ComputeCxx/Swift/AGType.cpp b/Sources/ComputeCxx/Swift/AGType.cpp index 2063992..c32aeaa 100644 --- a/Sources/ComputeCxx/Swift/AGType.cpp +++ b/Sources/ComputeCxx/Swift/AGType.cpp @@ -1,21 +1,34 @@ #include "ComputeCxx/AGType.h" +#if TARGET_OS_MAC #include +#else +#include +#endif #include "Closure/ClosureFunction.h" #include "ContextDescriptor.h" #include "Metadata.h" #include "MetadataVisitor.h" +#if TARGET_OS_MAC CFStringRef AGTypeDescription(AGTypeID typeID) { auto type = reinterpret_cast(typeID); - CFMutableStringRef description = CFStringCreateMutable(kCFAllocatorDefault, 0); type->append_description(description); CFAutorelease(description); return description; } +#else +CFStringRef AGTypeCopyDescription(AGTypeID typeID) { + auto type = reinterpret_cast(typeID); + CFMutableStringRef description = + CFStringCreateMutable(kCFAllocatorDefault, 0); + type->append_description(description); + return description; +} +#endif AGTypeKind AGTypeGetKind(AGTypeID typeID) { auto type = reinterpret_cast(typeID); diff --git a/Sources/ComputeCxx/Swift/ContextDescriptor.h b/Sources/ComputeCxx/Swift/ContextDescriptor.h index 8f635b0..487a505 100644 --- a/Sources/ComputeCxx/Swift/ContextDescriptor.h +++ b/Sources/ComputeCxx/Swift/ContextDescriptor.h @@ -1,14 +1,13 @@ #pragma once -#include #include -#include #include +#include "ComputeCxx/AGBase.h" #include "Metadata.h" #include "Vector/Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace swift { @@ -65,4 +64,4 @@ class class_type_descriptor { } // namespace swift } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Swift/Metadata.cpp b/Sources/ComputeCxx/Swift/Metadata.cpp index f6b9688..4e9ee87 100644 --- a/Sources/ComputeCxx/Swift/Metadata.cpp +++ b/Sources/ComputeCxx/Swift/Metadata.cpp @@ -1,18 +1,23 @@ #include "Metadata.h" -#include +#if TARGET_OS_MAC #include +#else +#include +#endif #include #include #include +#include +#include +#include #include #include #include "ContextDescriptor.h" #include "Errors/Errors.h" #include "MetadataVisitor.h" -#include "Swift/mach-o/dyld.h" #include "_SwiftStdlibCxxOverlay.h" namespace AG { @@ -174,14 +179,14 @@ namespace { class TypeSignatureCache { private: - os_unfair_lock _lock; + platform_lock _lock; util::Table _table; public: - TypeSignatureCache() : _lock(OS_UNFAIR_LOCK_INIT), _table() {}; + TypeSignatureCache() : _lock(PLATFORM_LOCK_INIT), _table() {}; - void lock() { os_unfair_lock_lock(&_lock); }; - void unlock() { os_unfair_lock_unlock(&_lock); }; + void lock() { platform_lock_lock(&_lock); }; + void unlock() { platform_lock_unlock(&_lock); }; const unsigned char *lookup(const metadata *type, const metadata **_Nullable found) { return _table.lookup(type, found); @@ -226,27 +231,27 @@ const void *metadata::signature() const { } } } - + if (descriptors.size()) { - auto context = CC_SHA1_CTX(); - CC_SHA1_Init(&context); + auto context = PLATFORM_SHA1_CTX(); + PLATFORM_SHA1_Init(&context); const char prefix[] = "AGTypeSignature"; - CC_SHA1_Update(&context, prefix, sizeof(prefix)); + PLATFORM_SHA1_Update(&context, prefix, sizeof(prefix)); - auto infos = vector(); + auto infos = vector(); infos.reserve(descriptors.size()); - dyld_images_for_addresses((unsigned)descriptors.size(), static_cast(descriptors.data()), + platform_image_infos_for_addresses((unsigned)descriptors.size(), static_cast(descriptors.data()), infos.data()); for (auto info : infos) { - CC_SHA1_Update(&context, info.uuid, sizeof(((dyld_image_uuid_offset *)0)->uuid)); - CC_SHA1_Update(&context, &info.offsetInImage, sizeof(((dyld_image_uuid_offset *)0)->offsetInImage)); + PLATFORM_SHA1_Update(&context, info.identifier, sizeof(((platform_image_info_t *)0)->identifier)); + PLATFORM_SHA1_Update(&context, &info.offset, sizeof(((platform_image_info_t *)0)->offset)); } - auto digest = new unsigned char[CC_SHA1_DIGEST_LENGTH]; - CC_SHA1_Final(digest, &context); + auto digest = new unsigned char[PLATFORM_SHA1_DIGEST_LENGTH]; + PLATFORM_SHA1_Final(digest, &context); signature = digest; } else { @@ -263,6 +268,7 @@ const void *metadata::signature() const { const equatable_witness_table *metadata::equatable() const { switch (getKind()) { case ::swift::MetadataKind::Class: { +#if TARGET_OS_MAC static const equatable_witness_table *nsobject_conformance = []() -> const equatable_witness_table * { Class nsobject = objc_getClass("NSObject"); if (!nsobject) { @@ -272,14 +278,18 @@ const equatable_witness_table *metadata::equatable() const { if (!nsobject_metadata) { return nullptr; } - auto witness_table = swift_conformsToProtocol(nsobject_metadata, EquatableProtocolDescriptor); + auto witness_table = + swift_conformsToProtocol(nsobject_metadata, &EquatableProtocolDescriptor); return reinterpret_cast(witness_table); }(); +#endif auto conformance = reinterpret_cast( swift_conformsToProtocol(this, &EquatableProtocolDescriptor)); +#if TARGET_OS_MAC if (conformance == nsobject_conformance) { return nullptr; } +#endif return conformance; } case ::swift::MetadataKind::Struct: @@ -406,14 +416,14 @@ class TypeCache { using value_info = std::pair; private: - os_unfair_lock _lock; + platform_lock _lock; util::Heap _heap; char _heap_buffer[4096]; util::Table _table; public: TypeCache() - : _lock(OS_UNFAIR_LOCK_INIT), _heap(_heap_buffer, 4096, 0), + : _lock(PLATFORM_LOCK_INIT), _heap(_heap_buffer, 4096, 0), _table([](const key_info *key) -> uint64_t { return uintptr_t(key->first) * 0x21 ^ uintptr_t(key->second); }, [](const key_info *a, const key_info *b) -> bool { if (a->first != b->first) { @@ -423,8 +433,8 @@ class TypeCache { }, nullptr, nullptr, &_heap) {}; - void lock() { os_unfair_lock_lock(&_lock); }; - void unlock() { os_unfair_lock_unlock(&_lock); }; + void lock() { platform_lock_lock(&_lock); }; + void unlock() { platform_lock_unlock(&_lock); }; const value_info *lookup(const key_info *type, const key_info **_Nullable found) { return _table.lookup(type, found); @@ -607,10 +617,12 @@ bool metadata::visit_heap(metadata_visitor &visitor, LayoutDescriptor::HeapMode bool metadata::visit_heap_class(metadata_visitor &visitor) const { const auto class_type = static_cast(base()); +#if SWIFT_OBJC_INTEROP if ((class_type->Data & 3) == 0) { // Pure Objective-C class unsupported return visitor.unknown_result(); } +#endif auto context = descriptor(); if (!context) { @@ -647,6 +659,7 @@ bool metadata::visit_heap_class(metadata_visitor &visitor) const { if ((class_type->Flags & ::swift::ClassFlags::UsesSwiftRefcounting) == 0) { size_t *ivar_offsets = nullptr; // TODO: use new +#if SWIFT_OBJC_INTEROP unsigned int ivar_count; Ivar *ivar_list = class_copyIvarList(reinterpret_cast((void *)this), &ivar_count); if (ivar_list) { @@ -658,6 +671,7 @@ bool metadata::visit_heap_class(metadata_visitor &visitor) const { } free(ivar_list); } +#endif if (ivar_offsets && *ivar_offsets != 0) { unsigned index = 0; diff --git a/Sources/ComputeCxx/Swift/Metadata.h b/Sources/ComputeCxx/Swift/Metadata.h index a6366fc..9357463 100644 --- a/Sources/ComputeCxx/Swift/Metadata.h +++ b/Sources/ComputeCxx/Swift/Metadata.h @@ -1,12 +1,12 @@ #pragma once -#include -#include #include +#include +#include "ComputeCxx/AGBase.h" #include "Comparison/LayoutDescriptor.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN CF_EXPORT const void *PROTOCOL_DESCR_SYM(SQ); @@ -30,6 +30,7 @@ class metadata : public ::swift::Metadata { static const metadata *from_base(const ::swift::Metadata *base) { return static_cast(base); }; bool is_type_metadata() const { +#if SWIFT_OBJC_INTEROP if (::swift::ClassMetadata::classof(this)) { const auto class_type = static_cast(base()); // Depending on the deployment target a binary was compiled for, @@ -39,6 +40,7 @@ class metadata : public ::swift::Metadata { // https://github.com/swiftlang/swift/blob/main/include/swift/ABI/Metadata.h return class_type->Data & 0x3; } +#endif return true; } @@ -95,4 +97,4 @@ class existential_type_metadata : public ::swift::ExistentialTypeMetadata { } // namespace swift } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Swift/MetadataVisitor.h b/Sources/ComputeCxx/Swift/MetadataVisitor.h index 987fda3..4d58ff8 100644 --- a/Sources/ComputeCxx/Swift/MetadataVisitor.h +++ b/Sources/ComputeCxx/Swift/MetadataVisitor.h @@ -4,12 +4,12 @@ #include #include -#include #include +#include "ComputeCxx/AGBase.h" #include "Metadata.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { namespace swift { @@ -35,4 +35,4 @@ class metadata_visitor { } // namespace swift } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Swift/SwiftShims.h b/Sources/ComputeCxx/Swift/SwiftShims.h index e9031e0..c4df267 100644 --- a/Sources/ComputeCxx/Swift/SwiftShims.h +++ b/Sources/ComputeCxx/Swift/SwiftShims.h @@ -1,14 +1,18 @@ #pragma once -#include +#include "ComputeCxx/AGBase.h" + +#if TARGET_OS_MAC #include #include +#else +#include +#include +#endif -#include "ComputeCxx/AGSwiftSupport.h" - -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN AG_SWIFT_CC(swift) bool AGDispatchEquatable(const void *lhs_value, const void *rhs_value, const ::swift::Metadata *type, @@ -19,6 +23,6 @@ AG_SWIFT_CC(swift) bool AGSetTypeForKey(NSMutableDictionary *dict, NSString *key, const ::swift::Metadata *type); #endif -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Swift/_SwiftStdlibCxxOverlay.h b/Sources/ComputeCxx/Swift/_SwiftStdlibCxxOverlay.h index 1d45ada..dccf70e 100644 --- a/Sources/ComputeCxx/Swift/_SwiftStdlibCxxOverlay.h +++ b/Sources/ComputeCxx/Swift/_SwiftStdlibCxxOverlay.h @@ -1,6 +1,6 @@ #pragma once -#include "ComputeCxx/AGSwiftSupport.h" +#include "ComputeCxx/AGBase.h" extern "C" const ::swift::Metadata *_Nullable swift_getTypeByMangledNameInContext( const char *_Nullable typeNameStart, size_t typeNameLength, const void *_Nullable context, diff --git a/Sources/ComputeCxx/Swift/mach-o/dyld.cpp b/Sources/ComputeCxx/Swift/mach-o/dyld.cpp deleted file mode 100644 index e05661f..0000000 --- a/Sources/ComputeCxx/Swift/mach-o/dyld.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "dyld.h" - -#include -#include -#include - -#include "MachOFile.h" - -bool dyld_get_image_uuid(const mach_header *mh, uuid_t uuid) { - const MachOFile *mf = (MachOFile *)mh; - if (!mf->hasMachOMagic()) { - return false; - } - return mf->getUuid(uuid); -} - -void dyld_images_for_addresses(unsigned count, const void *addresses[], dyld_image_uuid_offset infos[]) { - for (unsigned i = 0; i < count; i++) { - const void *addr = addresses[i]; - bzero(&infos[i], sizeof(dyld_image_uuid_offset)); - - Dl_info dl_info; - if (dladdr(addr, &dl_info)) { - infos[i].image = (mach_header *)dl_info.dli_fbase; - infos[i].offsetInImage = (uintptr_t)addr - (uintptr_t)dl_info.dli_fbase; - dyld_get_image_uuid((mach_header *)dl_info.dli_fbase, infos[i].uuid); - } - } -} diff --git a/Sources/ComputeCxx/Swift/mach-o/dyld.h b/Sources/ComputeCxx/Swift/mach-o/dyld.h deleted file mode 100644 index cd9dd32..0000000 --- a/Sources/ComputeCxx/Swift/mach-o/dyld.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include - -extern "C" { - -struct dyld_image_uuid_offset { - uuid_t uuid; - uint64_t offsetInImage; - const struct mach_header *image; -}; - -// Given an array of addresses, returns info about each address. -// For each address, returns the where that image was loaded, the offset -// of the address in the image, and the image's uuid. If a specified -// address is unknown to dyld, all fields will be returned a zeros. -extern void dyld_images_for_addresses(unsigned count, const void *addresses[], struct dyld_image_uuid_offset infos[]); -} diff --git a/Sources/ComputeCxx/Time/Time.cpp b/Sources/ComputeCxx/Time/Time.cpp index 39480a7..164c5c1 100644 --- a/Sources/ComputeCxx/Time/Time.cpp +++ b/Sources/ComputeCxx/Time/Time.cpp @@ -1,21 +1,43 @@ #include "Time.h" +#if TARGET_OS_MAC #include +#else +#include +#endif #include namespace AG { -double current_time() { return absolute_time_to_seconds(mach_absolute_time()); } +double current_time() { +#if TARGET_OS_MAC + uint64_t ticks = mach_absolute_time(); +#else + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { + return NAN; + } + + // Convert to nanoseconds to match Darwin "ticks" semantics + uint64_t ticks = static_cast(ts.tv_sec) * 1000000000ull + static_cast(ts.tv_nsec); +#endif + return absolute_time_to_seconds(ticks); +} double absolute_time_to_seconds(uint64_t ticks) { +#if TARGET_OS_MAC static double time_scale = []() -> double { struct mach_timebase_info info; auto err = mach_timebase_info(&info); if (err) { return NAN; } - return (info.numer / info.denom) * 0.000000001; + return (info.numer / info.denom) * 1e-9; }(); +#else + // On POSIX, ticks are already nanoseconds + static const double time_scale = 1e-9; +#endif return static_cast(ticks) * time_scale; } diff --git a/Sources/ComputeCxx/Time/Time.h b/Sources/ComputeCxx/Time/Time.h index f17a9cf..875ec45 100644 --- a/Sources/ComputeCxx/Time/Time.h +++ b/Sources/ComputeCxx/Time/Time.h @@ -1,8 +1,14 @@ #include +#include "ComputeCxx/AGBase.h" + +AG_ASSUME_NONNULL_BEGIN + namespace AG { double current_time(void); double absolute_time_to_seconds(uint64_t ticks); } + +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Trace/ExternalTrace.h b/Sources/ComputeCxx/Trace/ExternalTrace.h index 41fde40..dbbe974 100644 --- a/Sources/ComputeCxx/Trace/ExternalTrace.h +++ b/Sources/ComputeCxx/Trace/ExternalTrace.h @@ -1,7 +1,6 @@ #pragma once -#include - +#include "ComputeCxx/AGBase.h" #include "ComputeCxx/AGAttribute.h" #include "ComputeCxx/AGComparison.h" #include "ComputeCxx/AGGraph.h" @@ -10,7 +9,7 @@ #include "Subgraph/Subgraph.h" #include "Trace/Trace.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN class ExternalTrace : public AG::Trace { public: @@ -92,4 +91,4 @@ class ExternalTrace : public AG::Trace { size_t range_size, const AG::swift::metadata *_Nullable type) override; }; -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Trace/Trace.h b/Sources/ComputeCxx/Trace/Trace.h index 8912b09..fb285f9 100644 --- a/Sources/ComputeCxx/Trace/Trace.h +++ b/Sources/ComputeCxx/Trace/Trace.h @@ -1,12 +1,18 @@ #pragma once +#include "ComputeCxx/AGBase.h" + +#if TARGET_OS_MAC #include +#else +#include +#endif #include "ComputeCxx/AGGraph.h" #include "ComputeCxx/AGUniqueID.h" #include "Graph/Graph.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -100,4 +106,4 @@ class Trace { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/UniqueID/AGUniqueID.cpp b/Sources/ComputeCxx/UniqueID/AGUniqueID.cpp index d816b46..90c780e 100644 --- a/Sources/ComputeCxx/UniqueID/AGUniqueID.cpp +++ b/Sources/ComputeCxx/UniqueID/AGUniqueID.cpp @@ -1,6 +1,8 @@ -#include "ComputeCxx/AGUniqueID.h" +#include + +#include AGUniqueID AGMakeUniqueID() { - static uint64_t counter = 0; - return ++counter; + static atomic_ulong counter = 1; + return atomic_fetch_add_explicit(&counter, 1, memory_order_relaxed); } diff --git a/Sources/ComputeCxx/Vector/IndirectPointerVector.h b/Sources/ComputeCxx/Vector/IndirectPointerVector.h index 2735d30..e289090 100644 --- a/Sources/ComputeCxx/Vector/IndirectPointerVector.h +++ b/Sources/ComputeCxx/Vector/IndirectPointerVector.h @@ -1,12 +1,11 @@ #pragma once -#include "CoreFoundation/CFBase.h" #include -#include +#include "ComputeCxx/AGBase.h" #include "Vector.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -280,4 +279,4 @@ void indirect_pointer_vector::resize(size_type count) { } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/Vector/Vector.h b/Sources/ComputeCxx/Vector/Vector.h index fb7a855..211ac8b 100644 --- a/Sources/ComputeCxx/Vector/Vector.h +++ b/Sources/ComputeCxx/Vector/Vector.h @@ -1,16 +1,18 @@ #pragma once -#include #include #include +#include #include #include -#include #include +#include + +#include "ComputeCxx/AGBase.h" #include "Errors/Errors.h" -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN namespace AG { @@ -806,4 +808,4 @@ void vector, 0, size_type>::push_back(std::uniq } // namespace AG -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGAttribute.h b/Sources/ComputeCxx/include/ComputeCxx/AGAttribute.h index 8caa425..e4aecce 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGAttribute.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGAttribute.h @@ -1,24 +1,21 @@ #pragma once -#include -#include +#include -#include +AG_ASSUME_NONNULL_BEGIN -CF_ASSUME_NONNULL_BEGIN - -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef uint32_t AGAttribute AG_SWIFT_STRUCT AG_SWIFT_NAME(AnyAttribute); -CF_EXPORT +AG_EXPORT const AGAttribute AGAttributeNil; -typedef CF_OPTIONS(uint8_t, AGAttributeFlags) { +typedef AG_OPTIONS(uint8_t, AGAttributeFlags) { AGAttributeFlagsNone = 0, AGAttributeFlagsAll = 0xFF, -} CF_SWIFT_NAME(AGSubgraphRef.Flags); +} AG_SWIFT_NAME(AGSubgraphRef.Flags); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGAttributeInfo.h b/Sources/ComputeCxx/include/ComputeCxx/AGAttributeInfo.h index 7a14d9f..926d04e 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGAttributeInfo.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGAttributeInfo.h @@ -1,19 +1,17 @@ #pragma once -#include - #include -#include +#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct AGAttributeInfo { const AGAttributeType *type; const void *body; } AGAttributeInfo; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGAttributeType.h b/Sources/ComputeCxx/include/ComputeCxx/AGAttributeType.h index d3ac5f4..8aa81c9 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGAttributeType.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGAttributeType.h @@ -1,25 +1,38 @@ #pragma once +#include + +#if TARGET_OS_MAC +#include +#else +#include +#endif + #include #include -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct AGAttributeType AGAttributeType; -typedef struct CF_SWIFT_NAME(_AttributeVTable) AGAttributeVTable { +typedef struct AG_SWIFT_NAME(_AttributeVTable) AGAttributeVTable { unsigned long version; void (*_Nullable type_destroy)(AGAttributeType *); void (*_Nullable self_destroy)(const AGAttributeType *, void *); +#if TARGET_OS_MAC CFStringRef _Nullable (*_Nullable self_description)(const AGAttributeType *, const void *); CFStringRef _Nullable (*_Nullable value_description)(const AGAttributeType *, const void *); +#else + CFStringRef _Nullable (*_Nullable copy_self_description)(const AGAttributeType *, const void *); + CFStringRef _Nullable (*_Nullable copy_value_description)(const AGAttributeType *, const void *); +#endif void (*_Nullable update_default)(const AGAttributeType *, void *); } AGAttributeVTable; -typedef CF_OPTIONS(uint32_t, AGAttributeTypeFlags) { +typedef AG_OPTIONS(uint32_t, AGAttributeTypeFlags) { AGAttributeTypeFlagsComparisonModeBitwise = 0, AGAttributeTypeFlagsComparisonModeIndirect = 1, AGAttributeTypeFlagsComparisonModeEquatableUnlessPOD = 2, @@ -30,9 +43,9 @@ typedef CF_OPTIONS(uint32_t, AGAttributeTypeFlags) { AGAttributeTypeFlagsMainThread = 1 << 3, AGAttributeTypeFlagsExternal = 1 << 4, AGAttributeTypeFlagsAsyncThread = 1 << 5, -} CF_SWIFT_NAME(_AttributeType.Flags); +} AG_SWIFT_NAME(_AttributeType.Flags); -typedef struct CF_SWIFT_NAME(_AttributeType) AGAttributeType { +typedef struct AG_SWIFT_NAME(_AttributeType) AGAttributeType { AGTypeID self_id; AGTypeID value_id; AGClosureStorage update; @@ -48,7 +61,7 @@ typedef struct CF_SWIFT_NAME(_AttributeType) AGAttributeType { } body_conformance; } AGAttributeType; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGBase.h b/Sources/ComputeCxx/include/ComputeCxx/AGBase.h new file mode 100644 index 0000000..748a9fb --- /dev/null +++ b/Sources/ComputeCxx/include/ComputeCxx/AGBase.h @@ -0,0 +1,200 @@ +#pragma once + +#include +#include +#include + +#include "AGTargetConditionals.h" + +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +#define _AG_STRINGIFY(_x) #_x + +#if !defined(AG_EXTERN_C_BEGIN) +#if defined(__cplusplus) +#define AG_EXTERN_C_BEGIN extern "C" { +#define AG_EXTERN_C_END } +#else +#define AG_EXTERN_C_BEGIN +#define AG_EXTERN_C_END +#endif +#endif + +#if __GNUC__ +#define AG_EXPORT extern __attribute__((__visibility__("default"))) +#else +#define AG_EXPORT extern +#endif + +#if __GNUC__ +#define AG_INLINE static __inline__ +#else +#define AG_INLINE static inline +#endif + +#ifndef AG_RETURNS_RETAINED +#if __has_feature(attribute_cf_returns_retained) +#define AG_RETURNS_RETAINED __attribute__((cf_returns_retained)) +#else +#define AG_RETURNS_RETAINED +#endif +#endif + +#ifndef AG_IMPLICIT_BRIDGING_ENABLED +#if __has_feature(arc_cf_code_audited) +#define AG_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin") +#else +#define AG_IMPLICIT_BRIDGING_ENABLED +#endif +#endif + +#ifndef AG_IMPLICIT_BRIDGING_DISABLED +#if __has_feature(arc_cf_code_audited) +#define AG_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end") +#else +#define AG_IMPLICIT_BRIDGING_DISABLED +#endif +#endif + +#if __has_attribute(objc_bridge) && __has_feature(objc_bridge_id) && __has_feature(objc_bridge_id_on_typedefs) + +#ifdef __OBJC__ +@class NSArray; +@class NSAttributedString; +@class NSString; +@class NSNull; +@class NSCharacterSet; +@class NSData; +@class NSDate; +@class NSTimeZone; +@class NSDictionary; +@class NSError; +@class NSLocale; +@class NSNumber; +@class NSSet; +@class NSURL; +#endif + +#define AG_BRIDGED_TYPE(T) __attribute__((objc_bridge(T))) +#define AG_BRIDGED_MUTABLE_TYPE(T) __attribute__((objc_bridge_mutable(T))) +#define AG_RELATED_TYPE(T,C,I) __attribute__((objc_bridge_related(T,C,I))) +#else +#define AG_BRIDGED_TYPE(T) +#define AG_BRIDGED_MUTABLE_TYPE(T) +#define AG_RELATED_TYPE(T,C,I) +#endif + +#if __has_feature(assume_nonnull) +#define AG_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define AG_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define AG_ASSUME_NONNULL_BEGIN +#define AG_ASSUME_NONNULL_END +#endif + +#if !__has_feature(nullability) +#ifndef _Nullable +#define _Nullable +#endif +#ifndef _Nonnull +#define _Nonnull +#endif +#ifndef _Null_unspecified +#define _Null_unspecified +#endif +#endif + +#if __has_attribute(enum_extensibility) +#define __AG_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open))) +#define __AG_CLOSED_ENUM_ATTRIBUTES __attribute__((enum_extensibility(closed))) +#define __AG_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open))) +#else +#define __AG_ENUM_ATTRIBUTES +#define __AG_CLOSED_ENUM_ATTRIBUTES +#define __AG_OPTIONS_ATTRIBUTES +#endif + +#define __AG_ENUM_FIXED_IS_AVAILABLE (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && (__has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum))) + +#if __AG_ENUM_FIXED_IS_AVAILABLE +#define AG_ENUM(_type, _name) enum __AG_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type +#define AG_CLOSED_ENUM(_type, _name) enum __AG_CLOSED_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type +#if (__cplusplus) +#define AG_OPTIONS(_type, _name) __attribute__((availability(swift,unavailable))) _type _name; enum __AG_OPTIONS_ATTRIBUTES : _name +#else +#define AG_OPTIONS(_type, _name) enum __AG_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type +#endif +#else +#define AG_ENUM(_type, _name) _type _name; enum +#define AG_CLOSED_ENUM(_type, _name) _type _name; enum +#define AG_OPTIONS(_type, _name) _type _name; enum +#endif + +#if __has_attribute(swift_private) +#define AG_REFINED_FOR_SWIFT __attribute__((swift_private)) +#else +#define AG_REFINED_FOR_SWIFT +#endif + +#if __has_attribute(swift_name) +#define AG_SWIFT_NAME(_name) __attribute__((swift_name(#_name))) +#else +#define AG_SWIFT_NAME(_name) +#endif + +#if __has_attribute(swift_wrapper) +#define AG_SWIFT_STRUCT __attribute__((swift_wrapper(struct))) +#else +#define AG_SWIFT_STRUCT +#endif + +// Define mappings for calling conventions. + +// Annotation for specifying a calling convention of +// a runtime function. It should be used with declarations +// of runtime functions like this: +// void runtime_function_name() AG_SWIFT_CC(swift) +#define AG_SWIFT_CC(CC) AG_SWIFT_CC_##CC + +// AG_SWIFT_CC(c) is the C calling convention. +#define AG_SWIFT_CC_c + +// AG_SWIFT_CC(swift) is the Swift calling convention. +#if __has_attribute(swiftcall) +#define AG_SWIFT_CC_swift __attribute__((swiftcall)) +#define AG_SWIFT_CONTEXT __attribute__((swift_context)) +#define AG_SWIFT_ERROR_RESULT __attribute__((swift_error_result)) +#define AG_SWIFT_INDIRECT_RESULT __attribute__((swift_indirect_result)) +#else +#define AG_SWIFT_CC_swift +#define AG_SWIFT_CONTEXT +#define AG_SWIFT_ERROR_RESULT +#define AG_SWIFT_INDIRECT_RESULT +#endif + +#if __has_attribute(swift_attr) +#define AG_SWIFT_SHARED_REFERENCE(_retain, _release) \ + __attribute__((swift_attr("import_reference"))) \ + __attribute__((swift_attr(_AG_STRINGIFY(retain:_retain)))) \ + __attribute__((swift_attr(_AG_STRINGIFY(release:_release)))) +#else +#define AG_SWIFT_SHARED_REFERENCE(_retain, _release) +#endif + +#if __has_include() +#include +#define AG_COUNTED_BY(N) __counted_by(N) +#else +#define AG_COUNTED_BY(N) +#endif diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGChangedValue.h b/Sources/ComputeCxx/include/ComputeCxx/AGChangedValue.h index a826c81..f754bf2 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGChangedValue.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGChangedValue.h @@ -1,14 +1,12 @@ #pragma once -#include +#include -#include +AG_ASSUME_NONNULL_BEGIN -CF_ASSUME_NONNULL_BEGIN +AG_EXTERN_C_BEGIN -CF_EXTERN_C_BEGIN - -typedef CF_OPTIONS(uint8_t, AGChangedValueFlags) { +typedef AG_OPTIONS(uint8_t, AGChangedValueFlags) { AGChangedValueFlagsChanged = 1 << 0, AGChangedValueFlagsRequiresMainThread = 1 << 1, }; @@ -23,6 +21,6 @@ typedef struct AGWeakChangedValue { AGChangedValueFlags flags; } AGWeakChangedValue; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGClosure.h b/Sources/ComputeCxx/include/ComputeCxx/AGClosure.h index ee7ac60..bdf8820 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGClosure.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGClosure.h @@ -1,27 +1,25 @@ #pragma once -#include +#include -#include "AGSwiftSupport.h" +AG_ASSUME_NONNULL_BEGIN -CF_ASSUME_NONNULL_BEGIN +AG_EXTERN_C_BEGIN -CF_EXTERN_C_BEGIN - -typedef struct CF_SWIFT_NAME(_AGClosureStorage) AGClosureStorage { +typedef struct AG_SWIFT_NAME(_AGClosureStorage) AGClosureStorage { const void *thunk; const void *_Nullable context; } AGClosureStorage; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGClosureStorage AGRetainClosure(void (*closure)(void *_Nullable context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), void *_Nullable closure_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGReleaseClosure(AGClosureStorage closure); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGComparison.h b/Sources/ComputeCxx/include/ComputeCxx/AGComparison.h index 87c8b16..88ddada 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGComparison.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGComparison.h @@ -1,15 +1,12 @@ #pragma once -#include -#include - -#include +#include #include -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct AGFieldRange { size_t offset; @@ -18,30 +15,30 @@ typedef struct AGFieldRange { typedef struct AGComparisonStateStorage *AGComparisonState AG_SWIFT_STRUCT AG_SWIFT_NAME(ComparisonState); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT const void *AGComparisonStateGetDestination(AGComparisonState state); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT const void *AGComparisonStateGetSource(AGComparisonState state); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGFieldRange AGComparisonStateGetFieldRange(AGComparisonState state); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGTypeID AGComparisonStateGetFieldType(AGComparisonState state); -typedef CF_ENUM(uint8_t, AGComparisonMode) { +typedef AG_ENUM(uint8_t, AGComparisonMode) { AGComparisonModeBitwise = 0, AGComparisonModeIndirect = 1, AGComparisonModeEquatableUnlessPOD = 2, AGComparisonModeEquatableAlways = 3, -} CF_SWIFT_NAME(ComparisonMode); +} AG_SWIFT_NAME(ComparisonMode); -typedef CF_OPTIONS(uint32_t, AGComparisonOptions) { +typedef AG_OPTIONS(uint32_t, AGComparisonOptions) { AGComparisonOptionsComparisonModeBitwise = 0, AGComparisonOptionsComparisonModeIndirect = 1, AGComparisonOptionsComparisonModeEquatableUnlessPOD = 2, @@ -51,23 +48,23 @@ typedef CF_OPTIONS(uint32_t, AGComparisonOptions) { AGComparisonOptionsCopyOnWrite = 1 << 8, AGComparisonOptionsFetchLayoutsSynchronously = 1 << 9, AGComparisonOptionsTraceCompareFailed = 1ul << 31, // -1 signed int -} CF_SWIFT_NAME(ComparisonOptions); +} AG_SWIFT_NAME(ComparisonOptions); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGCompareValues(const void *_Nonnull destination, const void *_Nonnull source, AGTypeID type_id, AGComparisonOptions options); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT const unsigned char *_Nullable AGPrefetchCompareValues(AGTypeID type_id, AGComparisonOptions options, uint32_t priority); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGOverrideComparisonForTypeDescriptor(void *descriptor, AGComparisonMode mode); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGDescription.h b/Sources/ComputeCxx/include/ComputeCxx/AGDescription.h index 235ce94..d9a844b 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGDescription.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGDescription.h @@ -1,29 +1,37 @@ #pragma once -#include +#include + +#if TARGET_OS_MAC #include +#else +#include +#endif #include -#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN + +AG_EXTERN_C_BEGIN + +#if TARGET_OS_MAC -CF_EXTERN_C_BEGIN +typedef CFStringRef AGDescriptionOption AG_SWIFT_STRUCT AG_SWIFT_NAME(DescriptionOption); -typedef CFStringRef AGDescriptionOption AG_SWIFT_STRUCT CF_SWIFT_NAME(DescriptionOption); +AG_EXPORT +const AGDescriptionOption AGDescriptionFormat AG_SWIFT_NAME(AGDescriptionOption.format); -CF_EXPORT -const AGDescriptionOption AGDescriptionFormat CF_SWIFT_NAME(AGDescriptionOption.format); +AG_EXPORT +const AGDescriptionOption AGDescriptionMaxFrames AG_SWIFT_NAME(AGDescriptionOption.maxFrames); -CF_EXPORT -const AGDescriptionOption AGDescriptionMaxFrames CF_SWIFT_NAME(AGDescriptionOption.maxFrames); +AG_EXPORT +const AGDescriptionOption AGDescriptionIncludeValues AG_SWIFT_NAME(AGDescriptionOption.includeValues); -CF_EXPORT -const AGDescriptionOption AGDescriptionIncludeValues CF_SWIFT_NAME(AGDescriptionOption.includeValues); +AG_EXPORT +const AGDescriptionOption AGDescriptionTruncationLimit AG_SWIFT_NAME(AGDescriptionOption.truncationLimit); -CF_EXPORT -const AGDescriptionOption AGDescriptionTruncationLimit CF_SWIFT_NAME(AGDescriptionOption.truncationLimit); +#endif -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGGraph.h b/Sources/ComputeCxx/include/ComputeCxx/AGGraph.h index bb558da..cdb18f5 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGGraph.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGGraph.h @@ -1,9 +1,16 @@ #pragma once +#include + +#if TARGET_OS_MAC #include -#include #include #include +#else +#include +#include +#include +#endif #include #include @@ -13,72 +20,71 @@ #include #include #include -#include #include #include #include #include -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN // MARK: CFType -typedef struct CF_BRIDGED_TYPE(id) AGGraphStorage *AGGraphRef AG_SWIFT_NAME(Graph); +typedef struct AG_BRIDGED_TYPE(id) AGGraphStorage *AGGraphRef AG_SWIFT_NAME(Graph); typedef void *AGUnownedGraphContextRef AG_SWIFT_STRUCT; typedef struct AGTrace *AGTraceRef; -CF_EXPORT -CF_REFINED_FOR_SWIFT -CFTypeID AGGraphGetTypeID(void) CF_SWIFT_NAME(getter:AGGraphRef.typeID()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +CFTypeID AGGraphGetTypeID(void) AG_SWIFT_NAME(getter:AGGraphRef.typeID()); // MARK: Graph Context -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGGraphRef AGGraphCreate(void) CF_SWIFT_NAME(AGGraphRef.init()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGGraphRef AGGraphCreate(void) AG_SWIFT_NAME(AGGraphRef.init()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGGraphRef AGGraphCreateShared(AGGraphRef _Nullable graph) CF_SWIFT_NAME(AGGraphRef.init(shared:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGGraphRef AGGraphCreateShared(AGGraphRef _Nullable graph) AG_SWIFT_NAME(AGGraphRef.init(shared:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGUnownedGraphContextRef AGGraphGetGraphContext(AGGraphRef graph) CF_SWIFT_NAME(getter:AGGraphRef.graphContext(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGUnownedGraphContextRef AGGraphGetGraphContext(AGGraphRef graph) AG_SWIFT_NAME(getter:AGGraphRef.graphContext(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGGraphRef AGGraphContextGetGraph(void *context); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphInvalidate(AGGraphRef graph) CF_SWIFT_NAME(AGGraphRef.invalidate(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphInvalidate(AGGraphRef graph) AG_SWIFT_NAME(AGGraphRef.invalidate(self:)); // MARK: User context -CF_EXPORT -CF_REFINED_FOR_SWIFT -const void *_Nullable AGGraphGetContext(AGGraphRef graph) CF_SWIFT_NAME(getter:AGGraphRef.context(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +const void *_Nullable AGGraphGetContext(AGGraphRef graph) AG_SWIFT_NAME(getter:AGGraphRef.context(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetContext(AGGraphRef graph, const void *_Nullable context) - CF_SWIFT_NAME(setter:AGGraphRef.context(self:_:)); + AG_SWIFT_NAME(setter:AGGraphRef.context(self:_:)); // MARK: Counter -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT uint64_t AGGraphGetCounter(AGGraphRef graph, AGGraphCounterQueryType query) - CF_SWIFT_NAME(AGGraphRef.counter(self:for:)); + AG_SWIFT_NAME(AGGraphRef.counter(self:for:)); // MARK: Main handler -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphWithMainThreadHandler(AGGraphRef graph, void (*body)(const void *context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *body_context, @@ -89,141 +95,141 @@ void AGGraphWithMainThreadHandler(AGGraphRef graph, // MARK: Subgraphs -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGGraphBeginDeferringSubgraphInvalidation(AGGraphRef graph) - CF_SWIFT_NAME(AGGraphRef.beginDeferringSubgraphInvalidation(self:)); + AG_SWIFT_NAME(AGGraphRef.beginDeferringSubgraphInvalidation(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphEndDeferringSubgraphInvalidation(AGGraphRef graph, bool was_deferring) - CF_SWIFT_NAME(AGGraphRef.endDeferringSubgraphInvalidation(self:wasDeferring:)); + AG_SWIFT_NAME(AGGraphRef.endDeferringSubgraphInvalidation(self:wasDeferring:)); // MARK: Attribute types -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT uint32_t AGGraphInternAttributeType(AGUnownedGraphContextRef graph, AGTypeID type, const AGAttributeType *_Nonnull (*_Nonnull make_attribute_type)( const void *_Nullable context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *_Nullable make_attribute_type_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphVerifyType(AGAttribute attribute, AGTypeID type) CF_SWIFT_NAME(AGAttribute.verifyType(self:type:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphVerifyType(AGAttribute attribute, AGTypeID type) AG_SWIFT_NAME(AGAttribute.verifyType(self:type:)); // MARK: Attributes -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphCreateAttribute(uint32_t type_id, const void *body, const void *_Nullable value) - CF_SWIFT_NAME(AGAttribute.init(type:body:value:)); + AG_SWIFT_NAME(AGAttribute.init(type:body:value:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGGraphRef AGGraphGetAttributeGraph(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.graph(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGGraphRef AGGraphGetAttributeGraph(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.graph(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGAttributeInfo AGGraphGetAttributeInfo(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.info(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGAttributeInfo AGGraphGetAttributeInfo(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.info(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGAttributeFlags AGGraphGetFlags(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.flags(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGAttributeFlags AGGraphGetFlags(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.flags(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphSetFlags(AGAttribute attribute, AGAttributeFlags flags) CF_SWIFT_NAME(setter:AGAttribute.flags(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphSetFlags(AGAttribute attribute, AGAttributeFlags flags) AG_SWIFT_NAME(setter:AGAttribute.flags(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT uint32_t AGGraphAddInput(AGAttribute attribute, AGAttribute input, AGInputOptions options) - CF_SWIFT_NAME(AGAttribute.addInput(self:_:options:)); + AG_SWIFT_NAME(AGAttribute.addInput(self:_:options:)); // MARK: Offset attributes -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphCreateOffsetAttribute(AGAttribute attribute, uint32_t offset); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphCreateOffsetAttribute2(AGAttribute attribute, uint32_t offset, size_t size); // MARK: Indirect attributes -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGAttribute AGGraphCreateIndirectAttribute(AGAttribute attribute) CF_SWIFT_NAME(AGAttribute.createIndirect(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGAttribute AGGraphCreateIndirectAttribute(AGAttribute attribute) AG_SWIFT_NAME(AGAttribute.createIndirect(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphCreateIndirectAttribute2(AGAttribute attribute, size_t size); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGAttribute AGGraphGetIndirectAttribute(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.source(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGAttribute AGGraphGetIndirectAttribute(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.source(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetIndirectAttribute(AGAttribute attribute, AGAttribute source) - CF_SWIFT_NAME(setter:AGAttribute.source(self:_:)); + AG_SWIFT_NAME(setter:AGAttribute.source(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphResetIndirectAttribute(AGAttribute attribute, bool non_nil); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphGetIndirectDependency(AGAttribute attribute); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetIndirectDependency(AGAttribute attribute, AGAttribute dependency); // MARK: Search -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGGraphSearch(AGAttribute attribute, AGSearchOptions options, bool (*predicate)(const void *context AG_SWIFT_CONTEXT, AGAttribute attribute) AG_SWIFT_CC(swift), const void *predicate_context); // MARK: Body -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphMutateAttribute(AGAttribute attribute, AGTypeID type, bool invalidating, void (*modify)(const void *context AG_SWIFT_CONTEXT, void *body) AG_SWIFT_CC(swift), const void *modify_context); // MARK: Value -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGChangedValue AGGraphGetValue(AGAttribute attribute, AGValueOptions options, AGTypeID type); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGWeakChangedValue AGGraphGetWeakValue(AGWeakAttribute attribute, AGValueOptions options, AGTypeID type); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGChangedValue AGGraphGetInputValue(AGAttribute attribute, AGAttribute input, AGValueOptions options, AGTypeID type); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGGraphSetValue(AGAttribute attribute, const void *value, AGTypeID type); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphHasValue(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.hasValue(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphHasValue(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.hasValue(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGValueState AGGraphGetValueState(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.valueState(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGValueState AGGraphGetValueState(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.valueState(self:)); -typedef CF_OPTIONS(uint32_t, AGGraphUpdateOptions) { +typedef AG_OPTIONS(uint32_t, AGGraphUpdateOptions) { AGGraphUpdateOptionsNone = 0, AGGraphUpdateOptionsInTransaction = 1 << 0, AGGraphUpdateOptionsAbortIfCancelled = 1 << 1, @@ -232,25 +238,25 @@ typedef CF_OPTIONS(uint32_t, AGGraphUpdateOptions) { AGGraphUpdateOptionsEndDeferringSubgraphInvalidationOnExit = 1 << 4, }; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphUpdateValue(AGAttribute attribute, AGGraphUpdateOptions options) - CF_SWIFT_NAME(AGAttribute.updateValue(self:options:)); + AG_SWIFT_NAME(AGAttribute.updateValue(self:options:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint32_t AGGraphPrefetchValue(AGAttribute attribute) CF_SWIFT_NAME(AGAttribute.prefetchValue(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint32_t AGGraphPrefetchValue(AGAttribute attribute) AG_SWIFT_NAME(AGAttribute.prefetchValue(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphInvalidateValue(AGAttribute attribute) CF_SWIFT_NAME(AGAttribute.invalidateValue(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphInvalidateValue(AGAttribute attribute) AG_SWIFT_NAME(AGAttribute.invalidateValue(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphInvalidateAllValues(AGGraphRef graph) CF_SWIFT_NAME(AGGraphRef.invalidateAllValues(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphInvalidateAllValues(AGGraphRef graph) AG_SWIFT_NAME(AGGraphRef.invalidateAllValues(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetInvalidationCallback(AGGraphRef graph, void (*callback)(const void *context AG_SWIFT_CONTEXT, AGAttribute) AG_SWIFT_CC(swift), @@ -258,182 +264,184 @@ void AGGraphSetInvalidationCallback(AGGraphRef graph, // MARK: Update -typedef CF_ENUM(uint32_t, AGGraphUpdateStatus) { +typedef AG_ENUM(uint32_t, AGGraphUpdateStatus) { AGGraphUpdateStatusNoChange = 0, AGGraphUpdateStatusChanged = 1, AGGraphUpdateStatusAborted = 2, AGGraphUpdateStatusNeedsCallMainHandler = 3, }; -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphSetUpdate(const void *update) CF_SWIFT_NAME(AGGraphRef.setUpdate(_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphSetUpdate(const void *update) AG_SWIFT_NAME(AGGraphRef.setUpdate(_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -const void *AGGraphClearUpdate(void) CF_SWIFT_NAME(AGGraphRef.clearUpdate()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +const void *AGGraphClearUpdate(void) AG_SWIFT_NAME(AGGraphRef.clearUpdate()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphCancelUpdate(void) CF_SWIFT_NAME(AGGraphRef.cancelUpdate()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphCancelUpdate(void) AG_SWIFT_NAME(AGGraphRef.cancelUpdate()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphCancelUpdateIfNeeded(void) CF_SWIFT_NAME(AGGraphRef.cancelUpdateIfNeeded()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphCancelUpdateIfNeeded(void) AG_SWIFT_NAME(AGGraphRef.cancelUpdateIfNeeded()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphUpdateWasCancelled(void) CF_SWIFT_NAME(getter:AGGraphRef.updateWasCancelled()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphUpdateWasCancelled(void) AG_SWIFT_NAME(getter:AGGraphRef.updateWasCancelled()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint64_t AGGraphGetDeadline(AGGraphRef graph) CF_SWIFT_NAME(getter:AGGraphRef.deadline(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint64_t AGGraphGetDeadline(AGGraphRef graph) AG_SWIFT_NAME(getter:AGGraphRef.deadline(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphSetDeadline(AGGraphRef graph, uint64_t deadline) CF_SWIFT_NAME(setter:AGGraphRef.deadline(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphSetDeadline(AGGraphRef graph, uint64_t deadline) AG_SWIFT_NAME(setter:AGGraphRef.deadline(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphHasDeadlinePassed(void) CF_SWIFT_NAME(getter:AGGraphRef.hasDeadlinePassed()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphHasDeadlinePassed(void) AG_SWIFT_NAME(getter:AGGraphRef.hasDeadlinePassed()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphSetNeedsUpdate(AGGraphRef graph) CF_SWIFT_NAME(AGGraphRef.setNeedsUpdate(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphSetNeedsUpdate(AGGraphRef graph) AG_SWIFT_NAME(AGGraphRef.setNeedsUpdate(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphWithUpdate(AGAttribute attribute, void (*body)(const void *context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *body_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphWithoutUpdate(void (*body)(const void *context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *body_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetUpdateCallback(AGGraphRef graph, void (*callback)(const void *context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *callback_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGGraphGetCurrentAttribute(void); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphCurrentAttributeWasModified(void) CF_SWIFT_NAME(getter:AGAttribute.currentWasModified()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphCurrentAttributeWasModified(void) AG_SWIFT_NAME(getter:AGAttribute.currentWasModified()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphAnyInputsChanged(const AGAttribute *__counted_by(count) exclude_attributes, size_t count); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphAnyInputsChanged(const AGAttribute *AG_COUNTED_BY(count) exclude_attributes, size_t count); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void *_Nullable AGGraphGetOutputValue(AGTypeID type); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetOutputValue(const void *value, AGTypeID type); // MARK: Trace -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphStartTracing(AGGraphRef _Nullable graph, AGTraceFlags trace_flags) - CF_SWIFT_NAME(AGGraphRef.startTracing(_:flags:)); + AG_SWIFT_NAME(AGGraphRef.startTracing(_:flags:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphStartTracing2(AGGraphRef _Nullable graph, AGTraceFlags trace_flags, CFArrayRef _Nullable subsystems) - CF_SWIFT_NAME(AGGraphRef.startTracing(_:flags:subsystems:)); // TODO: flags or options + AG_SWIFT_NAME(AGGraphRef.startTracing(_:flags:subsystems:)); // TODO: flags or options -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphStopTracing(AGGraphRef _Nullable graph) CF_SWIFT_NAME(AGGraphRef.stopTracing(_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphStopTracing(AGGraphRef _Nullable graph) AG_SWIFT_NAME(AGGraphRef.stopTracing(_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphSyncTracing(AGGraphRef graph) CF_SWIFT_NAME(AGGraphRef.syncTracing(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphSyncTracing(AGGraphRef graph) AG_SWIFT_NAME(AGGraphRef.syncTracing(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -CFStringRef AGGraphCopyTracePath(AGGraphRef graph) CF_SWIFT_NAME(getter:AGGraphRef.tracePath(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +CFStringRef AGGraphCopyTracePath(AGGraphRef graph) AG_SWIFT_NAME(getter:AGGraphRef.tracePath(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT uint64_t AGGraphAddTrace(AGGraphRef graph, const AGTraceRef trace, void *_Nullable context) - CF_SWIFT_NAME(AGGraphRef.addTrace(self:_:context:)); + AG_SWIFT_NAME(AGGraphRef.addTrace(self:_:context:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphRemoveTrace(AGGraphRef graph, uint64_t trace_id) CF_SWIFT_NAME(AGGraphRef.removeTrace(self:traceID:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphRemoveTrace(AGGraphRef graph, uint64_t trace_id) AG_SWIFT_NAME(AGGraphRef.removeTrace(self:traceID:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphSetTrace(AGGraphRef graph, const AGTraceRef trace, void *_Nullable context) - CF_SWIFT_NAME(AGGraphRef.setTrace(self:_:context:)); + AG_SWIFT_NAME(AGGraphRef.setTrace(self:_:context:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphResetTrace(AGGraphRef graph) CF_SWIFT_NAME(AGGraphRef.resetTrace(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphResetTrace(AGGraphRef graph) AG_SWIFT_NAME(AGGraphRef.resetTrace(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGGraphIsTracingActive(AGGraphRef graph) CF_SWIFT_NAME(getter:AGGraphRef.isTracingActive(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGGraphIsTracingActive(AGGraphRef graph) AG_SWIFT_NAME(getter:AGGraphRef.isTracingActive(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphPrepareTrace(AGGraphRef graph, const AGTraceRef trace, void *_Nullable context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGGraphTraceEventEnabled(AGGraphRef graph, uint32_t event_id) - CF_SWIFT_NAME(AGGraphRef.traceEventEnabled(self:for:)); + AG_SWIFT_NAME(AGGraphRef.traceEventEnabled(self:for:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphAddTraceEvent(AGGraphRef graph, const char *event_name, const void *value, AGTypeID type) - CF_SWIFT_NAME(AGGraphRef.addTraceEvent(self:name:value:type:)); + AG_SWIFT_NAME(AGGraphRef.addTraceEvent(self:name:value:type:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphAddNamedTraceEvent(AGGraphRef graph, uint32_t event_id, uint32_t event_arg_count, const void *event_args, CFDataRef data, uint32_t arg6) - CF_SWIFT_NAME(AGGraphRef.addNamedTraceEvent(self:eventID:eventArgCount:eventArgs:data:arg6:)); + AG_SWIFT_NAME(AGGraphRef.addNamedTraceEvent(self:eventID:eventArgCount:eventArgs:data:arg6:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -const char *_Nullable AGGraphGetTraceEventName(uint32_t event_id) CF_SWIFT_NAME(AGGraphRef.traceEventName(for:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +const char *_Nullable AGGraphGetTraceEventName(uint32_t event_id) AG_SWIFT_NAME(AGGraphRef.traceEventName(for:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT const char *_Nullable AGGraphGetTraceEventSubsystem(uint32_t event_id) - CF_SWIFT_NAME(AGGraphRef.traceEventSubsystem(for:)); + AG_SWIFT_NAME(AGGraphRef.traceEventSubsystem(for:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT uint32_t AGGraphRegisterNamedTraceEvent(const char *event_name, const char *event_subsystem) - CF_SWIFT_NAME(AGGraphRef.registerNamedTraceEvent(name:subsystem:)); + AG_SWIFT_NAME(AGGraphRef.registerNamedTraceEvent(name:subsystem:)); // MARK: Description -CF_EXPORT -CF_REFINED_FOR_SWIFT +#if TARGET_OS_MAC +AG_EXPORT +AG_REFINED_FOR_SWIFT CFTypeRef _Nullable AGGraphDescription(AGGraphRef _Nullable graph, CFDictionaryRef options) - CF_SWIFT_NAME(AGGraphRef.description(_:options:)); + AG_SWIFT_NAME(AGGraphRef.description(_:options:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGGraphArchiveJSON(const char *_Nullable filename) CF_SWIFT_NAME(AGGraphRef.archiveJSON(name:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGGraphArchiveJSON(const char *_Nullable filename) AG_SWIFT_NAME(AGGraphRef.archiveJSON(name:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGGraphArchiveJSON2(const char *filename, bool exclude_values) - CF_SWIFT_NAME(AGGraphRef.archiveJSON(name:excludeValues:)); + AG_SWIFT_NAME(AGGraphRef.archiveJSON(name:excludeValues:)); +#endif -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGGraphCounterQueryType.h b/Sources/ComputeCxx/include/ComputeCxx/AGGraphCounterQueryType.h index f40991d..a23da42 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGGraphCounterQueryType.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGGraphCounterQueryType.h @@ -1,8 +1,8 @@ #pragma once -#include +#include -typedef CF_ENUM(uint32_t, AGGraphCounterQueryType) { +typedef AG_ENUM(uint32_t, AGGraphCounterQueryType) { AGGraphCounterQueryTypeNodes, AGGraphCounterQueryTypeTransactions, AGGraphCounterQueryTypeUpdates, @@ -17,4 +17,4 @@ typedef CF_ENUM(uint32_t, AGGraphCounterQueryType) { AGGraphCounterQueryTypeCreatedNodes, AGGraphCounterQueryTypeSubgraphs, AGGraphCounterQueryTypeCreatedSubgraphs, -} CF_SWIFT_NAME(AGGraphRef.CounterQueryType); +} AG_SWIFT_NAME(AGGraphRef.CounterQueryType); diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGInputOptions.h b/Sources/ComputeCxx/include/ComputeCxx/AGInputOptions.h index d2fc6bf..09224ad 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGInputOptions.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGInputOptions.h @@ -1,12 +1,12 @@ #pragma once -#include +#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN -typedef CF_OPTIONS(uint8_t, AGInputOptions) { +typedef AG_OPTIONS(uint8_t, AGInputOptions) { AGInputOptionsNone = 0, AGInputOptionsUnprefetched = 1 << 0, AGInputOptionsSyncMainRef = 1 << 1, @@ -15,6 +15,6 @@ typedef CF_OPTIONS(uint8_t, AGInputOptions) { AGInputOptionsEnabled = 1 << 4, }; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGSearchOptions.h b/Sources/ComputeCxx/include/ComputeCxx/AGSearchOptions.h index f6ecbdd..5093336 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGSearchOptions.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGSearchOptions.h @@ -1,17 +1,17 @@ #pragma once -#include +#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN -typedef CF_OPTIONS(uint32_t, AGSearchOptions) { +typedef AG_OPTIONS(uint32_t, AGSearchOptions) { AGSearchOptionsSearchInputs = 1 << 0, AGSearchOptionsSearchOutputs = 1 << 1, AGSearchOptionsTraverseGraphContexts = 1 << 2, -} CF_SWIFT_NAME(SearchOptions); +} AG_SWIFT_NAME(SearchOptions); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGSubgraph.h b/Sources/ComputeCxx/include/ComputeCxx/AGSubgraph.h index fc62f4d..ce4e4ba 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGSubgraph.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGSubgraph.h @@ -1,187 +1,186 @@ #pragma once -#include - +#include #include #include #include -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN // MARK: CFType -typedef struct CF_BRIDGED_TYPE(id) AGSubgraphStorage *AGSubgraphRef CF_SWIFT_NAME(Subgraph); +typedef struct AG_BRIDGED_TYPE(id) AGSubgraphStorage *AGSubgraphRef AG_SWIFT_NAME(Subgraph); -CF_EXPORT -CF_REFINED_FOR_SWIFT -CFTypeID AGSubgraphGetTypeID(void) CF_SWIFT_NAME(getter:AGSubgraphRef.typeID()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +CFTypeID AGSubgraphGetTypeID(void) AG_SWIFT_NAME(getter:AGSubgraphRef.typeID()); // MARK: Current subgraph -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGSubgraphRef _Nullable AGSubgraphGetCurrent(void) CF_SWIFT_NAME(getter:AGSubgraphRef.current()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGSubgraphRef _Nullable AGSubgraphGetCurrent(void) AG_SWIFT_NAME(getter:AGSubgraphRef.current()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphSetCurrent(AGSubgraphRef _Nullable subgraph) CF_SWIFT_NAME(setter:AGSubgraphRef.current(_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphSetCurrent(AGSubgraphRef _Nullable subgraph) AG_SWIFT_NAME(setter:AGSubgraphRef.current(_:)); // MARK: Graph Context -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGSubgraphRef AGSubgraphCreate(AGGraphRef graph) CF_SWIFT_NAME(AGSubgraphRef.init(graph:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGSubgraphRef AGSubgraphCreate(AGGraphRef graph) AG_SWIFT_NAME(AGSubgraphRef.init(graph:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGSubgraphRef AGSubgraphCreate2(AGGraphRef graph, AGAttribute attribute) - CF_SWIFT_NAME(AGSubgraphRef.init(graph:attribute:)); + AG_SWIFT_NAME(AGSubgraphRef.init(graph:attribute:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGUnownedGraphContextRef _Nullable AGSubgraphGetCurrentGraphContext(void) - CF_SWIFT_NAME(getter:AGSubgraphRef.currentGraphContext()); + AG_SWIFT_NAME(getter:AGSubgraphRef.currentGraphContext()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGGraphRef AGSubgraphGetGraph(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.graph(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGGraphRef AGSubgraphGetGraph(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.graph(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGSubgraphIsValid(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.isValid(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGSubgraphIsValid(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.isValid(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphInvalidate(AGSubgraphRef subgraph) CF_SWIFT_NAME(AGSubgraphRef.invalidate(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphInvalidate(AGSubgraphRef subgraph) AG_SWIFT_NAME(AGSubgraphRef.invalidate(self:)); // MARK: Index -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint32_t AGSubgraphGetIndex(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.index(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint32_t AGSubgraphGetIndex(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.index(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphSetIndex(AGSubgraphRef subgraph, uint32_t index) CF_SWIFT_NAME(setter:AGSubgraphRef.index(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphSetIndex(AGSubgraphRef subgraph, uint32_t index) AG_SWIFT_NAME(setter:AGSubgraphRef.index(self:_:)); // MARK: Observers -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGUniqueID AGSubgraphAddObserver(AGSubgraphRef subgraph, void (*observer)(const void *_Nullable context AG_SWIFT_CONTEXT) AG_SWIFT_CC(swift), const void *_Nullable observer_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphRemoveObserver(AGSubgraphRef subgraph, AGUniqueID observer_id) - CF_SWIFT_NAME(AGSubgraphRef.removeObserver(self:_:)); + AG_SWIFT_NAME(AGSubgraphRef.removeObserver(self:_:)); // MARK: Children -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphAddChild(AGSubgraphRef subgraph, AGSubgraphRef child) CF_SWIFT_NAME(AGSubgraphRef.addChild(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphAddChild(AGSubgraphRef subgraph, AGSubgraphRef child) AG_SWIFT_NAME(AGSubgraphRef.addChild(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphAddChild2(AGSubgraphRef subgraph, AGSubgraphRef child, uint8_t tag) - CF_SWIFT_NAME(AGSubgraphRef.addChild(self:_:tag:)); + AG_SWIFT_NAME(AGSubgraphRef.addChild(self:_:tag:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphRemoveChild(AGSubgraphRef subgraph, AGSubgraphRef child) - CF_SWIFT_NAME(AGSubgraphRef.removeChild(self:_:)); + AG_SWIFT_NAME(AGSubgraphRef.removeChild(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGSubgraphRef AGSubgraphGetChild(AGSubgraphRef subgraph, uint32_t index, uint8_t *_Nullable tag_out) - CF_SWIFT_NAME(AGSubgraphRef.child(self:at:tag:)); + AG_SWIFT_NAME(AGSubgraphRef.child(self:at:tag:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint32_t AGSubgraphGetChildCount(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.childCount(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint32_t AGSubgraphGetChildCount(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.childCount(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGSubgraphRef AGSubgraphGetParent(AGSubgraphRef subgraph, int64_t index) CF_SWIFT_NAME(AGSubgraphRef.parent(self:at:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGSubgraphRef AGSubgraphGetParent(AGSubgraphRef subgraph, int64_t index) AG_SWIFT_NAME(AGSubgraphRef.parent(self:at:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint64_t AGSubgraphGetParentCount(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.parentCount(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint64_t AGSubgraphGetParentCount(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.parentCount(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGSubgraphIsAncestor(AGSubgraphRef subgraph, AGSubgraphRef other) - CF_SWIFT_NAME(AGSubgraphRef.isAncestor(self:of:)); + AG_SWIFT_NAME(AGSubgraphRef.isAncestor(self:of:)); // MARK: Flags -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGSubgraphIntersects(AGSubgraphRef subgraph, AGAttributeFlags flags) - CF_SWIFT_NAME(AGSubgraphRef.intersects(self:flags:)); + AG_SWIFT_NAME(AGSubgraphRef.intersects(self:flags:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGSubgraphIsDirty(AGSubgraphRef subgraph, AGAttributeFlags flags) CF_SWIFT_NAME(AGSubgraphRef.isDirty(self:flags:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGSubgraphIsDirty(AGSubgraphRef subgraph, AGAttributeFlags flags) AG_SWIFT_NAME(AGSubgraphRef.isDirty(self:flags:)); // MARK: Attributes -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGSubgraphRef AGGraphGetAttributeSubgraph(AGAttribute attribute) CF_SWIFT_NAME(getter:AGAttribute.subgraph(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGSubgraphRef AGGraphGetAttributeSubgraph(AGAttribute attribute) AG_SWIFT_NAME(getter:AGAttribute.subgraph(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGSubgraphRef _Nullable AGGraphGetAttributeSubgraph2(AGAttribute attribute) - CF_SWIFT_NAME(getter:AGAttribute.subgraphOrNil(self:)); + AG_SWIFT_NAME(getter:AGAttribute.subgraphOrNil(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphApply(AGSubgraphRef subgraph, uint32_t options, void (*body)(const void *context AG_SWIFT_CONTEXT, AGAttribute) AG_SWIFT_CC(swift), const void *body_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphUpdate(AGSubgraphRef subgraph, AGAttributeFlags flags) CF_SWIFT_NAME(AGSubgraphRef.update(self:flags:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphUpdate(AGSubgraphRef subgraph, AGAttributeFlags flags) AG_SWIFT_NAME(AGSubgraphRef.update(self:flags:)); // MARK: Tree -CF_EXPORT -CF_REFINED_FOR_SWIFT -_Nullable AGTreeElement AGSubgraphGetTreeRoot(AGSubgraphRef subgraph) CF_SWIFT_NAME(getter:AGSubgraphRef.treeRoot(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +_Nullable AGTreeElement AGSubgraphGetTreeRoot(AGSubgraphRef subgraph) AG_SWIFT_NAME(getter:AGSubgraphRef.treeRoot(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphBeginTreeElement(AGAttribute value, AGTypeID type, uint32_t flags); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphEndTreeElement(AGAttribute value); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphSetTreeOwner(AGSubgraphRef subgraph, AGAttribute owner) - CF_SWIFT_NAME(setter:AGSubgraphRef.treeOwner(self:_:)); + AG_SWIFT_NAME(setter:AGSubgraphRef.treeOwner(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGSubgraphAddTreeValue(AGAttribute value, AGTypeID type, const char *key, uint32_t flags); -CF_EXPORT -CF_REFINED_FOR_SWIFT -bool AGSubgraphShouldRecordTree(void) CF_SWIFT_NAME(getter:AGSubgraphRef.shouldRecordTree()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +bool AGSubgraphShouldRecordTree(void) AG_SWIFT_NAME(getter:AGSubgraphRef.shouldRecordTree()); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGSubgraphSetShouldRecordTree(void) CF_SWIFT_NAME(AGSubgraphRef.setShouldRecordTree()); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGSubgraphSetShouldRecordTree(void) AG_SWIFT_NAME(AGSubgraphRef.setShouldRecordTree()); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGSwiftSupport.h b/Sources/ComputeCxx/include/ComputeCxx/AGSwiftSupport.h deleted file mode 100644 index 187769a..0000000 --- a/Sources/ComputeCxx/include/ComputeCxx/AGSwiftSupport.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#if __has_attribute(swift_private) -# define AG_REFINED_FOR_SWIFT __attribute__((swift_private)) -#else -# define AG_REFINED_FOR_SWIFT -#endif - - -#if __has_attribute(swift_name) -# define AG_SWIFT_NAME(_name) __attribute__((swift_name(#_name))) -#else -# define AG_SWIFT_NAME(_name) -#endif - -#if __has_attribute(swift_wrapper) -#define AG_SWIFT_STRUCT __attribute__((swift_wrapper(struct))) -#else -#define AG_SWIFT_STRUCT -#endif - -// Define mappings for calling conventions. - -// Annotation for specifying a calling convention of -// a runtime function. It should be used with declarations -// of runtime functions like this: -// void runtime_function_name() AG_SWIFT_CC(swift) -#define AG_SWIFT_CC(CC) AG_SWIFT_CC_##CC - -// AG_SWIFT_CC(c) is the C calling convention. -#define AG_SWIFT_CC_c - -// AG_SWIFT_CC(swift) is the Swift calling convention. -#if __has_attribute(swiftcall) -#define AG_SWIFT_CC_swift __attribute__((swiftcall)) -#define AG_SWIFT_CONTEXT __attribute__((swift_context)) -#define AG_SWIFT_ERROR_RESULT __attribute__((swift_error_result)) -#define AG_SWIFT_INDIRECT_RESULT __attribute__((swift_indirect_result)) -#else -#define AG_SWIFT_CC_swift -#define AG_SWIFT_CONTEXT -#define AG_SWIFT_ERROR_RESULT -#define AG_SWIFT_INDIRECT_RESULT -#endif - -#if __has_attribute(swift_async_context) -#define AG_SWIFT_ASYNC_CONTEXT __attribute__((swift_async_context)) -#else -#define AG_SWIFT_ASYNC_CONTEXT -#endif diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTargetConditionals.h b/Sources/ComputeCxx/include/ComputeCxx/AGTargetConditionals.h new file mode 100644 index 0000000..4714be2 --- /dev/null +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTargetConditionals.h @@ -0,0 +1,283 @@ +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// + +/* + File: TargetConditionals.h + + Contains: Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone + + Note: TargetConditionals.h in 3.4 Universal Interfaces works + with all compilers. This header only recognizes compilers + known to run on Mac OS X. + +*/ + +#if __has_include() +#include +#else + +#ifndef __TARGETCONDITIONALS__ +#define __TARGETCONDITIONALS__ +/**************************************************************************************************** + + TARGET_CPU_* + These conditionals specify which microprocessor instruction set is being + generated. At most one of these is true, the rest are false. + + TARGET_CPU_PPC - Compiler is generating PowerPC instructions for 32-bit mode + TARGET_CPU_PPC64 - Compiler is generating PowerPC instructions for 64-bit mode + TARGET_CPU_68K - Compiler is generating 680x0 instructions + TARGET_CPU_X86 - Compiler is generating x86 instructions + TARGET_CPU_ARM - Compiler is generating ARM instructions + TARGET_CPU_MIPS - Compiler is generating MIPS instructions + TARGET_CPU_SPARC - Compiler is generating Sparc instructions + TARGET_CPU_ALPHA - Compiler is generating Dec Alpha instructions + TARGET_CPU_WASM32 - Compiler is generating WebAssembly instructions for 32-bit mode + + + TARGET_OS_* + These conditionals specify in which Operating System the generated code will + run. Indention is used to show which conditionals are evolutionary subclasses. + + The MAC/WIN32/UNIX conditionals are mutually exclusive. + The IOS/TV/WATCH conditionals are mutually exclusive. + + + TARGET_OS_WIN32 - Generated code will run under 32-bit Windows + TARGET_OS_UNIX - Generated code will run under some Unix (not OSX) + TARGET_OS_CYGWIN - Generated code will run under 64-bit Cygwin + TARGET_OS_WASI - Generated code will run under WebAssembly System Interface + TARGET_OS_MAC - Generated code will run under Mac OS X variant + TARGET_OS_IPHONE - Generated code for firmware, devices, or simulator + TARGET_OS_IOS - Generated code will run under iOS + TARGET_OS_TV - Generated code will run under Apple TV OS + TARGET_OS_WATCH - Generated code will run under Apple Watch OS + TARGET_OS_SIMULATOR - Generated code will run under a simulator + TARGET_OS_EMBEDDED - Generated code for firmware + + TARGET_IPHONE_SIMULATOR - DEPRECATED: Same as TARGET_OS_SIMULATOR + TARGET_OS_NANO - DEPRECATED: Same as TARGET_OS_WATCH + + TARGET_RT_* + These conditionals specify in which runtime the generated code will + run. This is needed when the OS and CPU support more than one runtime + (e.g. Mac OS X supports CFM and mach-o). + + TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers + TARGET_RT_BIG_ENDIAN - Generated code uses big endian format for integers + TARGET_RT_64_BIT - Generated code uses 64-bit pointers + TARGET_RT_MAC_CFM - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used + TARGET_RT_MAC_MACHO - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used + + +****************************************************************************************************/ + +#if __APPLE__ +#define TARGET_OS_DARWIN 1 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __ANDROID__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 1 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __linux__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __CYGWIN__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 1 +#define TARGET_OS_WASI 0 +#elif _WIN32 || _WIN64 +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 1 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __unix__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 1 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __wasi__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 1 +#else +#error unknown operating system +#endif + +#define TARGET_OS_WIN32 TARGET_OS_WINDOWS +#define TARGET_OS_MAC TARGET_OS_DARWIN +#define TARGET_OS_OSX TARGET_OS_DARWIN + +// iOS, watchOS, and tvOS are not supported +#define TARGET_OS_IPHONE 0 +#define TARGET_OS_IOS 0 +#define TARGET_OS_WATCH 0 +#define TARGET_OS_TV 0 + +#if __x86_64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 1 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __arm64__ || __aarch64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 1 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __mips64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 1 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __powerpc64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 1 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __i386__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 1 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __arm__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 1 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __mips__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 1 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __powerpc__ +#define TARGET_CPU_PPC 1 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __s390x__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 1 +#define TARGET_CPU_WASM32 0 +#elif __wasm32__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 1 +#else +#error unknown architecture +#endif + +#if __LITTLE_ENDIAN__ +#define TARGET_RT_LITTLE_ENDIAN 1 +#define TARGET_RT_BIG_ENDIAN 0 +#elif __BIG_ENDIAN__ +#define TARGET_RT_LITTLE_ENDIAN 0 +#define TARGET_RT_BIG_ENDIAN 1 +#else +#error unknown endian +#endif + +#if __LP64__ || __LLP64__ || __POINTER_WIDTH__-0 == 64 +#define TARGET_RT_64_BIT 1 +#else +#define TARGET_RT_64_BIT 0 +#endif + +#endif /* __TARGETCONDITIONALS__ */ + +#endif // __has_include diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTrace.h b/Sources/ComputeCxx/include/ComputeCxx/AGTrace.h index 84d4fc4..4648852 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGTrace.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTrace.h @@ -1,15 +1,14 @@ #pragma once -#include - +#include #include #include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN -typedef CF_ENUM(uint64_t, AGTraceEvents) { +typedef AG_ENUM(uint64_t, AGTraceEvents) { AGTraceEventsCustom = 1, AGTraceEventsNamed = 2, AGTraceEventsDeadline = 3, @@ -77,6 +76,6 @@ typedef struct AGTrace { void (*_Nullable compare_failed)(void *_Nullable context, AGAttribute attribute, AGComparisonState comparisonState); } AGTrace; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTraceFlags.h b/Sources/ComputeCxx/include/ComputeCxx/AGTraceFlags.h index d678e72..33bafbd 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGTraceFlags.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTraceFlags.h @@ -1,22 +1,21 @@ #pragma once -#include - +#include #include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN -typedef CF_OPTIONS(uint32_t, AGTraceFlags) { +typedef AG_OPTIONS(uint32_t, AGTraceFlags) { AGTraceFlagsEnabled = 1 << 0, AGTraceFlagsFull = 1 << 1, AGTraceFlagsBacktrace = 1 << 2, AGTraceFlagsPrepare = 1 << 3, AGTraceFlagsCustom = 1 << 4, AGTraceFlagsAll = 1 << 5, -} CF_SWIFT_NAME(AGGraphRef.TraceFlags); // TODO: what is real name +} AG_SWIFT_NAME(AGGraphRef.TraceFlags); // TODO: what is real name -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTreeElement.h b/Sources/ComputeCxx/include/ComputeCxx/AGTreeElement.h index 69e69b8..731fe1e 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGTreeElement.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTreeElement.h @@ -1,33 +1,31 @@ #pragma once -#include -#include - +#include #include #include #include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct _AGTreeElement *AGTreeElement AG_SWIFT_STRUCT AG_SWIFT_NAME(TreeElement); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTypeID AGTreeElementGetType(AGTreeElement tree_element) CF_SWIFT_NAME(getter:AGTreeElement.type(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTypeID AGTreeElementGetType(AGTreeElement tree_element) AG_SWIFT_NAME(getter:AGTreeElement.type(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGTreeElementGetValue(AGTreeElement tree_element); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint32_t AGTreeElementGetFlags(AGTreeElement tree_element) CF_SWIFT_NAME(getter:AGTreeElement.flags(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint32_t AGTreeElementGetFlags(AGTreeElement tree_element) AG_SWIFT_NAME(getter:AGTreeElement.flags(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTreeElement _Nullable AGTreeElementGetParent(AGTreeElement tree_element) CF_SWIFT_NAME(getter:AGTreeElement.parent(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTreeElement _Nullable AGTreeElementGetParent(AGTreeElement tree_element) AG_SWIFT_NAME(getter:AGTreeElement.parent(self:)); // MARK: Iterating values @@ -36,14 +34,14 @@ typedef struct AGTreeElementValueIterator { uintptr_t next_elt; } AG_SWIFT_NAME(Values) AGTreeElementValueIterator; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGTreeElementValueIterator AGTreeElementMakeValueIterator(AGTreeElement tree_element) - CF_SWIFT_NAME(getter:AGTreeElement.values(self:)); + AG_SWIFT_NAME(getter:AGTreeElement.values(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTreeValue _Nullable AGTreeElementGetNextValue(AGTreeElementValueIterator *iter) CF_SWIFT_NAME(AGTreeElementValueIterator.next(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTreeValue _Nullable AGTreeElementGetNextValue(AGTreeElementValueIterator *iter) AG_SWIFT_NAME(AGTreeElementValueIterator.next(self:)); // MARK: Iterating nodes @@ -52,13 +50,13 @@ typedef struct AGTreeElementNodeIterator { unsigned long node_index; } AG_SWIFT_NAME(Nodes) AGTreeElementNodeIterator; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGTreeElementNodeIterator AGTreeElementMakeNodeIterator(AGTreeElement tree_element) - CF_SWIFT_NAME(getter:AGTreeElement.nodes(self:)); + AG_SWIFT_NAME(getter:AGTreeElement.nodes(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGTreeElementGetNextNode(AGTreeElementNodeIterator *iter); // MARK: Iterating children @@ -69,15 +67,15 @@ typedef struct AGTreeElementChildIterator { size_t subgraph_index; } AG_SWIFT_NAME(Children) AGTreeElementChildIterator; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGTreeElementChildIterator AGTreeElementMakeChildIterator(AGTreeElement tree_element) - CF_SWIFT_NAME(getter:AGTreeElement.children(self:)); + AG_SWIFT_NAME(getter:AGTreeElement.children(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTreeElement _Nullable AGTreeElementGetNextChild(AGTreeElementChildIterator *iter) CF_SWIFT_NAME(AGTreeElementChildIterator.next(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTreeElement _Nullable AGTreeElementGetNextChild(AGTreeElementChildIterator *iter) AG_SWIFT_NAME(AGTreeElementChildIterator.next(self:)); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTreeValue.h b/Sources/ComputeCxx/include/ComputeCxx/AGTreeValue.h index 665efe3..25615c8 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGTreeValue.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTreeValue.h @@ -1,33 +1,31 @@ #pragma once -#include -#include - +#include #include #include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct _AGTreeValue *AGTreeValue AG_SWIFT_STRUCT AG_SWIFT_NAME(TreeValue); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTypeID AGTreeValueGetType(AGTreeValue tree_value) CF_SWIFT_NAME(getter:AGTreeValue.type(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTypeID AGTreeValueGetType(AGTreeValue tree_value) AG_SWIFT_NAME(getter:AGTreeValue.type(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGAttribute AGTreeValueGetValue(AGTreeValue tree_value) CF_SWIFT_NAME(getter:AGTreeValue.value(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGAttribute AGTreeValueGetValue(AGTreeValue tree_value) AG_SWIFT_NAME(getter:AGTreeValue.value(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -const char *AGTreeValueGetKey(AGTreeValue tree_value) CF_SWIFT_NAME(getter:AGTreeValue.key(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +const char *AGTreeValueGetKey(AGTreeValue tree_value) AG_SWIFT_NAME(getter:AGTreeValue.key(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint32_t AGTreeValueGetFlags(AGTreeValue tree_value) CF_SWIFT_NAME(getter:AGTreeValue.flags(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint32_t AGTreeValueGetFlags(AGTreeValue tree_value) AG_SWIFT_NAME(getter:AGTreeValue.flags(self:)); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGTuple.h b/Sources/ComputeCxx/include/ComputeCxx/AGTuple.h index e8e4903..08f04e0 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGTuple.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGTuple.h @@ -1,91 +1,89 @@ #pragma once -#include - -#include +#include #include -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN -typedef CF_ENUM(uint32_t, AGTupleCopyOptions) { +typedef AG_ENUM(uint32_t, AGTupleCopyOptions) { AGTupleCopyOptionsAssignCopy = 0, AGTupleCopyOptionsInitCopy = 1, AGTupleCopyOptionsAssignTake = 2, AGTupleCopyOptionsInitTake = 3, -} CF_SWIFT_NAME(TupleType.CopyOptions); +} AG_SWIFT_NAME(TupleType.CopyOptions); -typedef const struct AGSwiftMetadata *AGTupleType AG_SWIFT_STRUCT CF_SWIFT_NAME(TupleType); +typedef const struct AGSwiftMetadata *AGTupleType AG_SWIFT_STRUCT AG_SWIFT_NAME(TupleType); typedef struct AGUnsafeTuple { AGTupleType type; const void *value; -} CF_SWIFT_NAME(UnsafeTuple) AGUnsafeTuple; +} AG_SWIFT_NAME(UnsafeTuple) AGUnsafeTuple; typedef struct AGUnsafeMutableTuple { AGTupleType type; void *value; -} CF_SWIFT_NAME(UnsafeMutableTuple) AGUnsafeMutableTuple; +} AG_SWIFT_NAME(UnsafeMutableTuple) AGUnsafeMutableTuple; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGTupleType AGNewTupleType(size_t count, const AGTypeID _Nonnull *_Nonnull elements) - CF_SWIFT_NAME(TupleType.init(count:elements:)); + AG_SWIFT_NAME(TupleType.init(count:elements:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -size_t AGTupleCount(AGTupleType tuple_type) CF_SWIFT_NAME(getter:AGTupleType.count(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +size_t AGTupleCount(AGTupleType tuple_type) AG_SWIFT_NAME(getter:AGTupleType.count(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -size_t AGTupleSize(AGTupleType tuple_type) CF_SWIFT_NAME(getter:AGTupleType.size(self:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +size_t AGTupleSize(AGTupleType tuple_type) AG_SWIFT_NAME(getter:AGTupleType.size(self:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTypeID AGTupleElementType(AGTupleType tuple_type, size_t index) CF_SWIFT_NAME(TupleType.elementType(self:at:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTypeID AGTupleElementType(AGTupleType tuple_type, size_t index) AG_SWIFT_NAME(TupleType.elementType(self:at:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -size_t AGTupleElementSize(AGTupleType tuple_type, size_t index) CF_SWIFT_NAME(TupleType.elementSize(self:at:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +size_t AGTupleElementSize(AGTupleType tuple_type, size_t index) AG_SWIFT_NAME(TupleType.elementSize(self:at:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -size_t AGTupleElementOffset(AGTupleType tuple_type, size_t index) CF_SWIFT_NAME(TupleType.elementOffset(self:at:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +size_t AGTupleElementOffset(AGTupleType tuple_type, size_t index) AG_SWIFT_NAME(TupleType.elementOffset(self:at:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT size_t AGTupleElementOffsetChecked(AGTupleType tuple_type, size_t index, AGTypeID element_type) - CF_SWIFT_NAME(TupleType.elementOffset(self:at:type:)); + AG_SWIFT_NAME(TupleType.elementOffset(self:at:type:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void *AGTupleGetElement(AGTupleType tuple_type, void *tuple_value, size_t index, void *element_value, AGTypeID element_type, AGTupleCopyOptions options); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void *AGTupleSetElement(AGTupleType tuple_type, void *tuple_value, size_t index, const void *element_value, AGTypeID element_type, AGTupleCopyOptions options); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGTupleDestroy(AGTupleType tuple_type, void *tuple_value) CF_SWIFT_NAME(TupleType.destroy(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGTupleDestroy(AGTupleType tuple_type, void *tuple_value) AG_SWIFT_NAME(TupleType.destroy(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGTupleDestroyElement(AGTupleType tuple_type, void *tuple_value, size_t index) - CF_SWIFT_NAME(TupleType.destroy(self:_:at:)); + AG_SWIFT_NAME(TupleType.destroy(self:_:at:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGTupleWithBuffer(AGTupleType tuple_type, size_t count, void (*function)(void *context AG_SWIFT_CONTEXT, const AGUnsafeMutableTuple mutable_tuple) AG_SWIFT_CC(swift), void *context); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGType.h b/Sources/ComputeCxx/include/ComputeCxx/AGType.h index 8f2cc56..124f623 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGType.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGType.h @@ -1,14 +1,17 @@ #pragma once -#include -#include +#include -#include +#if TARGET_OS_MAC +#include +#else +#include +#endif -CF_ASSUME_NONNULL_BEGIN -CF_IMPLICIT_BRIDGING_ENABLED +AG_ASSUME_NONNULL_BEGIN +AG_IMPLICIT_BRIDGING_ENABLED -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wextern-c-compat" @@ -22,7 +25,7 @@ typedef struct AGTypeSignature { uint8_t bytes[20]; } AG_SWIFT_NAME(Signature) AGTypeSignature; -typedef CF_CLOSED_ENUM(uint32_t, AGTypeKind) { +typedef AG_CLOSED_ENUM(uint32_t, AGTypeKind) { AGTypeKindNone, AGTypeKindClass, AGTypeKindStruct, @@ -32,81 +35,87 @@ typedef CF_CLOSED_ENUM(uint32_t, AGTypeKind) { AGTypeKindFunction, AGTypeKindExistential, AGTypeKindMetatype, -} CF_SWIFT_NAME(Metadata.Kind); +} AG_SWIFT_NAME(Metadata.Kind); -CF_EXPORT -CF_REFINED_FOR_SWIFT +#if TARGET_OS_MAC +AG_EXPORT +AG_REFINED_FOR_SWIFT CFStringRef AGTypeDescription(AGTypeID typeID); - -CF_EXPORT -CF_REFINED_FOR_SWIFT -AGTypeKind AGTypeGetKind(AGTypeID typeID) CF_SWIFT_NAME(getter:Metadata.kind(self:)); - -CF_EXPORT -CF_REFINED_FOR_SWIFT -const AGTypeSignature AGTypeGetSignature(AGTypeID typeID) CF_SWIFT_NAME(getter:Metadata.signature(self:)); - -CF_EXPORT -CF_REFINED_FOR_SWIFT -const void *_Nullable AGTypeGetDescriptor(AGTypeID typeID) CF_SWIFT_NAME(getter:Metadata.descriptor(self:)); - -CF_EXPORT -CF_REFINED_FOR_SWIFT -const void *_Nullable AGTypeNominalDescriptor(AGTypeID typeID) CF_SWIFT_NAME(getter:Metadata.nominalDescriptor(self:)); - -CF_EXPORT -CF_REFINED_FOR_SWIFT +#else +AG_EXPORT +AG_REFINED_FOR_SWIFT +CFStringRef AGTypeCopyDescription(AGTypeID typeID); +#endif + +AG_EXPORT +AG_REFINED_FOR_SWIFT +AGTypeKind AGTypeGetKind(AGTypeID typeID) AG_SWIFT_NAME(getter:Metadata.kind(self:)); + +AG_EXPORT +AG_REFINED_FOR_SWIFT +const AGTypeSignature AGTypeGetSignature(AGTypeID typeID) AG_SWIFT_NAME(getter:Metadata.signature(self:)); + +AG_EXPORT +AG_REFINED_FOR_SWIFT +const void *_Nullable AGTypeGetDescriptor(AGTypeID typeID) AG_SWIFT_NAME(getter:Metadata.descriptor(self:)); + +AG_EXPORT +AG_REFINED_FOR_SWIFT +const void *_Nullable AGTypeNominalDescriptor(AGTypeID typeID) AG_SWIFT_NAME(getter:Metadata.nominalDescriptor(self:)); + +AG_EXPORT +AG_REFINED_FOR_SWIFT const char *_Nullable AGTypeNominalDescriptorName(AGTypeID typeID) - CF_SWIFT_NAME(getter:Metadata.nominalDescriptorName(self:)); + AG_SWIFT_NAME(getter:Metadata.nominalDescriptorName(self:)); -typedef CF_OPTIONS(uint32_t, AGTypeApplyOptions) { +typedef AG_OPTIONS(uint32_t, AGTypeApplyOptions) { AGTypeApplyOptionsEnumerateStructFields = 0, AGTypeApplyOptionsEnumerateClassFields = 1 << 0, AGTypeApplyOptionsContinueAfterUnknownField = 1 << 1, AGTypeApplyOptionsEnumerateEnumCases = 1 << 2, -} CF_SWIFT_NAME(Metadata.ApplyOptions); +} AG_SWIFT_NAME(Metadata.ApplyOptions); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT void AGTypeApplyFields(AGTypeID typeID, void (*apply)(const void *_Nullable context AG_SWIFT_CONTEXT, const char *field_name, size_t field_offset, AGTypeID field_type) AG_SWIFT_CC(swift), const void *apply_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGTypeApplyFields2(AGTypeID typeID, AGTypeApplyOptions options, bool (*_Nonnull apply)(const void *context AG_SWIFT_CONTEXT, const char *field_name, size_t field_offset, AGTypeID field_type) AG_SWIFT_CC(swift), const void *apply_context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGTypeApplyEnumData(AGTypeID typeID, void *value, void (*body)(void *context AG_SWIFT_CONTEXT, uint32_t tag, AGTypeID field_type, const void *field_value) AG_SWIFT_CC(swift), void *context); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT bool AGTypeApplyMutableEnumData(AGTypeID typeID, void *value, void (*body)(void *context AG_SWIFT_CONTEXT, uint32_t tag, AGTypeID field_type, void *field_value) AG_SWIFT_CC(swift), void *context); -CF_EXPORT -CF_REFINED_FOR_SWIFT -uint64_t AGTypeGetEnumTag(AGTypeID typeID, const void *value) CF_SWIFT_NAME(AGTypeID.enumTag(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +uint64_t AGTypeGetEnumTag(AGTypeID typeID, const void *value) AG_SWIFT_NAME(AGTypeID.enumTag(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGTypeProjectEnumData(AGTypeID typeID, void *value) CF_SWIFT_NAME(AGTypeID.projectEnumData(self:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGTypeProjectEnumData(AGTypeID typeID, void *value) AG_SWIFT_NAME(AGTypeID.projectEnumData(self:_:)); -CF_EXPORT -CF_REFINED_FOR_SWIFT -void AGTypeInjectEnumTag(AGTypeID typeID, uint32_t tag, void *value) CF_SWIFT_NAME(AGTypeID.injectEnumTag(self:tag:_:)); +AG_EXPORT +AG_REFINED_FOR_SWIFT +void AGTypeInjectEnumTag(AGTypeID typeID, uint32_t tag, void *value) AG_SWIFT_NAME(AGTypeID.injectEnumTag(self:tag:_:)); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_IMPLICIT_BRIDGING_DISABLED -CF_ASSUME_NONNULL_END +AG_IMPLICIT_BRIDGING_DISABLED +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGUniqueID.h b/Sources/ComputeCxx/include/ComputeCxx/AGUniqueID.h index 07ffcff..6cd0c88 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGUniqueID.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGUniqueID.h @@ -1,16 +1,15 @@ #pragma once -#include -#include +#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef long AGUniqueID; -AGUniqueID AGMakeUniqueID(void) CF_SWIFT_NAME(makeUniqueID()); +AGUniqueID AGMakeUniqueID(void) AG_SWIFT_NAME(makeUniqueID()); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGValue.h b/Sources/ComputeCxx/include/ComputeCxx/AGValue.h index e370c04..79cd527 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGValue.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGValue.h @@ -1,14 +1,12 @@ #pragma once -#include +#include -#include +AG_ASSUME_NONNULL_BEGIN -CF_ASSUME_NONNULL_BEGIN +AG_EXTERN_C_BEGIN -CF_EXTERN_C_BEGIN - -typedef CF_OPTIONS(uint32_t, AGValueOptions) { +typedef AG_OPTIONS(uint32_t, AGValueOptions) { AGValueOptionsNone = 0, AGValueOptionsInputOptionsUnprefetched = 1 << 0, AGValueOptionsInputOptionsSyncMainRef = 1 << 1, @@ -17,7 +15,7 @@ typedef CF_OPTIONS(uint32_t, AGValueOptions) { AGValueOptionsIncrementGraphVersion = 1 << 2, // AsTopLevelOutput }; -typedef CF_OPTIONS(uint8_t, AGValueState) { +typedef AG_OPTIONS(uint8_t, AGValueState) { AGValueStateNone = 0, AGValueStateDirty = 1 << 0, AGValueStatePending = 1 << 1, @@ -29,6 +27,6 @@ typedef CF_OPTIONS(uint8_t, AGValueState) { AGValueStateSelfModified = 1 << 7, }; -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/AGWeakAttribute.h b/Sources/ComputeCxx/include/ComputeCxx/AGWeakAttribute.h index 1d742cd..9e6c01c 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/AGWeakAttribute.h +++ b/Sources/ComputeCxx/include/ComputeCxx/AGWeakAttribute.h @@ -1,30 +1,27 @@ #pragma once -#include -#include - +#include #include -#include -CF_ASSUME_NONNULL_BEGIN +AG_ASSUME_NONNULL_BEGIN -CF_EXTERN_C_BEGIN +AG_EXTERN_C_BEGIN typedef struct AGWeakAttribute { struct { AGAttribute identifier; uint32_t seed; } _details; -} CF_SWIFT_NAME(AnyWeakAttribute) AGWeakAttribute; +} AG_SWIFT_NAME(AnyWeakAttribute) AGWeakAttribute; -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGWeakAttribute AGCreateWeakAttribute(AGAttribute attribute); -CF_EXPORT -CF_REFINED_FOR_SWIFT +AG_EXPORT +AG_REFINED_FOR_SWIFT AGAttribute AGWeakAttributeGetAttribute(AGWeakAttribute attribute); -CF_EXTERN_C_END +AG_EXTERN_C_END -CF_ASSUME_NONNULL_END +AG_ASSUME_NONNULL_END diff --git a/Sources/ComputeCxx/include/ComputeCxx/ComputeCxx.h b/Sources/ComputeCxx/include/ComputeCxx/ComputeCxx.h index cb036e3..b301762 100644 --- a/Sources/ComputeCxx/include/ComputeCxx/ComputeCxx.h +++ b/Sources/ComputeCxx/include/ComputeCxx/ComputeCxx.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/Sources/ComputeCxx/internalInclude/CoreFoundationPrivate/CFRuntime.h b/Sources/ComputeCxx/internalInclude/CoreFoundationPrivate/CFRuntime.h new file mode 100644 index 0000000..adace9e --- /dev/null +++ b/Sources/ComputeCxx/internalInclude/CoreFoundationPrivate/CFRuntime.h @@ -0,0 +1,286 @@ +#include "ComputeCxx/AGTargetConditionals.h" + +#if TARGET_OS_MAC + +/* CFRuntime.h + Copyright (c) 1999-2019, Apple Inc. All rights reserved. + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFRUNTIME__) +#define __COREFOUNDATION_CFRUNTIME__ 1 + +#include +#include +#include + +#if __has_include() +#include +#endif + +#ifndef __ptrauth_cf_objc_isa_pointer +#define __ptrauth_cf_objc_isa_pointer +#endif + +#ifndef __ptrauth_objc_isa_pointer +#define __ptrauth_objc_isa_pointer +#endif + +CF_EXTERN_C_BEGIN + +#if (TARGET_OS_MAC && !TARGET_OS_IPHONE && !__x86_64h__) + +// Although we no longer support GC, we leave exported symbols in place for now to avoid any lockstep dependency issues. +CF_EXPORT bool kCFUseCollectableAllocator; +CF_EXPORT bool (*__CFObjCIsCollectable)(void *); + +#else + +#define kCFUseCollectableAllocator 0 +#define __CFObjCIsCollectable 0 + +#endif + + +CF_INLINE Boolean _CFAllocatorIsSystemDefault(CFAllocatorRef allocator) { + if (allocator == kCFAllocatorSystemDefault) return true; + if (NULL == allocator || kCFAllocatorDefault == allocator) { + return (kCFAllocatorSystemDefault == CFAllocatorGetDefault()); + } + return false; +} + +#define CF_USING_COLLECTABLE_MEMORY 0 +#define CF_IS_COLLECTABLE_ALLOCATOR(allocator) (0 && allocator) // prevent allocator from being claimed to be un-used +#define CF_IS_COLLECTABLE(obj) (0 && obj) // prevent obj from being claimed to be un-used + +enum { + _kCFRuntimeNotATypeID = 0 +}; + +enum { // Version field constants + _kCFRuntimeScannedObject = (1UL << 0), + _kCFRuntimeResourcefulObject = (1UL << 2), // tells CFRuntime to make use of the reclaim field + _kCFRuntimeCustomRefCount = (1UL << 3), // tells CFRuntime to make use of the refcount field + _kCFRuntimeRequiresAlignment = (1UL << 4), // tells CFRuntime to make use of the requiredAlignment field +}; + +typedef struct __CFRuntimeClass { + CFIndex version; + const char *className; // must be a pure ASCII string, nul-terminated + void (*init)(CFTypeRef cf); + CFTypeRef (*copy)(CFAllocatorRef allocator, CFTypeRef cf); + void (*finalize)(CFTypeRef cf); + Boolean (*equal)(CFTypeRef cf1, CFTypeRef cf2); + CFHashCode (*hash)(CFTypeRef cf); + CFStringRef (*copyFormattingDesc)(CFTypeRef cf, CFDictionaryRef formatOptions); // return str with retain + CFStringRef (*copyDebugDesc)(CFTypeRef cf); // return str with retain + +#define CF_RECLAIM_AVAILABLE 1 + void (*reclaim)(CFTypeRef cf); // Or in _kCFRuntimeResourcefulObject in the .version to indicate this field should be used + +#define CF_REFCOUNT_AVAILABLE 1 + uint32_t (*refcount)(intptr_t op, CFTypeRef cf); // Or in _kCFRuntimeCustomRefCount in the .version to indicate this field should be used + // this field must be non-NULL when _kCFRuntimeCustomRefCount is in the .version field + // - if the callback is passed 1 in 'op' it should increment the 'cf's reference count and return 0 + // - if the callback is passed 0 in 'op' it should return the 'cf's reference count, up to 32 bits + // - if the callback is passed -1 in 'op' it should decrement the 'cf's reference count; if it is now zero, 'cf' should be cleaned up and deallocated; then return 0 + // remember to use saturation arithmetic logic and stop incrementing and decrementing when the ref count hits UINT32_MAX, or you will have a security bug + // remember that reference count incrementing/decrementing must be done thread-safely/atomically + // objects should be created/initialized with a custom ref-count of 1 by the class creation functions + // do not attempt to use any bits within the CFRuntimeBase for your reference count; store that in some additional field in your CF object + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#define CF_REQUIRED_ALIGNMENT_AVAILABLE 1 + uintptr_t requiredAlignment; // Or in _kCFRuntimeRequiresAlignment in the .version field to indicate this field should be used; the allocator to _CFRuntimeCreateInstance() will be ignored in this case; if this is less than the minimum alignment the system supports, you'll get higher alignment; if this is not an alignment the system supports (e.g., most systems will only support powers of two, or if it is too high), the result (consequences) will be up to CF or the system to decide + +} CFRuntimeClass; + +#define RADAR_5115468_FIXED 1 + +/* Note that CF runtime class registration and unregistration is not currently + * thread-safe, which should not currently be a problem, as long as unregistration + * is done only when valid to do so. + */ + +CF_EXPORT CFTypeID _CFRuntimeRegisterClass(const CFRuntimeClass * const cls); + /* Registers a new class with the CF runtime. Pass in a + * pointer to a CFRuntimeClass structure. The pointer is + * remembered by the CF runtime -- the structure is NOT + * copied. + * + * - version field must be zero currently. + * - className field points to a null-terminated C string + * containing only ASCII (0 - 127) characters; this field + * may NOT be NULL. + * - init field points to a function which classes can use to + * apply some generic initialization to instances as they + * are created; this function is called by both + * _CFRuntimeCreateInstance and _CFRuntimeInitInstance; if + * this field is NULL, no function is called; the instance + * has been initialized enough that the polymorphic funcs + * CFGetTypeID(), CFRetain(), CFRelease(), CFGetRetainCount(), + * and CFGetAllocator() are valid on it when the init + * function if any is called. + * - copy field should always be NULL. Generic copying of CF + * objects has never been defined (and is unlikely). + * - finalize field points to a function which destroys an + * instance when the retain count has fallen to zero; if + * this is NULL, finalization does nothing. Note that if + * the class-specific functions which create or initialize + * instances more fully decide that a half-initialized + * instance must be destroyed, the finalize function for + * that class has to be able to deal with half-initialized + * instances. The finalize function should NOT destroy the + * memory for the instance itself; that is done by the + * CF runtime after this finalize callout returns. + * - equal field points to an equality-testing function; this + * field may be NULL, in which case only pointer/reference + * equality is performed on instances of this class. + * Pointer equality is tested, and the type IDs are checked + * for equality, before this function is called (so, the + * two instances are not pointer-equal but are of the same + * class before this function is called). + * NOTE: the equal function must implement an immutable + * equality relation, satisfying the reflexive, symmetric, + * and transitive properties, and remains the same across + * time and immutable operations (that is, if equal(A,B) at + * some point, then later equal(A,B) provided neither + * A or B has been mutated). + * - hash field points to a hash-code-computing function for + * instances of this class; this field may be NULL in which + * case the pointer value of an instance is converted into + * a hash. + * NOTE: the hash function and equal function must satisfy + * the relationship "equal(A,B) implies hash(A) == hash(B)"; + * that is, if two instances are equal, their hash codes must + * be equal too. (However, the converse is not true!) + * - copyFormattingDesc field points to a function returning a + * CFStringRef with a human-readable description of the + * instance; if this is NULL, the type does not have special + * human-readable string-formats. + * - copyDebugDesc field points to a function returning a + * CFStringRef with a debugging description of the instance; + * if this is NULL, a simple description is generated. + * + * This function returns _kCFRuntimeNotATypeID on failure, or + * on success, returns the CFTypeID for the new class. This + * CFTypeID is what the class uses to allocate or initialize + * instances of the class. It is also returned from the + * conventional *GetTypeID() function, which returns the + * class's CFTypeID so that clients can compare the + * CFTypeID of instances with that of a class. + * + * The function to compute a human-readable string is very + * optional, and is really only interesting for classes, + * like strings or numbers, where it makes sense to format + * the instance using just its contents. + */ + +CF_EXPORT const CFRuntimeClass * _CFRuntimeGetClassWithTypeID(CFTypeID typeID); + /* Returns the pointer to the CFRuntimeClass which was + * assigned the specified CFTypeID. + */ + +CF_EXPORT void _CFRuntimeUnregisterClassWithTypeID(CFTypeID typeID); + /* Unregisters the class with the given type ID. It is + * undefined whether type IDs are reused or not (expect + * that they will be). + * + * Whether or not unregistering the class is a good idea or + * not is not CF's responsibility. In particular you must + * be quite sure all instances are gone, and there are no + * valid weak refs to such in other threads. + */ + +/* All CF "instances" start with this structure. Never refer to + * these fields directly -- they are for CF's use and may be added + * to or removed or change format without warning. Binary + * compatibility for uses of this struct is not guaranteed from + * release to release. + */ +#if DEPLOYMENT_RUNTIME_SWIFT + +typedef struct __attribute__((__aligned__(8))) __CFRuntimeBase { + // This matches the isa and retain count storage in Swift + __ptrauth_cf_objc_isa_pointer uintptr_t _cfisa; + uintptr_t _swift_rc; + // This is for CF's use, and must match __NSCFType/_CFInfo layout + _Atomic(uint64_t) _cfinfoa; +} CFRuntimeBase; + +#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0x0000000000000080ULL} + +#else +typedef struct __CFRuntimeBase { + __ptrauth_cf_objc_isa_pointer uintptr_t _cfisa; +#if defined(__LP64__) || defined(__LLP64__) + _Atomic(uint64_t) _cfinfoa; +#else + _Atomic(uint32_t) _cfinfoa; +#endif +} CFRuntimeBase; + +#if TARGET_RT_64_BIT +#define INIT_CFRUNTIME_BASE(...) {0, 0x0000000000000080ULL} +#else +#define INIT_CFRUNTIME_BASE(...) {0, 0x00000080UL} +#endif + +#endif + +CF_EXPORT CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CFIndex extraBytes, unsigned char *category); + /* Creates a new CF instance of the class specified by the + * given CFTypeID, using the given allocator, and returns it. + * If the allocator returns NULL, this function returns NULL. + * A CFRuntimeBase structure is initialized at the beginning + * of the returned instance. extraBytes is the additional + * number of bytes to allocate for the instance (BEYOND that + * needed for the CFRuntimeBase). If the specified CFTypeID + * is unknown to the CF runtime, this function returns NULL. + * The base header is initialized and the extra bytes if + * requested will be zeroed. + * All instances created with this function must be destroyed + * only through use of the CFRelease() function -- instances + * must not be destroyed by using CFAllocatorDeallocate() + * directly, even in the initialization or creation functions + * of a class. Pass NULL for the category parameter. + */ + +CF_EXPORT void _CFRuntimeSetInstanceTypeID(CFTypeRef cf, CFTypeID typeID); + /* This function changes the typeID of the given instance. + * If the specified CFTypeID is unknown to the CF runtime, + * this function does nothing. This function CANNOT be used + * to initialize an instance. It is for advanced usages such + * as faulting. You cannot change the CFTypeID of an object + * of a _kCFRuntimeCustomRefCount class, or to a + * _kCFRuntimeCustomRefCount class. + */ + +#if DEPLOYMENT_RUNTIME_SWIFT +#else +CF_EXPORT void _CFRuntimeInitStaticInstance(void *memory, CFTypeID typeID); + /* This function initializes a memory block to be a constant + * (unreleaseable) CF object of the given typeID. + * If the specified CFTypeID is unknown to the CF runtime, + * this function does nothing. The memory block should + * be a chunk of in-binary writeable static memory, and at + * least as large as sizeof(CFRuntimeBase) on the platform + * the code is being compiled for. The init function of the + * CFRuntimeClass is invoked on the memory as well, if the + * class has one. Static instances cannot be initialized to + * _kCFRuntimeCustomRefCount classes. + */ +#define CF_HAS_INIT_STATIC_INSTANCE 1 +#endif + +CF_EXTERN_C_END + +#endif /* ! __COREFOUNDATION_CFRUNTIME__ */ + +#endif diff --git a/Sources/ComputeCxx/Swift/mach-o/MachOFile.cpp b/Sources/Platform/MachOFile.cpp similarity index 99% rename from Sources/ComputeCxx/Swift/mach-o/MachOFile.cpp rename to Sources/Platform/MachOFile.cpp index 856aa79..942c0fa 100644 --- a/Sources/ComputeCxx/Swift/mach-o/MachOFile.cpp +++ b/Sources/Platform/MachOFile.cpp @@ -1,5 +1,7 @@ #include "MachOFile.h" +#if __APPLE__ + #include bool MachOFile::hasMachOMagic() const { return magic == MH_MAGIC || magic == MH_MAGIC_64; } @@ -58,3 +60,5 @@ void MachOFile::forEachLoadCommand(/* Diagnostics& diag, */ void (^callback)(con cmd = nextCmd; } } + +#endif diff --git a/Sources/ComputeCxx/Swift/mach-o/MachOFile.h b/Sources/Platform/MachOFile.h similarity index 94% rename from Sources/ComputeCxx/Swift/mach-o/MachOFile.h rename to Sources/Platform/MachOFile.h index a90a2ad..f389b12 100644 --- a/Sources/ComputeCxx/Swift/mach-o/MachOFile.h +++ b/Sources/Platform/MachOFile.h @@ -1,5 +1,7 @@ #pragma once +#if __APPLE__ + #include #include @@ -13,3 +15,5 @@ struct MachOFile : mach_header { bool hasMachOBigEndianMagic() const; void forEachLoadCommand(/* Diagnostics &diag, */ void (^callback)(const load_command *cmd, bool &stop)) const; }; + +#endif diff --git a/Sources/Platform/image.cpp b/Sources/Platform/image.cpp new file mode 100644 index 0000000..06e103b --- /dev/null +++ b/Sources/Platform/image.cpp @@ -0,0 +1,34 @@ +#include "platform/image.h" + +#if __APPLE__ +#include + +#include "MachOFile.h" +#endif + +#include + +void platform_image_infos_for_addresses(unsigned count, const void *_Nonnull addresses[_Nonnull], + platform_image_info_t infos[_Nonnull]) { + for (unsigned i = 0; i < count; i++) { + const void *addr = addresses[i]; + bzero(&infos[i], sizeof(platform_image_info_t)); + +#if __APPLE__ + Dl_info dl_info; + if (dladdr(addr, &dl_info)) { + // infos[i].image = (mach_header *)dl_info.dli_fbase; + infos[i].offset = (uintptr_t)addr - (uintptr_t)dl_info.dli_fbase; + + const MachOFile *mf = (MachOFile *)dl_info.dli_fbase; + if (mf->hasMachOMagic()) { + mf->getUuid(infos[i].identifier); + } else { + bzero(infos[i].identifier, sizeof(uuid_t)); + } + } +#else + // TODO +#endif + } +} diff --git a/Sources/Platform/include/module.modulemap b/Sources/Platform/include/module.modulemap new file mode 100644 index 0000000..a949e25 --- /dev/null +++ b/Sources/Platform/include/module.modulemap @@ -0,0 +1,3 @@ +module Platform { + header "platform/platform.h" +} diff --git a/Sources/Platform/include/platform/base.h b/Sources/Platform/include/platform/base.h new file mode 100644 index 0000000..37d92ed --- /dev/null +++ b/Sources/Platform/include/platform/base.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include +#include + +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +#if !defined(PLATFORM_EXTERN_C_BEGIN) +#if defined(__cplusplus) +#define PLATFORM_EXTERN_C_BEGIN extern "C" { +#define PLATFORM_EXTERN_C_END } +#else +#define PLATFORM_EXTERN_C_BEGIN +#define PLATFORM_EXTERN_C_END +#endif +#endif + +#if __GNUC__ +#define PLATFORM_EXPORT extern __attribute__((__visibility__("default"))) +#else +#define PLATFORM_EXPORT extern +#endif + +#if __GNUC__ +#define PLATFORM_INLINE static __inline__ +#else +#define PLATFORM_INLINE static inline +#endif + +#if __has_feature(assume_nonnull) +#define PLATFORM_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define PLATFORM_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define PLATFORM_ASSUME_NONNULL_BEGIN +#define PLATFORM_ASSUME_NONNULL_END +#endif + +#if !__has_feature(nullability) +#ifndef _Nullable +#define _Nullable +#endif +#ifndef _Nonnull +#define _Nonnull +#endif +#ifndef _Null_unspecified +#define _Null_unspecified +#endif +#endif + +#if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \ + __has_extension(cxx_strong_enums) +#define PLATFORM_ENUM(_name, _type, ...) \ + typedef enum : _type { __VA_ARGS__ } _name##_t +#else +#define PLATFORM_ENUM(_name, _type, ...) \ + typedef _type _name##_t; enum { __VA_ARGS__ } +#endif diff --git a/Sources/Platform/include/platform/image.h b/Sources/Platform/include/platform/image.h new file mode 100644 index 0000000..73a8f4f --- /dev/null +++ b/Sources/Platform/include/platform/image.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +PLATFORM_ASSUME_NONNULL_BEGIN +PLATFORM_EXTERN_C_BEGIN + +#define PLATFORM_IMAGE_INFO_IDENTIFIER_LENGTH 16 + +typedef struct _platform_image_info { + unsigned char identifier[PLATFORM_IMAGE_INFO_IDENTIFIER_LENGTH]; + uint64_t offset; +} platform_image_info_t; + +PLATFORM_EXPORT +void platform_image_infos_for_addresses(unsigned count, const void *_Nonnull addresses[_Nonnull], + platform_image_info_t infos[_Nonnull]); + +PLATFORM_EXTERN_C_END +PLATFORM_ASSUME_NONNULL_END diff --git a/Sources/Platform/include/platform/lock.h b/Sources/Platform/include/platform/lock.h new file mode 100644 index 0000000..8e44455 --- /dev/null +++ b/Sources/Platform/include/platform/lock.h @@ -0,0 +1,27 @@ +#pragma once + +#if __APPLE__ + +#include + +typedef os_unfair_lock platform_lock; + +#define PLATFORM_LOCK_INIT ((os_unfair_lock)OS_UNFAIR_LOCK_INIT) + +#define platform_lock_lock(LP) ({ (void)os_unfair_lock_lock(LP); }) +#define platform_lock_unlock(LP) ({ (void)os_unfair_lock_unlock(LP); }) +#define platform_lock_trylock(LP) ({ os_unfair_lock_trylock(LP); }) + +#else + +#include + +typedef pthread_mutex_t platform_lock; + +#define PLATFORM_LOCK_INIT ((pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER) + +#define platform_lock_lock(LP) ({ (void)pthread_mutex_lock(LP); }) +#define platform_lock_unlock(LP) ({ (void)pthread_mutex_unlock(LP); }) +#define platform_lock_trylock(LP) ({ pthread_mutex_trylock(LP) == 0; }) + +#endif diff --git a/Sources/Platform/include/platform/log.h b/Sources/Platform/include/platform/log.h new file mode 100644 index 0000000..87526fe --- /dev/null +++ b/Sources/Platform/include/platform/log.h @@ -0,0 +1,55 @@ +#pragma once + +#if __APPLE__ +#include +#else +#include +#endif + +#include + +PLATFORM_ASSUME_NONNULL_BEGIN +PLATFORM_EXTERN_C_BEGIN + +#if __APPLE__ + +typedef os_log_t platform_log_t; + +#define platform_log_create(subsystem, category) ({ (platform_log_t)os_log_create(subsystem, category); }) + +#define platform_log_info(log, format, ...) ({ (void)os_log_info(log, format, ##__VA_ARGS__); }) +#define platform_log_error(log, format, ...) ({ (void)os_log_error(log, format, ##__VA_ARGS__); }) +#define platform_log_fault(log, format, ...) ({ (void)os_log_fault(log, format, ##__VA_ARGS__); }) + +#else + +typedef struct platform_log_s *platform_log_t; + +PLATFORM_ENUM(platform_log_type, uint8_t, + PLATFORM_LOG_TYPE_DEFAULT = 0x00, + PLATFORM_LOG_TYPE_INFO = 0x01, + PLATFORM_LOG_TYPE_DEBUG = 0x02, + PLATFORM_LOG_TYPE_ERROR = 0x10, + PLATFORM_LOG_TYPE_FAULT = 0x11, +); + +PLATFORM_EXPORT +platform_log_t platform_log_create(const char *subsystem, const char *category); + +#define platform_log_info(log, format, ...) \ + _platform_log_impl(log, PLATFORM_LOG_TYPE_INFO, (format), ##__VA_ARGS__) + +#define platform_log_error(log, format, ...) \ + _platform_log_impl(log, PLATFORM_LOG_TYPE_ERROR, (format), ##__VA_ARGS__) + +#define platform_log_fault(log, format, ...) \ + _platform_log_impl(log, PLATFORM_LOG_TYPE_FAULT, (format), ##__VA_ARGS__) + +PLATFORM_EXPORT +void _platform_log_impl(platform_log_t log, platform_log_type_t type, + const char *format, ...); + +#endif + +PLATFORM_EXTERN_C_END +PLATFORM_ASSUME_NONNULL_END diff --git a/Sources/Platform/include/platform/malloc.h b/Sources/Platform/include/platform/malloc.h new file mode 100644 index 0000000..989baa7 --- /dev/null +++ b/Sources/Platform/include/platform/malloc.h @@ -0,0 +1,24 @@ +#pragma once + +#if __APPLE__ +#include +#else + +#include + +typedef int malloc_zone_t; + +#define malloc_zone_malloc(zone,size) malloc(size) +#define malloc_zone_memalign(zone,align,size) malloc(size) +#define malloc_zone_calloc(zone,count,size) calloc(count,size) +#define malloc_zone_realloc(zone,ptr,size) realloc(ptr,size) +#define malloc_zone_free(zone,ptr) free(ptr) + +#define malloc_size(ptr) malloc_usable_size(ptr) +#define malloc_good_size(size) (size) + +#define malloc_create_zone(a,b) ((malloc_zone_t *)NULL) +#define malloc_destroy_zone(zone) +#define malloc_set_zone_name(zone,name) + +#endif diff --git a/Sources/Platform/include/platform/once.h b/Sources/Platform/include/platform/once.h new file mode 100644 index 0000000..ea27dbd --- /dev/null +++ b/Sources/Platform/include/platform/once.h @@ -0,0 +1,42 @@ +#pragma once + +#if __APPLE__ +#include +#else +#include +#endif + +#include + +PLATFORM_ASSUME_NONNULL_BEGIN +PLATFORM_EXTERN_C_BEGIN + +#if __APPLE__ + +typedef dispatch_once_t platform_once_t; +typedef void (*platform_once_function_t)(void); + +PLATFORM_INLINE +void _platform_once_thunk(void *_Nullable context) { + ((dispatch_function_t)context)(NULL); +} + +PLATFORM_INLINE +void platform_once(platform_once_t *predicate, platform_once_function_t function) { + dispatch_once_f(predicate, (void *)function, _platform_once_thunk); +} + +#else + +typedef pthread_once_t platform_once_t; +typedef void (*platform_once_function_t)(void); + +PLATFORM_INLINE +void platform_once(platform_once_t *predicate, platform_once_function_t function) { + pthread_once(predicate, function); +} + +#endif + +PLATFORM_EXTERN_C_END +PLATFORM_ASSUME_NONNULL_END diff --git a/Sources/Platform/include/platform/platform.h b/Sources/Platform/include/platform/platform.h new file mode 100644 index 0000000..ac9981d --- /dev/null +++ b/Sources/Platform/include/platform/platform.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/Sources/Platform/include/platform/sha.h b/Sources/Platform/include/platform/sha.h new file mode 100644 index 0000000..c40b61b --- /dev/null +++ b/Sources/Platform/include/platform/sha.h @@ -0,0 +1,25 @@ +#pragma once + +#if __APPLE__ + +#include + +typedef CC_SHA1_CTX PLATFORM_SHA1_CTX; + +#define PLATFORM_SHA1_Init CC_SHA1_Init +#define PLATFORM_SHA1_Update CC_SHA1_Update +#define PLATFORM_SHA1_Final CC_SHA1_Final +#define PLATFORM_SHA1_DIGEST_LENGTH CC_SHA1_DIGEST_LENGTH + +#else + +#include + +typedef SHA_CTX PLATFORM_SHA1_CTX; + +#define PLATFORM_SHA1_Init SHA1_Init +#define PLATFORM_SHA1_Update SHA1_Update +#define PLATFORM_SHA1_Final SHA1_Final +#define PLATFORM_SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH + +#endif diff --git a/Sources/Platform/include/platform/time.h b/Sources/Platform/include/platform/time.h new file mode 100644 index 0000000..9f0ec79 --- /dev/null +++ b/Sources/Platform/include/platform/time.h @@ -0,0 +1,36 @@ +#pragma once + +#if __APPLE__ + +#include + +typedef dispatch_time_t platform_time_t; + +#define platform_absolute_time() mach_absolute_time() + +#else + +#include +#include + +typedef uint64_t platform_time_t; + +#define platform_absolute_time() ({ \ + struct timespec ts; \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + (uint64_t)ts.tv_nsec + (uint64_t)ts.tv_sec * 1000000000UL; \ +}) + +#endif + +//PLATFORM_INLINE +//uint64_t platform_absolute_time() { +//#if TARGET_OS_MAC +// +// ULONGLONG ullTime; +// QueryUnbiasedInterruptTimePrecise(&ullTime); +// return ullTime; +//#elif TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_MAC || TARGET_OS_WASI + +//#endif +//} diff --git a/Sources/Platform/include/platform/vm.h b/Sources/Platform/include/platform/vm.h new file mode 100644 index 0000000..8b5dd03 --- /dev/null +++ b/Sources/Platform/include/platform/vm.h @@ -0,0 +1,19 @@ +#pragma once + +#if __APPLE__ +#endif + +#include + +PLATFORM_ASSUME_NONNULL_BEGIN +PLATFORM_EXTERN_C_BEGIN + +#if __APPLE__ +#else +typedef uintptr_t vm_offset_t; +typedef uintptr_t vm_size_t; +typedef vm_offset_t vm_address_t; +#endif + +PLATFORM_EXTERN_C_END +PLATFORM_ASSUME_NONNULL_END diff --git a/Sources/Platform/log.c b/Sources/Platform/log.c new file mode 100644 index 0000000..6f1bac1 --- /dev/null +++ b/Sources/Platform/log.c @@ -0,0 +1,64 @@ +#include "platform/log.h" + +#if !TARGET_OS_MAC + +#include +#include +#include +#include + +struct platform_log_s { + char *subsystem; + char *category; +}; + +platform_log_t platform_log_create(const char *subsystem, const char *category) { + platform_log_t log = malloc(sizeof(struct platform_log_s)); + if (subsystem) { + log->subsystem = strdup(subsystem); + } else { + log->subsystem = NULL; + } + if (category) { + log->category = strdup(category); + } else { + log->category = NULL; + } + return log; +} + +void platform_log_destroy(platform_log_t log) { + if (log) { + if (log->subsystem) { + free(log->subsystem); + } + if (log->category) { + free(log->category); + } + free(log); + } +} + +void _platform_log_impl(platform_log_t log, platform_log_type_t type, const char *format, ...) { + char *message = NULL; + + va_list args; + va_start(args, format); + vasprintf(&message, format, args); + va_end(args); + + if (message) { + openlog(log->subsystem, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); + if (type >= PLATFORM_LOG_TYPE_FAULT) { + syslog(LOG_CRIT, "%s", message); + } else if (type >= PLATFORM_LOG_TYPE_ERROR) { + syslog(LOG_ERR, "%s", message); + } else { + syslog(LOG_INFO, "%s", message); + } + closelog(); + free(message); + } +} + +#endif diff --git a/Sources/SwiftCorelibsCoreFoundation/empty.c b/Sources/SwiftCorelibsCoreFoundation/empty.c new file mode 100644 index 0000000..223a194 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/empty.c @@ -0,0 +1 @@ +#include "SwiftCorelibsCoreFoundation/CoreFoundation.h" diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFArray.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFArray.h new file mode 100644 index 0000000..8ec1996 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFArray.h @@ -0,0 +1,672 @@ +/* CFArray.h + Copyright (c) 1998-2019, Apple Inc. All rights reserved. +*/ + +/*! + @header CFArray + CFArray implements an ordered, compact container of pointer-sized + values. Values are accessed via integer keys (indices), from the + range 0 to N-1, where N is the number of values in the array when + an operation is performed. The array is said to be "compact" because + deleted or inserted values do not leave a gap in the key space -- + the values with higher-numbered indices have their indices + renumbered lower (or higher, in the case of insertion) so that the + set of valid indices is always in the integer range [0, N-1]. Thus, + the index to access a particular value in the array may change over + time as other values are inserted into or deleted from the array. + + Arrays come in two flavors, immutable, which cannot have values + added to them or removed from them after the array is created, and + mutable, to which you can add values or from which remove values. + Mutable arrays can have an unlimited number of values (or rather, + limited only by constraints external to CFArray, like the amount + of available memory). + + As with all CoreFoundation collection types, arrays maintain hard + references on the values you put in them, but the retaining and + releasing functions are user-defined callbacks that can actually do + whatever the user wants (for example, nothing). + + Computational Complexity + The access time for a value in the array is guaranteed to be at + worst O(lg N) for any implementation, current and future, but will + often be O(1) (constant time). Linear search operations similarly + have a worst case complexity of O(N*lg N), though typically the + bounds will be tighter, and so on. Insertion or deletion operations + will typically be linear in the number of values in the array, but + may be O(N*lg N) clearly in the worst case in some implementations. + There are no favored positions within the array for performance; + that is, it is not necessarily faster to access values with low + indices, or to insert or delete values with high indices, or + whatever. +*/ + +#if !defined(__COREFOUNDATION_CFARRAY__) +#define __COREFOUNDATION_CFARRAY__ 1 + +#include "CFBase.h" + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +/*! + @typedef CFArrayCallBacks + Structure containing the callbacks of a CFArray. + @field version The version number of the structure type being passed + in as a parameter to the CFArray creation functions. This + structure is version 0. + @field retain The callback used to add a retain for the array on + values as they are put into the array. This callback returns + the value to store in the array, which is usually the value + parameter passed to this callback, but may be a different + value if a different value should be stored in the array. + The array's allocator is passed as the first argument. + @field release The callback used to remove a retain previously added + for the array from values as they are removed from the + array. The array's allocator is passed as the first + argument. + @field copyDescription The callback used to create a descriptive + string representation of each value in the array. This is + used by the CFCopyDescription() function. + @field equal The callback used to compare values in the array for + equality for some operations. +*/ +typedef const void * (*CFArrayRetainCallBack)(CFAllocatorRef allocator, const void *value); +typedef void (*CFArrayReleaseCallBack)(CFAllocatorRef allocator, const void *value); +typedef CFStringRef (*CFArrayCopyDescriptionCallBack)(const void *value); +typedef Boolean (*CFArrayEqualCallBack)(const void *value1, const void *value2); +typedef struct { + CFIndex version; + CFArrayRetainCallBack retain; + CFArrayReleaseCallBack release; + CFArrayCopyDescriptionCallBack copyDescription; + CFArrayEqualCallBack equal; +} CFArrayCallBacks; + +/*! + @constant kCFTypeArrayCallBacks + Predefined CFArrayCallBacks structure containing a set of callbacks + appropriate for use when the values in a CFArray are all CFTypes. +*/ +CF_EXPORT +const CFArrayCallBacks kCFTypeArrayCallBacks; + +/*! + @typedef CFArrayApplierFunction + Type of the callback function used by the apply functions of + CFArrays. + @param value The current value from the array. + @param context The user-defined context parameter given to the apply + function. +*/ +typedef void (*CFArrayApplierFunction)(const void *value, void *context); + +/*! + @typedef CFArrayRef + This is the type of a reference to immutable CFArrays. +*/ +typedef const struct CF_BRIDGED_TYPE(NSArray) __CFArray * CFArrayRef; + +/*! + @typedef CFMutableArrayRef + This is the type of a reference to mutable CFArrays. +*/ +typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableArray) __CFArray * CFMutableArrayRef; + +/*! + @function CFArrayGetTypeID + Returns the type identifier of all CFArray instances. +*/ +CF_EXPORT +CFTypeID CFArrayGetTypeID(void); + +/*! + @function CFArrayCreate + Creates a new immutable array with the given values. + @param allocator The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param values A C array of the pointer-sized values to be in the + array. The values in the array are ordered in the same order + in which they appear in this C array. This parameter may be + NULL if the numValues parameter is 0. This C array is not + changed or freed by this function. If this parameter is not + a valid pointer to a C array of at least numValues pointers, + the behavior is undefined. + @param numValues The number of values to copy from the values C + array into the CFArray. This number will be the count of the + array. + If this parameter is negative, or greater than the number of + values actually in the value's C array, the behavior is + undefined. + @param callBacks A pointer to a CFArrayCallBacks structure + initialized with the callbacks for the array to use on each + value in the array. The retain callback will be used within + this function, for example, to retain all of the new values + from the values C array. A copy of the contents of the + callbacks structure is made, so that a pointer to a + structure on the stack can be passed in, or can be reused + for multiple array creations. If the version field of this + callbacks structure is not one of the defined ones for + CFArray, the behavior is undefined. The retain field may be + NULL, in which case the CFArray will do nothing to add a + retain to the contained values for the array. The release + field may be NULL, in which case the CFArray will do nothing + to remove the array's retain (if any) on the values when the + array is destroyed. If the copyDescription field is NULL, + the array will create a simple description for the value. If + the equal field is NULL, the array will use pointer equality + to test for equality of values. This callbacks parameter + itself may be NULL, which is treated as if a valid structure + of version 0 with all fields NULL had been passed in. + Otherwise, if any of the fields are not valid pointers to + functions of the correct type, or this parameter is not a + valid pointer to a CFArrayCallBacks callbacks structure, + the behavior is undefined. If any of the values put into the + array is not one understood by one of the callback functions + the behavior when that callback function is used is + undefined. + @result A reference to the new immutable CFArray. +*/ +CF_EXPORT +CFArrayRef CFArrayCreate(CFAllocatorRef allocator, const void **values, CFIndex numValues, const CFArrayCallBacks *callBacks); + +/*! + @function CFArrayCreateCopy + Creates a new immutable array with the values from the given array. + @param allocator The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theArray The array which is to be copied. The values from the + array are copied as pointers into the new array (that is, + the values themselves are copied, not that which the values + point to, if anything). However, the values are also + retained by the new array. The count of the new array will + be the same as the given array. The new array uses the same + callbacks as the array to be copied. If this parameter is + not a valid CFArray, the behavior is undefined. + @result A reference to the new immutable CFArray. +*/ +CF_EXPORT +CFArrayRef CFArrayCreateCopy(CFAllocatorRef allocator, CFArrayRef theArray); + +/*! + @function CFArrayCreateMutable + Creates a new empty mutable array. + @param allocator The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param capacity A hint about the number of values that will be held + by the CFArray. Pass 0 for no hint. The implementation may + ignore this hint, or may use it to optimize various + operations. An array's actual capacity is only limited by + address space and available memory constraints). If this + parameter is negative, the behavior is undefined. + @param callBacks A pointer to a CFArrayCallBacks structure + initialized with the callbacks for the array to use on each + value in the array. A copy of the contents of the + callbacks structure is made, so that a pointer to a + structure on the stack can be passed in, or can be reused + for multiple array creations. If the version field of this + callbacks structure is not one of the defined ones for + CFArray, the behavior is undefined. The retain field may be + NULL, in which case the CFArray will do nothing to add a + retain to the contained values for the array. The release + field may be NULL, in which case the CFArray will do nothing + to remove the array's retain (if any) on the values when the + array is destroyed. If the copyDescription field is NULL, + the array will create a simple description for the value. If + the equal field is NULL, the array will use pointer equality + to test for equality of values. This callbacks parameter + itself may be NULL, which is treated as if a valid structure + of version 0 with all fields NULL had been passed in. + Otherwise, if any of the fields are not valid pointers to + functions of the correct type, or this parameter is not a + valid pointer to a CFArrayCallBacks callbacks structure, + the behavior is undefined. If any of the values put into the + array is not one understood by one of the callback functions + the behavior when that callback function is used is + undefined. + @result A reference to the new mutable CFArray. +*/ +CF_EXPORT +CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks); + +/*! + @function CFArrayCreateMutableCopy + Creates a new mutable array with the values from the given array. + @param allocator The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param capacity A hint about the number of values that will be held + by the CFArray. Pass 0 for no hint. The implementation may + ignore this hint, or may use it to optimize various + operations. An array's actual capacity is only limited by + address space and available memory constraints). + This parameter must be greater than or equal + to the count of the array which is to be copied, or the + behavior is undefined. If this parameter is negative, the + behavior is undefined. + @param theArray The array which is to be copied. The values from the + array are copied as pointers into the new array (that is, + the values themselves are copied, not that which the values + point to, if anything). However, the values are also + retained by the new array. The count of the new array will + be the same as the given array. The new array uses the same + callbacks as the array to be copied. If this parameter is + not a valid CFArray, the behavior is undefined. + @result A reference to the new mutable CFArray. +*/ +CF_EXPORT +CFMutableArrayRef CFArrayCreateMutableCopy(CFAllocatorRef allocator, CFIndex capacity, CFArrayRef theArray); + +/*! + @function CFArrayGetCount + Returns the number of values currently in the array. + @param theArray The array to be queried. If this parameter is not a valid + CFArray, the behavior is undefined. + @result The number of values in the array. +*/ +CF_EXPORT +CFIndex CFArrayGetCount(CFArrayRef theArray); + +/*! + @function CFArrayGetCountOfValue + Counts the number of times the given value occurs in the array. + @param theArray The array to be searched. If this parameter is not a + valid CFArray, the behavior is undefined. + @param range The range within the array to search. If the range + location or end point (defined by the location plus length + minus 1) is outside the index space of the array (0 to + N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + @param value The value for which to find matches in the array. The + equal() callback provided when the array was created is + used to compare. If the equal() callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values + in the array, are not understood by the equal() callback, + the behavior is undefined. + @result The number of times the given value occurs in the array, + within the specified range. +*/ +CF_EXPORT +CFIndex CFArrayGetCountOfValue(CFArrayRef theArray, CFRange range, const void *value); + +/*! + @function CFArrayContainsValue + Reports whether or not the value is in the array. + @param theArray The array to be searched. If this parameter is not a + valid CFArray, the behavior is undefined. + @param range The range within the array to search. If the range + location or end point (defined by the location plus length + minus 1) is outside the index space of the array (0 to + N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + @param value The value for which to find matches in the array. The + equal() callback provided when the array was created is + used to compare. If the equal() callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values + in the array, are not understood by the equal() callback, + the behavior is undefined. + @result true, if the value is in the specified range of the array, + otherwise false. +*/ +CF_EXPORT +Boolean CFArrayContainsValue(CFArrayRef theArray, CFRange range, const void *value); + +/*! + @function CFArrayGetValueAtIndex + Retrieves the value at the given index. + @param theArray The array to be queried. If this parameter is not a + valid CFArray, the behavior is undefined. + @param idx The index of the value to retrieve. If the index is + outside the index space of the array (0 to N-1 inclusive, + where N is the count of the array), the behavior is + undefined. + @result The value with the given index in the array. +*/ +CF_EXPORT +const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); + +/*! + @function CFArrayGetValues + Fills the buffer with values from the array. + @param theArray The array to be queried. If this parameter is not a + valid CFArray, the behavior is undefined. + @param range The range of values within the array to retrieve. If + the range location or end point (defined by the location + plus length minus 1) is outside the index space of the + array (0 to N-1 inclusive, where N is the count of the + array), the behavior is undefined. If the range length is + negative, the behavior is undefined. The range may be empty + (length 0), in which case no values are put into the buffer. + @param values A C array of pointer-sized values to be filled with + values from the array. The values in the C array are ordered + in the same order in which they appear in the array. If this + parameter is not a valid pointer to a C array of at least + range.length pointers, the behavior is undefined. +*/ +CF_EXPORT +void CFArrayGetValues(CFArrayRef theArray, CFRange range, const void **values); + +/*! + @function CFArrayApplyFunction + Calls a function once for each value in the array. + @param theArray The array to be operated upon. If this parameter is not + a valid CFArray, the behavior is undefined. + @param range The range of values within the array to which to apply + the function. If the range location or end point (defined by + the location plus length minus 1) is outside the index + space of the array (0 to N-1 inclusive, where N is the count + of the array), the behavior is undefined. If the range + length is negative, the behavior is undefined. The range may + be empty (length 0). + @param applier The callback function to call once for each value in + the given range in the array. If this parameter is not a + pointer to a function of the correct prototype, the behavior + is undefined. If there are values in the range which the + applier function does not expect or cannot properly apply + to, the behavior is undefined. + @param context A pointer-sized user-defined value, which is passed + as the second parameter to the applier function, but is + otherwise unused by this function. If the context is not + what is expected by the applier function, the behavior is + undefined. +*/ +CF_EXPORT +void CFArrayApplyFunction(CFArrayRef theArray, CFRange range, CFArrayApplierFunction CF_NOESCAPE applier, void *context); + +/*! + @function CFArrayGetFirstIndexOfValue + Searches the array for the value. + @param theArray The array to be searched. If this parameter is not a + valid CFArray, the behavior is undefined. + @param range The range within the array to search. If the range + location or end point (defined by the location plus length + minus 1) is outside the index space of the array (0 to + N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + The search progresses from the smallest index defined by + the range to the largest. + @param value The value for which to find a match in the array. The + equal() callback provided when the array was created is + used to compare. If the equal() callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values + in the array, are not understood by the equal() callback, + the behavior is undefined. + @result The lowest index of the matching values in the range, or + kCFNotFound if no value in the range matched. +*/ +CF_EXPORT +CFIndex CFArrayGetFirstIndexOfValue(CFArrayRef theArray, CFRange range, const void *value); + +/*! + @function CFArrayGetLastIndexOfValue + Searches the array for the value. + @param theArray The array to be searched. If this parameter is not a + valid CFArray, the behavior is undefined. + @param range The range within the array to search. If the range + location or end point (defined by the location plus length + minus 1) is outside the index space of the array (0 to + N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + The search progresses from the largest index defined by the + range to the smallest. + @param value The value for which to find a match in the array. The + equal() callback provided when the array was created is + used to compare. If the equal() callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values + in the array, are not understood by the equal() callback, + the behavior is undefined. + @result The highest index of the matching values in the range, or + kCFNotFound if no value in the range matched. +*/ +CF_EXPORT +CFIndex CFArrayGetLastIndexOfValue(CFArrayRef theArray, CFRange range, const void *value); + +/*! + @function CFArrayBSearchValues + Searches the array for the value using a binary search algorithm. + @param theArray The array to be searched. If this parameter is not a + valid CFArray, the behavior is undefined. If the array is + not sorted from least to greatest according to the + comparator function, the behavior is undefined. + @param range The range within the array to search. If the range + location or end point (defined by the location plus length + minus 1) is outside the index space of the array (0 to + N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + @param value The value for which to find a match in the array. If + value, or any of the values in the array, are not understood + by the comparator callback, the behavior is undefined. + @param comparator The function with the comparator function type + signature which is used in the binary search operation to + compare values in the array with the given value. If this + parameter is not a pointer to a function of the correct + prototype, the behavior is undefined. If there are values + in the range which the comparator function does not expect + or cannot properly compare, the behavior is undefined. + @param context A pointer-sized user-defined value, which is passed + as the third parameter to the comparator function, but is + otherwise unused by this function. If the context is not + what is expected by the comparator function, the behavior is + undefined. + @result The return value is either 1) the index of a value that + matched, if the target value matches one or more in the + range, 2) greater than or equal to the end point of the + range, if the value is greater than all the values in the + range, or 3) the index of the value greater than the target + value, if the value lies between two of (or less than all + of) the values in the range. +*/ +CF_EXPORT +CFIndex CFArrayBSearchValues(CFArrayRef theArray, CFRange range, const void *value, CFComparatorFunction comparator, void *context); + +/*! + @function CFArrayAppendValue + Adds the value to the array giving it a new largest index. + @param theArray The array to which the value is to be added. If this + parameter is not a valid mutable CFArray, the behavior is + undefined. + @param value The value to add to the array. The value is retained by + the array using the retain callback provided when the array + was created. If the value is not of the sort expected by the + retain callback, the behavior is undefined. The value is + assigned to the index one larger than the previous largest + index, and the count of the array is increased by one. +*/ +CF_EXPORT +void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value); + +/*! + @function CFArrayInsertValueAtIndex + Adds the value to the array, giving it the given index. + @param theArray The array to which the value is to be added. If this + parameter is not a valid mutable CFArray, the behavior is + undefined. + @param idx The index to which to add the new value. If the index is + outside the index space of the array (0 to N inclusive, + where N is the count of the array before the operation), the + behavior is undefined. If the index is the same as N, this + function has the same effect as CFArrayAppendValue(). + @param value The value to add to the array. The value is retained by + the array using the retain callback provided when the array + was created. If the value is not of the sort expected by the + retain callback, the behavior is undefined. The value is + assigned to the given index, and all values with equal and + larger indices have their indexes increased by one. +*/ +CF_EXPORT +void CFArrayInsertValueAtIndex(CFMutableArrayRef theArray, CFIndex idx, const void *value); + +/*! + @function CFArraySetValueAtIndex + Changes the value with the given index in the array. + @param theArray The array in which the value is to be changed. If this + parameter is not a valid mutable CFArray, the behavior is + undefined. + @param idx The index to which to set the new value. If the index is + outside the index space of the array (0 to N inclusive, + where N is the count of the array before the operation), the + behavior is undefined. If the index is the same as N, this + function has the same effect as CFArrayAppendValue(). + @param value The value to set in the array. The value is retained by + the array using the retain callback provided when the array + was created, and the previous value with that index is + released. If the value is not of the sort expected by the + retain callback, the behavior is undefined. The indices of + other values is not affected. +*/ +CF_EXPORT +void CFArraySetValueAtIndex(CFMutableArrayRef theArray, CFIndex idx, const void *value); + +/*! + @function CFArrayRemoveValueAtIndex + Removes the value with the given index from the array. + @param theArray The array from which the value is to be removed. If + this parameter is not a valid mutable CFArray, the behavior + is undefined. + @param idx The index from which to remove the value. If the index is + outside the index space of the array (0 to N-1 inclusive, + where N is the count of the array before the operation), the + behavior is undefined. +*/ +CF_EXPORT +void CFArrayRemoveValueAtIndex(CFMutableArrayRef theArray, CFIndex idx); + +/*! + @function CFArrayRemoveAllValues + Removes all the values from the array, making it empty. + @param theArray The array from which all of the values are to be + removed. If this parameter is not a valid mutable CFArray, + the behavior is undefined. +*/ +CF_EXPORT +void CFArrayRemoveAllValues(CFMutableArrayRef theArray); + +/*! + @function CFArrayReplaceValues + Replaces a range of values in the array. + @param theArray The array from which all of the values are to be + removed. If this parameter is not a valid mutable CFArray, + the behavior is undefined. + @param range The range of values within the array to replace. If the + range location or end point (defined by the location plus + length minus 1) is outside the index space of the array (0 + to N inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0), + in which case the new values are merely inserted at the + range location. + @param newValues A C array of the pointer-sized values to be placed + into the array. The new values in the array are ordered in + the same order in which they appear in this C array. This + parameter may be NULL if the newCount parameter is 0. This + C array is not changed or freed by this function. If this + parameter is not a valid pointer to a C array of at least + newCount pointers, the behavior is undefined. + @param newCount The number of values to copy from the values C + array into the CFArray. If this parameter is different than + the range length, the excess newCount values will be + inserted after the range, or the excess range values will be + deleted. This parameter may be 0, in which case no new + values are replaced into the array and the values in the + range are simply removed. If this parameter is negative, or + greater than the number of values actually in the newValues + C array, the behavior is undefined. +*/ +CF_EXPORT +void CFArrayReplaceValues(CFMutableArrayRef theArray, CFRange range, const void **newValues, CFIndex newCount); + +/*! + @function CFArrayExchangeValuesAtIndices + Exchanges the values at two indices of the array. + @param theArray The array of which the values are to be swapped. If + this parameter is not a valid mutable CFArray, the behavior + is undefined. + @param idx1 The first index whose values should be swapped. If the + index is outside the index space of the array (0 to N-1 + inclusive, where N is the count of the array before the + operation), the behavior is undefined. + @param idx2 The second index whose values should be swapped. If the + index is outside the index space of the array (0 to N-1 + inclusive, where N is the count of the array before the + operation), the behavior is undefined. +*/ +CF_EXPORT +void CFArrayExchangeValuesAtIndices(CFMutableArrayRef theArray, CFIndex idx1, CFIndex idx2); + +/*! + @function CFArraySortValues + Sorts the values in the array using the given comparison function. + @param theArray The array whose values are to be sorted. If this + parameter is not a valid mutable CFArray, the behavior is + undefined. + @param range The range of values within the array to sort. If the + range location or end point (defined by the location plus + length minus 1) is outside the index space of the array (0 + to N-1 inclusive, where N is the count of the array), the + behavior is undefined. If the range length is negative, the + behavior is undefined. The range may be empty (length 0). + @param comparator The function with the comparator function type + signature which is used in the sort operation to compare + values in the array with the given value. If this parameter + is not a pointer to a function of the correct prototype, the + the behavior is undefined. If there are values in the array + which the comparator function does not expect or cannot + properly compare, the behavior is undefined. The values in + the range are sorted from least to greatest according to + this function. + @param context A pointer-sized user-defined value, which is passed + as the third parameter to the comparator function, but is + otherwise unused by this function. If the context is not + what is expected by the comparator function, the behavior is + undefined. +*/ +CF_EXPORT +void CFArraySortValues(CFMutableArrayRef theArray, CFRange range, CFComparatorFunction comparator, void *context); + +/*! + @function CFArrayAppendArray + Adds the values from an array to another array. + @param theArray The array to which values from the otherArray are to + be added. If this parameter is not a valid mutable CFArray, + the behavior is undefined. + @param otherArray The array providing the values to be added to the + array. If this parameter is not a valid CFArray, the + behavior is undefined. + @param otherRange The range within the otherArray from which to add + the values to the array. If the range location or end point + (defined by the location plus length minus 1) is outside + the index space of the otherArray (0 to N-1 inclusive, where + N is the count of the otherArray), the behavior is + undefined. The new values are retained by the array using + the retain callback provided when the array was created. If + the values are not of the sort expected by the retain + callback, the behavior is undefined. The values are assigned + to the indices one larger than the previous largest index + in the array, and beyond, and the count of the array is + increased by range.length. The values are assigned new + indices in the array from smallest to largest index in the + order in which they appear in the otherArray. +*/ +CF_EXPORT +void CFArrayAppendArray(CFMutableArrayRef theArray, CFArrayRef otherArray, CFRange otherRange); + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFARRAY__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFAvailability.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFAvailability.h new file mode 100644 index 0000000..9cee298 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFAvailability.h @@ -0,0 +1,236 @@ +/* CFAvailability.h + Copyright (c) 2013-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#ifndef DEPLOYMENT_RUNTIME_SWIFT +#define DEPLOYMENT_RUNTIME_SWIFT 1 +#endif + +#if !defined(__COREFOUNDATION_CFAVAILABILITY__) +#define __COREFOUNDATION_CFAVAILABILITY__ 1 + +#include "CFTargetConditionals.h" + +#if __has_include() && __has_include() && __has_include() +#include +#include +// Even if unused, these must remain here for compatibility, because projects rely on them being included. +#include +#else +#define API_AVAILABLE(...) +#define API_DEPRECATED(...) +#define API_UNAVAILABLE(...) +#endif + +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +// The arguments to these availability macros is a version number, e.g. 10_6, 3_0 or 'NA' +// To use a deprecation message with the macro, add a string as the last argument. +#if __has_feature(attribute_availability_with_version_underscores) || (__has_feature(attribute_availability_with_message) && __clang__ && __clang_major__ >= 7) +#if TARGET_OS_OSX +// This section is for compilers targeting OS X which support attribute_availability_with_message + +#define CF_AVAILABLE(_mac, _ios) __attribute__((availability(macosx,introduced=_mac))) +#define CF_AVAILABLE_MAC(_mac) __attribute__((availability(macosx,introduced=_mac))) +#define CF_AVAILABLE_IOS(_ios) __attribute__((availability(macosx,unavailable))) +#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) __attribute__((availability(macosx,introduced=_macIntro,deprecated=_macDep,message="" __VA_ARGS__))) +#define CF_DEPRECATED_MAC(_macIntro, _macDep, ...) __attribute__((availability(macosx,introduced=_macIntro,deprecated=_macDep,message="" __VA_ARGS__))) +#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...) __attribute__((availability(macosx,unavailable))) + +#elif TARGET_OS_IPHONE +// This section is for compilers targeting iOS which support attribute_availability_with_message + +#define CF_AVAILABLE(_mac, _ios) __attribute__((availability(ios,introduced=_ios))) +#define CF_AVAILABLE_MAC(_mac) __attribute__((availability(ios,unavailable))) +#define CF_AVAILABLE_IOS(_ios) __attribute__((availability(ios,introduced=_ios))) +#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) __attribute__((availability(ios,introduced=_iosIntro,deprecated=_iosDep,message="" __VA_ARGS__))) +#define CF_DEPRECATED_MAC(_macIntro, _macDep, ...) __attribute__((availability(ios,unavailable))) +#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...) __attribute__((availability(ios,introduced=_iosIntro,deprecated=_iosDep,message="" __VA_ARGS__))) + +#endif + +#elif TARGET_OS_OSX || TARGET_OS_IPHONE +// This section is for OS X or iOS, and compilers without support for attribute_availability_with_message. We fall back to Availability.h. + +#ifndef __AVAILABILITY_INTERNAL__MAC_10_0_DEP__MAC_10_0 +#define __AVAILABILITY_INTERNAL__MAC_10_0_DEP__MAC_10_0 __AVAILABILITY_INTERNAL_DEPRECATED +#endif + +#define CF_AVAILABLE(_mac, _ios) __OSX_AVAILABLE_STARTING(__MAC_##_mac, __IPHONE_##_ios) +#define CF_AVAILABLE_MAC(_mac) __OSX_AVAILABLE_STARTING(__MAC_##_mac, __IPHONE_NA) +#define CF_AVAILABLE_IOS(_ios) __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_##_ios) +#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_##_macIntro, __MAC_##_macDep, __IPHONE_##_iosIntro, __IPHONE_##_iosDep) +#define CF_DEPRECATED_MAC(_macIntro, _macDep, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_##_macIntro, __MAC_##_macDep, __IPHONE_NA, __IPHONE_NA) +#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA, __MAC_NA, __IPHONE_##_iosIntro, __IPHONE_##_iosDep) + +#endif // __has_feature(attribute_availability_with_message) + +#ifndef CF_AVAILABLE +// This section is for platforms which do not support availability +#define CF_AVAILABLE(_mac, _ios) +#define CF_AVAILABLE_MAC(_mac) +#define CF_AVAILABLE_IOS(_ios) +#define CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) +#define CF_DEPRECATED_MAC(_macIntro, _macDep, ...) +#define CF_DEPRECATED_IOS(_iosIntro, _iosDep, ...) +#endif + +// Older versions of these macros; use iOS versions instead +#define CF_AVAILABLE_IPHONE(_ios) CF_AVAILABLE_IOS(_ios) +#define CF_DEPRECATED_IPHONE(_iosIntro, _iosDep) CF_DEPRECATED_IOS(_iosIntro, _iosDep) + +// Enum availability macros +#if __has_feature(enumerator_attributes) && __has_attribute(availability) +#define CF_ENUM_AVAILABLE(_mac, _ios) CF_AVAILABLE(_mac, _ios) +#define CF_ENUM_AVAILABLE_MAC(_mac) CF_AVAILABLE_MAC(_mac) +#define CF_ENUM_AVAILABLE_IOS(_ios) CF_AVAILABLE_IOS(_ios) +#define CF_ENUM_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) CF_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, __VA_ARGS__) +#define CF_ENUM_DEPRECATED_MAC(_macIntro, _macDep, ...) CF_DEPRECATED_MAC(_macIntro, _macDep, __VA_ARGS__) +#define CF_ENUM_DEPRECATED_IOS(_iosIntro, _iosDep, ...) CF_DEPRECATED_IOS(_iosIntro, _iosDep, __VA_ARGS__) +#else +#define CF_ENUM_AVAILABLE(_mac, _ios) +#define CF_ENUM_AVAILABLE_MAC(_mac) +#define CF_ENUM_AVAILABLE_IOS(_ios) +#define CF_ENUM_DEPRECATED(_macIntro, _macDep, _iosIntro, _iosDep, ...) +#define CF_ENUM_DEPRECATED_MAC(_macIntro, _macDep, ...) +#define CF_ENUM_DEPRECATED_IOS(_iosIntro, _iosDep, ...) +#endif + +// "Soft" deprecation. +#ifndef API_TO_BE_DEPRECATED +/// This macro is used as a version number in API that will be deprecated in an upcoming release. We call this API "soft deprecated". Soft deprecation is an intermediate step before formal deprecation, used as a way to give you a heads-up about the API before you start getting a compiler warning. +/// You can find all places in your code that use soft deprecated API by redefining the value of this macro to your current minimum deployment target, for example: +/// (macOS) +/// clang -DAPI_TO_BE_DEPRECATED=10.12 other compiler flags +/// (iOS) +/// clang -DAPI_TO_BE_DEPRECATED=11.0 other compiler flags +#define API_TO_BE_DEPRECATED 100000 +#endif + +// Enums and Options +#if __has_attribute(enum_extensibility) +#define __CF_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open))) +#define __CF_CLOSED_ENUM_ATTRIBUTES __attribute__((enum_extensibility(closed))) +#define __CF_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open))) +#else +#define __CF_ENUM_ATTRIBUTES +#define __CF_CLOSED_ENUM_ATTRIBUTES +#define __CF_OPTIONS_ATTRIBUTES +#endif + +#define __CF_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME +#define __CF_ENUM_FIXED_IS_AVAILABLE (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && (__has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum))) + +#if __CF_ENUM_FIXED_IS_AVAILABLE +#define __CF_NAMED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type +#define __CF_ANON_ENUM(_type) enum __CF_ENUM_ATTRIBUTES : _type +#define CF_CLOSED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type +#if (__cplusplus) +#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type +#else +#define CF_OPTIONS(_type, _name) int __CF_OPTIONS_ ## _name; enum __CF_OPTIONS_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type +#endif +#else +#define __CF_NAMED_ENUM(_type, _name) _type _name; enum +#define __CF_ANON_ENUM(_type) enum +#define CF_CLOSED_ENUM(_type, _name) _type _name; enum +#define CF_OPTIONS(_type, _name) _type _name; enum +#endif + +/* CF_ENUM supports the use of one or two arguments. The first argument is always the integer type used for the values of the enum. The second argument is an optional type name for the macro. When specifying a type name, you must precede the macro with 'typedef' like so: + +typedef CF_ENUM(CFIndex, CFComparisonResult) { + ... +}; + +If you do not specify a type name, do not use 'typdef', like so: + +CF_ENUM(CFIndex) { + ... +}; +*/ +#define CF_ENUM(...) __CF_ENUM_GET_MACRO(__VA_ARGS__, __CF_NAMED_ENUM, __CF_ANON_ENUM, )(__VA_ARGS__) + +#if __has_attribute(swift_wrapper) +#define _CF_TYPED_ENUM __attribute__((swift_wrapper(enum))) +#else +#define _CF_TYPED_ENUM +#endif + +#if __has_attribute(swift_wrapper) +#define _CF_TYPED_EXTENSIBLE_ENUM __attribute__((swift_wrapper(struct))) +#else +#define _CF_TYPED_EXTENSIBLE_ENUM +#endif + +#if DEPLOYMENT_RUNTIME_SWIFT +#define CF_STRING_ENUM +#define CF_EXTENSIBLE_STRING_ENUM + +#define CF_TYPED_ENUM +#define CF_TYPED_EXTENSIBLE_ENUM +#else +#define CF_STRING_ENUM _CF_TYPED_ENUM +#define CF_EXTENSIBLE_STRING_ENUM _CF_TYPED_EXTENSIBLE_ENUM + +#define CF_TYPED_ENUM _CF_TYPED_ENUM +#define CF_TYPED_EXTENSIBLE_ENUM _CF_TYPED_EXTENSIBLE_ENUM +#endif + +#define __CF_ERROR_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME +#if ((__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))) && __has_attribute(ns_error_domain) +#define __CF_NAMED_ERROR_ENUM(_domain, _name) enum __attribute__((ns_error_domain(_domain))) _name : CFIndex _name; enum _name : CFIndex +#define __CF_ANON_ERROR_ENUM(_domain) enum __attribute__((ns_error_domain(_domain))) : CFIndex +#else +#define __CF_NAMED_ERROR_ENUM(_domain, _name) __CF_NAMED_ENUM(CFIndex, _name) +#define __CF_ANON_ERROR_ENUM(_domain) __CF_ANON_ENUM(CFIndex) +#endif + +/* CF_ERROR_ENUM supports the use of one or two arguments. The first argument is always the domain specifier for the enum. The second argument is an optional name of the typedef for the macro. When specifying a name for of the typedef, you must precede the macro with 'typedef' like so: + + typedef CF_ERROR_ENUM(kCFSomeErrorDomain, SomeErrorCodes) { + ... + }; + + If you do not specify a typedef name, do not use 'typedef', like so: + + CF_ERROR_ENUM(kCFSomeErrorDomain) { + ... + }; + */ +#define CF_ERROR_ENUM(...) __CF_ERROR_ENUM_GET_MACRO(__VA_ARGS__, __CF_NAMED_ERROR_ENUM, __CF_ANON_ERROR_ENUM)(__VA_ARGS__) + +#ifndef CF_SWIFT_BRIDGED_TYPEDEF +#if __has_attribute(swift_bridged_typedef) +#define CF_SWIFT_BRIDGED_TYPEDEF __attribute__((swift_bridged_typedef)) +#else +#define CF_SWIFT_BRIDGED_TYPEDEF +#endif +#endif + +// Extension availability macros +#define CF_EXTENSION_UNAVAILABLE(_msg) __OS_EXTENSION_UNAVAILABLE(_msg) +#define CF_EXTENSION_UNAVAILABLE_MAC(_msg) __OSX_EXTENSION_UNAVAILABLE(_msg) +#define CF_EXTENSION_UNAVAILABLE_IOS(_msg) __IOS_EXTENSION_UNAVAILABLE(_msg) + +// Swift availability macro +#if __has_feature(attribute_availability_swift) +#define CF_SWIFT_UNAVAILABLE(_msg) __attribute__((availability(swift, unavailable, message=_msg))) +#else +#define CF_SWIFT_UNAVAILABLE(_msg) +#endif + +#endif // __COREFOUNDATION_CFAVAILABILITY__ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFBase.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFBase.h new file mode 100644 index 0000000..2b2bdc4 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFBase.h @@ -0,0 +1,701 @@ +/* CFBase.h + Copyright (c) 1998-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFBASE__) +#define __COREFOUNDATION_CFBASE__ 1 + +#include "CFTargetConditionals.h" +#include "CFAvailability.h" + +#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__) +#define __WIN32__ 1 +#endif + +#if defined(_WIN64) && !defined(__WIN64__) +#define __WIN64__ 1 +#endif + +#if defined(__WIN64__) && !defined(__LLP64__) +#define __LLP64__ 1 +#endif + +#if defined(_MSC_VER) && defined(_M_IX86) +#define __i386__ 1 +#endif + +#if (defined(__i386__) || defined(__x86_64__)) && !defined(__LITTLE_ENDIAN__) +#define __LITTLE_ENDIAN__ 1 +#endif + +#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +#error Do not know the endianess of this architecture +#endif + +#if !__BIG_ENDIAN__ && !__LITTLE_ENDIAN__ +#error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be false +#endif + +#if __BIG_ENDIAN__ && __LITTLE_ENDIAN__ +#error Both __BIG_ENDIAN__ and __LITTLE_ENDIAN__ cannot be true +#endif + +// Some compilers provide the capability to test if certain features are available. This macro provides a compatibility path for other compilers. +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +// Some compilers provide the capability to test if certain attributes are available. This macro provides a compatibility path for other compilers. +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif + +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +#if defined(__GNUC__) || TARGET_OS_WIN32 +#include +#endif + +#include + + #if (TARGET_OS_OSX || TARGET_OS_IPHONE) && !DEPLOYMENT_RUNTIME_SWIFT + #include + #endif + +#if TARGET_OS_MAC +#include +#endif + +#if !defined(__MACTYPES__) +#if !defined(_OS_OSTYPES_H) + typedef bool Boolean; + typedef unsigned char UInt8; + typedef signed char SInt8; + typedef unsigned short UInt16; + typedef signed short SInt16; + typedef unsigned int UInt32; + typedef signed int SInt32; + typedef uint64_t UInt64; + typedef int64_t SInt64; + typedef SInt32 OSStatus; +#endif + typedef float Float32; + typedef double Float64; + typedef unsigned short UniChar; + typedef unsigned long UniCharCount; + typedef unsigned char * StringPtr; + typedef const unsigned char * ConstStringPtr; + typedef unsigned char Str255[256]; + typedef const unsigned char * ConstStr255Param; + typedef SInt16 OSErr; + typedef SInt16 RegionCode; + typedef SInt16 LangCode; + typedef SInt16 ScriptCode; + typedef UInt32 FourCharCode; + typedef FourCharCode OSType; + typedef UInt8 Byte; + typedef SInt8 SignedByte; +#endif +#if !defined(__MACTYPES__) || (defined(UNIVERSAL_INTERFACES_VERSION) && UNIVERSAL_INTERFACES_VERSION < 0x0340) + typedef UInt32 UTF32Char; + typedef UInt16 UTF16Char; + typedef UInt8 UTF8Char; +#endif + +#if !defined(CF_EXTERN_C_BEGIN) +#if defined(__cplusplus) +#define CF_EXTERN_C_BEGIN extern "C" { +#define CF_EXTERN_C_END } +#else +#define CF_EXTERN_C_BEGIN +#define CF_EXTERN_C_END +#endif +#endif + +#if TARGET_OS_WIN32 + #if defined(__cplusplus) + #define _CF_EXTERN extern "C" + #else + #define _CF_EXTERN extern + #endif + + #if defined(_WINDLL) + #if defined(CoreFoundation_EXPORTS) || defined(CF_BUILDING_CF) + #define CF_EXPORT _CF_EXTERN __declspec(dllexport) + #else + #define CF_EXPORT _CF_EXTERN __declspec(dllimport) + #endif + #else + #define CF_EXPORT _CF_EXTERN + #endif +#else +#define CF_EXPORT extern +#endif + +CF_EXTERN_C_BEGIN + +#if !defined(NULL) +#if defined(__GNUG__) + #define NULL __null +#elif defined(__cplusplus) + #define NULL 0 +#else + #define NULL ((void *)0) +#endif +#endif + +#if !defined(TRUE) + #define TRUE 1 +#endif + +#if !defined(FALSE) + #define FALSE 0 +#endif + +// Marks functions which return a CF type that needs to be released by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed. +// This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules. +#ifndef CF_RETURNS_RETAINED +#if __has_feature(attribute_cf_returns_retained) +#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) +#else +#define CF_RETURNS_RETAINED +#endif +#endif + +// Marks functions which return a CF type that may need to be retained by the caller but whose names are not consistent with CoreFoundation naming rules. The recommended fix to this is to rename the functions, but this macro can be used to let the clang static analyzer know of any exceptions that cannot be fixed. +// This macro is ONLY to be used in exceptional circumstances, not to annotate functions which conform to the CoreFoundation naming rules. +#ifndef CF_RETURNS_NOT_RETAINED +#if __has_feature(attribute_cf_returns_not_retained) +#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) +#else +#define CF_RETURNS_NOT_RETAINED +#endif +#endif + +// Marks function arguments which are released by the callee. +#ifndef CF_RELEASES_ARGUMENT +#if __has_feature(attribute_cf_consumed) +#define CF_RELEASES_ARGUMENT __attribute__((cf_consumed)) +#else +#define CF_RELEASES_ARGUMENT +#endif +#endif + +// Compatibility +#ifndef CF_CONSUMED +#if __has_feature(attribute_cf_consumed) +#define CF_CONSUMED __attribute__((cf_consumed)) +#else +#define CF_CONSUMED +#endif +#endif + +// Marks functions which cannot be used when compiling in automatic reference counting mode. +#if __has_feature(objc_arc) +#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode"))) +#else +#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE +#endif + +#ifndef CF_IMPLICIT_BRIDGING_ENABLED +#if __has_feature(arc_cf_code_audited) +#define CF_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin") +#else +#define CF_IMPLICIT_BRIDGING_ENABLED +#endif +#endif + +#ifndef CF_IMPLICIT_BRIDGING_DISABLED +#if __has_feature(arc_cf_code_audited) +#define CF_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end") +#else +#define CF_IMPLICIT_BRIDGING_DISABLED +#endif +#endif + +#if __has_attribute(objc_bridge) && __has_feature(objc_bridge_id) && __has_feature(objc_bridge_id_on_typedefs) + +#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T))) +#define CF_BRIDGED_MUTABLE_TYPE(T) __attribute__((objc_bridge_mutable(T))) +#define CF_RELATED_TYPE(T,C,I) __attribute__((objc_bridge_related(T,C,I))) +#else +#define CF_BRIDGED_TYPE(T) +#define CF_BRIDGED_MUTABLE_TYPE(T) +#define CF_RELATED_TYPE(T,C,I) +#endif + + +#if __has_feature(assume_nonnull) +#define CF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define CF_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define CF_ASSUME_NONNULL_BEGIN +#define CF_ASSUME_NONNULL_END +#endif + + +#if !__has_feature(nullability) +#ifndef _Nullable +#define _Nullable +#endif +#ifndef _Nonnull +#define _Nonnull +#endif +#ifndef _Null_unspecified +#define _Null_unspecified +#endif +#endif + + +#if __has_attribute(swift_private) +# define CF_REFINED_FOR_SWIFT __attribute__((swift_private)) +#else +# define CF_REFINED_FOR_SWIFT +#endif + + +#if __has_attribute(swift_name) +# define CF_SWIFT_NAME(_name) __attribute__((swift_name(#_name))) +#else +# define CF_SWIFT_NAME(_name) +#endif + +#if __has_attribute(noescape) +#define CF_NOESCAPE __attribute__((noescape)) +#else +#define CF_NOESCAPE +#endif + +#if __has_attribute(not_tail_called) +#define CF_NO_TAIL_CALL __attribute__((not_tail_called)) +#else +#define CF_NO_TAIL_CALL +#endif + +#if __has_attribute(warn_unused_result) +#define CF_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define CF_WARN_UNUSED_RESULT +#endif + +#if __has_attribute(fallthrough) +#define CF_FALLTHROUGH __attribute__((fallthrough)) +#else +#define CF_FALLTHROUGH +#endif + +#if !__has_feature(objc_generics_variance) +#ifndef __covariant +#define __covariant +#endif +#ifndef __contravariant +#define __contravariant +#endif +#endif + +#if !defined(CF_INLINE) + #if defined(__GNUC__) && (__GNUC__ == 4) && !defined(DEBUG) + #define CF_INLINE static __inline__ __attribute__((always_inline)) + #elif defined(__GNUC__) + #define CF_INLINE static __inline__ + #elif defined(__cplusplus) + #define CF_INLINE static inline + #elif defined(_MSC_VER) + #define CF_INLINE static __inline + #elif TARGET_OS_WIN32 + #define CF_INLINE static __inline__ + #endif +#endif + +CF_EXPORT double kCFCoreFoundationVersionNumber; + +#if TARGET_OS_MAC +#define kCFCoreFoundationVersionNumber10_0 196.40 +#define kCFCoreFoundationVersionNumber10_0_3 196.50 +#define kCFCoreFoundationVersionNumber10_1 226.00 +#define kCFCoreFoundationVersionNumber10_1_1 226.00 +/* Note the next three do not follow the usual numbering policy from the base release */ +#define kCFCoreFoundationVersionNumber10_1_2 227.20 +#define kCFCoreFoundationVersionNumber10_1_3 227.20 +#define kCFCoreFoundationVersionNumber10_1_4 227.30 +#define kCFCoreFoundationVersionNumber10_2 263.00 +#define kCFCoreFoundationVersionNumber10_2_1 263.10 +#define kCFCoreFoundationVersionNumber10_2_2 263.10 +#define kCFCoreFoundationVersionNumber10_2_3 263.30 +#define kCFCoreFoundationVersionNumber10_2_4 263.30 +#define kCFCoreFoundationVersionNumber10_2_5 263.50 +#define kCFCoreFoundationVersionNumber10_2_6 263.50 +#define kCFCoreFoundationVersionNumber10_2_7 263.50 +#define kCFCoreFoundationVersionNumber10_2_8 263.50 +#define kCFCoreFoundationVersionNumber10_3 299.00 +#define kCFCoreFoundationVersionNumber10_3_1 299.00 +#define kCFCoreFoundationVersionNumber10_3_2 299.00 +#define kCFCoreFoundationVersionNumber10_3_3 299.30 +#define kCFCoreFoundationVersionNumber10_3_4 299.31 +#define kCFCoreFoundationVersionNumber10_3_5 299.31 +#define kCFCoreFoundationVersionNumber10_3_6 299.32 +#define kCFCoreFoundationVersionNumber10_3_7 299.33 +#define kCFCoreFoundationVersionNumber10_3_8 299.33 +#define kCFCoreFoundationVersionNumber10_3_9 299.35 +#define kCFCoreFoundationVersionNumber10_4 368.00 +#define kCFCoreFoundationVersionNumber10_4_1 368.10 +#define kCFCoreFoundationVersionNumber10_4_2 368.11 +#define kCFCoreFoundationVersionNumber10_4_3 368.18 +#define kCFCoreFoundationVersionNumber10_4_4_Intel 368.26 +#define kCFCoreFoundationVersionNumber10_4_4_PowerPC 368.25 +#define kCFCoreFoundationVersionNumber10_4_5_Intel 368.26 +#define kCFCoreFoundationVersionNumber10_4_5_PowerPC 368.25 +#define kCFCoreFoundationVersionNumber10_4_6_Intel 368.26 +#define kCFCoreFoundationVersionNumber10_4_6_PowerPC 368.25 +#define kCFCoreFoundationVersionNumber10_4_7 368.27 +#define kCFCoreFoundationVersionNumber10_4_8 368.27 +#define kCFCoreFoundationVersionNumber10_4_9 368.28 +#define kCFCoreFoundationVersionNumber10_4_10 368.28 +#define kCFCoreFoundationVersionNumber10_4_11 368.31 +#define kCFCoreFoundationVersionNumber10_5 476.00 +#define kCFCoreFoundationVersionNumber10_5_1 476.00 +#define kCFCoreFoundationVersionNumber10_5_2 476.10 +#define kCFCoreFoundationVersionNumber10_5_3 476.13 +#define kCFCoreFoundationVersionNumber10_5_4 476.14 +#define kCFCoreFoundationVersionNumber10_5_5 476.15 +#define kCFCoreFoundationVersionNumber10_5_6 476.17 +#define kCFCoreFoundationVersionNumber10_5_7 476.18 +#define kCFCoreFoundationVersionNumber10_5_8 476.19 +#define kCFCoreFoundationVersionNumber10_6 550.00 +#define kCFCoreFoundationVersionNumber10_6_1 550.00 +#define kCFCoreFoundationVersionNumber10_6_2 550.13 +#define kCFCoreFoundationVersionNumber10_6_3 550.19 +#define kCFCoreFoundationVersionNumber10_6_4 550.29 +#define kCFCoreFoundationVersionNumber10_6_5 550.42 +#define kCFCoreFoundationVersionNumber10_6_6 550.42 +#define kCFCoreFoundationVersionNumber10_6_7 550.42 +#define kCFCoreFoundationVersionNumber10_6_8 550.43 +#define kCFCoreFoundationVersionNumber10_7 635.00 +#define kCFCoreFoundationVersionNumber10_7_1 635.00 +#define kCFCoreFoundationVersionNumber10_7_2 635.15 +#define kCFCoreFoundationVersionNumber10_7_3 635.19 +#define kCFCoreFoundationVersionNumber10_7_4 635.21 +#define kCFCoreFoundationVersionNumber10_7_5 635.21 +#define kCFCoreFoundationVersionNumber10_8 744.00 +#define kCFCoreFoundationVersionNumber10_8_1 744.00 +#define kCFCoreFoundationVersionNumber10_8_2 744.12 +#define kCFCoreFoundationVersionNumber10_8_3 744.18 +#define kCFCoreFoundationVersionNumber10_8_4 744.19 +#define kCFCoreFoundationVersionNumber10_9 855.11 +#define kCFCoreFoundationVersionNumber10_9_1 855.11 +#define kCFCoreFoundationVersionNumber10_9_2 855.14 +#define kCFCoreFoundationVersionNumber10_10 1151.16 +#define kCFCoreFoundationVersionNumber10_10_1 1151.16 +#define kCFCoreFoundationVersionNumber10_10_2 1152 +#define kCFCoreFoundationVersionNumber10_10_3 1153.18 +#define kCFCoreFoundationVersionNumber10_10_4 1153.18 +#define kCFCoreFoundationVersionNumber10_10_5 1153.18 +#define kCFCoreFoundationVersionNumber10_10_Max 1199 +#define kCFCoreFoundationVersionNumber10_11 1253 +#define kCFCoreFoundationVersionNumber10_11_1 1255.1 +#define kCFCoreFoundationVersionNumber10_11_2 1256.14 +#define kCFCoreFoundationVersionNumber10_11_3 1256.14 +#define kCFCoreFoundationVersionNumber10_11_4 1258.1 +#define kCFCoreFoundationVersionNumber10_11_Max 1299 +#endif + +#if TARGET_OS_IPHONE +#define kCFCoreFoundationVersionNumber_iPhoneOS_2_0 478.23 +#define kCFCoreFoundationVersionNumber_iPhoneOS_2_1 478.26 +#define kCFCoreFoundationVersionNumber_iPhoneOS_2_2 478.29 +#define kCFCoreFoundationVersionNumber_iPhoneOS_3_0 478.47 +#define kCFCoreFoundationVersionNumber_iPhoneOS_3_1 478.52 +#define kCFCoreFoundationVersionNumber_iPhoneOS_3_2 478.61 +#define kCFCoreFoundationVersionNumber_iOS_4_0 550.32 +#define kCFCoreFoundationVersionNumber_iOS_4_1 550.38 +#define kCFCoreFoundationVersionNumber_iOS_4_2 550.52 +#define kCFCoreFoundationVersionNumber_iOS_4_3 550.52 +#define kCFCoreFoundationVersionNumber_iOS_5_0 675.00 +#define kCFCoreFoundationVersionNumber_iOS_5_1 690.10 +#define kCFCoreFoundationVersionNumber_iOS_6_0 793.00 +#define kCFCoreFoundationVersionNumber_iOS_6_1 793.00 +#define kCFCoreFoundationVersionNumber_iOS_7_0 847.20 +#define kCFCoreFoundationVersionNumber_iOS_7_1 847.24 +#define kCFCoreFoundationVersionNumber_iOS_8_0 1140.1 +#define kCFCoreFoundationVersionNumber_iOS_8_1 1141.14 +#define kCFCoreFoundationVersionNumber_iOS_8_2 1142.16 +#define kCFCoreFoundationVersionNumber_iOS_8_3 1144.17 +#define kCFCoreFoundationVersionNumber_iOS_8_4 1145.15 +#define kCFCoreFoundationVersionNumber_iOS_8_x_Max 1199 +#define kCFCoreFoundationVersionNumber_iOS_9_0 1240.1 +#define kCFCoreFoundationVersionNumber_iOS_9_1 1241.11 +#define kCFCoreFoundationVersionNumber_iOS_9_2 1242.13 +#define kCFCoreFoundationVersionNumber_iOS_9_3 1242.13 +#define kCFCoreFoundationVersionNumber_iOS_9_4 1280.38 +#define kCFCoreFoundationVersionNumber_iOS_9_x_Max 1299 +#endif + +#if __LLP64__ +typedef unsigned long long CFTypeID; +typedef unsigned long long CFOptionFlags; +typedef unsigned long long CFHashCode; +typedef signed long long CFIndex; +#else +typedef unsigned long CFTypeID; +typedef unsigned long CFOptionFlags; +typedef unsigned long CFHashCode; +typedef signed long CFIndex; +#endif + +/* Base "type" of all "CF objects", and polymorphic functions on them */ +typedef const CF_BRIDGED_TYPE(id) void * CFTypeRef; + +typedef const struct CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef; +typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableString) __CFString * CFMutableStringRef; + +/* + Type to mean any instance of a property list type; + currently, CFString, CFData, CFNumber, CFBoolean, CFDate, + CFArray, and CFDictionary. +*/ +typedef CF_BRIDGED_TYPE(id) CFTypeRef CFPropertyListRef; + +/* Values returned from comparison functions */ +typedef CF_ENUM(CFIndex, CFComparisonResult) { + kCFCompareLessThan = -1L, + kCFCompareEqualTo = 0, + kCFCompareGreaterThan = 1 +}; + +/* A standard comparison function */ +typedef CFComparisonResult (*CFComparatorFunction)(const void *val1, const void *val2, void *context); + +/* Constant used by some functions to indicate failed searches. */ +static const CFIndex kCFNotFound = -1; + + +/* Range type */ +typedef struct { + CFIndex location; + CFIndex length; +} CFRange; + +#if defined(CF_INLINE) +CF_INLINE CFRange CFRangeMake(CFIndex loc, CFIndex len) { + CFRange range; + range.location = loc; + range.length = len; + return range; +} +#else +#define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN) +#endif + +/* Private; do not use */ +CF_EXPORT +CFRange __CFRangeMake(CFIndex loc, CFIndex len); + + +/* Null representant */ + +typedef const struct CF_BRIDGED_TYPE(NSNull) __CFNull * CFNullRef; + +CF_EXPORT +CFTypeID CFNullGetTypeID(void); + +CF_EXPORT +const CFNullRef kCFNull; // the singleton null instance + + +/* Allocator API + + Most of the time when specifying an allocator to Create functions, the NULL + argument indicates "use the default"; this is the same as using kCFAllocatorDefault + or the return value from CFAllocatorGetDefault(). This assures that you will use + the allocator in effect at that time. +*/ +typedef const struct CF_BRIDGED_TYPE(id) __CFAllocator * CFAllocatorRef; + +/* This is a synonym for NULL, if you'd rather use a named constant. */ +CF_EXPORT +const CFAllocatorRef kCFAllocatorDefault; + +/* Default system allocator; you rarely need to use this. */ +CF_EXPORT +const CFAllocatorRef kCFAllocatorSystemDefault; + +/* This allocator uses malloc(), realloc(), and free(). This should not be + generally used; stick to kCFAllocatorDefault whenever possible. This + allocator is useful as the "bytesDeallocator" in CFData or + "contentsDeallocator" in CFString where the memory was obtained as a + result of malloc() type functions. +*/ +CF_EXPORT +const CFAllocatorRef kCFAllocatorMalloc; + +/* This allocator explicitly uses the default malloc zone, returned by + malloc_default_zone(). It should only be used when an object is + safe to be allocated in non-scanned memory. + */ +CF_EXPORT +const CFAllocatorRef kCFAllocatorMallocZone; + +/* Null allocator which does nothing and allocates no memory. This allocator + is useful as the "bytesDeallocator" in CFData or "contentsDeallocator" + in CFString where the memory should not be freed. +*/ +CF_EXPORT +const CFAllocatorRef kCFAllocatorNull; + +/* Special allocator argument to CFAllocatorCreate() which means + "use the functions given in the context to allocate the allocator + itself as well". +*/ +CF_EXPORT +const CFAllocatorRef kCFAllocatorUseContext; + +typedef const void * (*CFAllocatorRetainCallBack)(const void *info); +typedef void (*CFAllocatorReleaseCallBack)(const void *info); +typedef CFStringRef (*CFAllocatorCopyDescriptionCallBack)(const void *info); +typedef void * (*CFAllocatorAllocateCallBack)(CFIndex allocSize, CFOptionFlags hint, void *info); +typedef void * (*CFAllocatorReallocateCallBack)(void *ptr, CFIndex newsize, CFOptionFlags hint, void *info); +typedef void (*CFAllocatorDeallocateCallBack)(void *ptr, void *info); +typedef CFIndex (*CFAllocatorPreferredSizeCallBack)(CFIndex size, CFOptionFlags hint, void *info); +typedef struct { + CFIndex version; + void * info; + CFAllocatorRetainCallBack retain; + CFAllocatorReleaseCallBack release; + CFAllocatorCopyDescriptionCallBack copyDescription; + CFAllocatorAllocateCallBack allocate; + CFAllocatorReallocateCallBack reallocate; + CFAllocatorDeallocateCallBack deallocate; + CFAllocatorPreferredSizeCallBack preferredSize; +} CFAllocatorContext; + +CF_EXPORT +CFTypeID CFAllocatorGetTypeID(void); + +/* + CFAllocatorSetDefault() sets the allocator that is used in the current + thread whenever NULL is specified as an allocator argument. This means + that most, if not all allocations will go through this allocator. It + also means that any allocator set as the default needs to be ready to + deal with arbitrary memory allocation requests; in addition, the size + and number of requests will change between releases. + + An allocator set as the default will never be released, even if later + another allocator replaces it as the default. Not only is it impractical + for it to be released (as there might be caches created under the covers + that refer to the allocator), in general it's also safer and more + efficient to keep it around. + + If you wish to use a custom allocator in a context, it's best to provide + it as the argument to the various creation functions rather than setting + it as the default. Setting the default allocator is not encouraged. + + If you do set an allocator as the default, either do it for all time in + your app, or do it in a nested fashion (by restoring the previous allocator + when you exit your context). The latter might be appropriate for plug-ins + or libraries that wish to set the default allocator. +*/ +CF_EXPORT +void CFAllocatorSetDefault(CFAllocatorRef allocator); + +CF_EXPORT +CFAllocatorRef CFAllocatorGetDefault(void); + +CF_EXPORT +CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *context); + +CF_EXPORT +void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint); + +CF_EXPORT +void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize, CFOptionFlags hint); + +CF_EXPORT +void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr); + +CF_EXPORT +CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint); + +CF_EXPORT +void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context); + + +/* Polymorphic CF functions */ + +CF_IMPLICIT_BRIDGING_ENABLED + +CF_EXPORT +CFTypeID CFGetTypeID(CFTypeRef cf); + +CF_EXPORT +CFStringRef CFCopyTypeIDDescription(CFTypeID type_id); + +CF_EXPORT +CFTypeRef CFRetain(CFTypeRef cf); + +CF_EXPORT +void CFRelease(CFTypeRef cf); + +#if DEPLOYMENT_RUNTIME_SWIFT +#else +CF_EXPORT +CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) API_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0)); + +CF_EXPORT +CFIndex CFGetRetainCount(CFTypeRef cf); +#endif + +CF_EXPORT +Boolean CFEqual(CFTypeRef cf1, CFTypeRef cf2); + +CF_EXPORT +CFHashCode CFHash(CFTypeRef cf); + +CF_EXPORT +CFStringRef CFCopyDescription(CFTypeRef cf); + +CF_EXPORT +CFAllocatorRef CFGetAllocator(CFTypeRef cf); + +CF_IMPLICIT_BRIDGING_DISABLED + +// This function is unavailable in ARC mode. On OS X 10.12 and later, this function simply returns the argument. +CF_EXPORT +CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE; + +CF_EXTERN_C_END + +#if DEPLOYMENT_RUNTIME_SWIFT + +#if TARGET_RT_64_BIT +#define _CF_SWIFT_RC_PINNED_FLAG (0x80000004ffffffff) +#else +#define _CF_SWIFT_RC_PINNED_FLAG (0x800004FF) +#endif +#define _CF_CONSTANT_OBJECT_STRONG_RC ((uintptr_t)_CF_SWIFT_RC_PINNED_FLAG) +#endif + +#if __has_include() +#include +#endif + +#ifndef __ptrauth_objc_isa_pointer +#define __ptrauth_objc_isa_pointer +#endif + +#define ISA_PTRAUTH_DISCRIMINATOR 0x6AE1 +#if defined(__ptrauth_objc_isa_uintptr) +#define __ptrauth_cf_objc_isa_pointer __ptrauth_objc_isa_uintptr +#elif defined(__arm64e__) && defined(__PTRAUTH_INTRINSICS__) && __has_feature(ptrauth_objc_isa) +#define __ptrauth_cf_objc_isa_pointer __ptrauth_restricted_intptr(ptrauth_key_objc_isa_pointer, 1, ISA_PTRAUTH_DISCRIMINATOR) +#else +#define __ptrauth_cf_objc_isa_pointer +#endif + +#endif /* ! __COREFOUNDATION_CFBASE__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFCharacterSet.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFCharacterSet.h new file mode 100644 index 0000000..c7bd104 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFCharacterSet.h @@ -0,0 +1,386 @@ +/* CFCharacterSet.h + Copyright (c) 1999-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +/*! + @header CFCharacterSet + CFCharacterSet represents a set, or a bag, of Unicode characters. + The API consists of 3 groups: + 1) creation/manipulation of CFCharacterSet instances, + 2) query of a single Unicode character membership, + and 3) bitmap representation related (reading/writing). + Conceptually, CFCharacterSet is a 136K byte bitmap array of + which each bit represents a Unicode code point. It could + contain the Unicode characters in ISO 10646 Basic Multilingual + Plane (BMP) and characters in Plane 1 through Plane 16 + accessible via surrogate paris in the Unicode Transformation + Format, 16-bit encoding form (UTF-16). In other words, it can + store values from 0x00000 to 0x10FFFF in the Unicode + Transformation Format, 32-bit encoding form (UTF-32). However, + in general, how CFCharacterSet stores the information is an + implementation detail. Note even CFData used for the external + bitmap representation rarely has 136K byte. For detailed + discussion of the external bitmap representation, refer to the + comments for CFCharacterSetCreateWithBitmapRepresentation below. + Note that the existence of non-BMP characters in a character set + does not imply the membership of the corresponding surrogate + characters. For example, a character set with U+10000 does not + match with U+D800. +*/ + +#if !defined(__COREFOUNDATION_CFCHARACTERSET__) +#define __COREFOUNDATION_CFCHARACTERSET__ 1 + +#include "CFBase.h" +#include "CFData.h" + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +/*! + @typedef CFCharacterSetRef + This is the type of a reference to immutable CFCharacterSets. +*/ +typedef const struct CF_BRIDGED_TYPE(NSCharacterSet) __CFCharacterSet * CFCharacterSetRef; + +/*! + @typedef CFMutableCharacterSetRef + This is the type of a reference to mutable CFMutableCharacterSets. +*/ +typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableCharacterSet) __CFCharacterSet * CFMutableCharacterSetRef; + +/*! + @typedef CFCharacterSetPredefinedSet + Type of the predefined CFCharacterSet selector values. +*/ + +typedef CF_ENUM(CFIndex, CFCharacterSetPredefinedSet) { + kCFCharacterSetControl = 1, /* Control character set (Unicode General Category Cc and Cf) */ + kCFCharacterSetWhitespace, /* Whitespace character set (Unicode General Category Zs and U0009 CHARACTER TABULATION) */ + kCFCharacterSetWhitespaceAndNewline, /* Whitespace and Newline character set (Unicode General Category Z*, U000A ~ U000D, and U0085) */ + kCFCharacterSetDecimalDigit, /* Decimal digit character set */ + kCFCharacterSetLetter, /* Letter character set (Unicode General Category L* & M*) */ + kCFCharacterSetLowercaseLetter, /* Lowercase character set (Unicode General Category Ll) */ + kCFCharacterSetUppercaseLetter, /* Uppercase character set (Unicode General Category Lu and Lt) */ + kCFCharacterSetNonBase, /* Non-base character set (Unicode General Category M*) */ + kCFCharacterSetDecomposable, /* Canonically decomposable character set */ + kCFCharacterSetAlphaNumeric, /* Alpha Numeric character set (Unicode General Category L*, M*, & N*) */ + kCFCharacterSetPunctuation, /* Punctuation character set (Unicode General Category P*) */ + kCFCharacterSetCapitalizedLetter = 13, /* Titlecase character set (Unicode General Category Lt) */ + kCFCharacterSetSymbol = 14, /* Symbol character set (Unicode General Category S*) */ + kCFCharacterSetNewline API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 15, /* Newline character set (U000A ~ U000D, U0085, U2028, and U2029) */ + kCFCharacterSetIllegal = 12/* Illegal character set */ +}; + +/*! + @function CFCharacterSetGetTypeID + Returns the type identifier of all CFCharacterSet instances. +*/ +CF_EXPORT +CFTypeID CFCharacterSetGetTypeID(void); + +/*! + @function CFCharacterSetGetPredefined + Returns a predefined CFCharacterSet instance. + @param theSetIdentifier The CFCharacterSetPredefinedSet selector + which specifies the predefined character set. If the + value is not in CFCharacterSetPredefinedSet, the behavior + is undefined. + @result A reference to the predefined immutable CFCharacterSet. + This instance is owned by CF. +*/ +CF_EXPORT +CFCharacterSetRef CFCharacterSetGetPredefined(CFCharacterSetPredefinedSet theSetIdentifier); + +/*! + @function CFCharacterSetCreateWithCharactersInRange + Creates a new immutable character set with the values from the given range. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theRange The CFRange which should be used to specify the + Unicode range the character set is filled with. It + accepts the range in 32-bit in the UTF-32 format. The + valid character point range is from 0x00000 to 0x10FFFF. + If the range is outside of the valid Unicode character + point, the behavior is undefined. + @result A reference to the new immutable CFCharacterSet. +*/ +CF_EXPORT +CFCharacterSetRef CFCharacterSetCreateWithCharactersInRange(CFAllocatorRef alloc, CFRange theRange); + +/*! + @function CFCharacterSetCreateWithCharactersInString + Creates a new immutable character set with the values in the given string. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theString The CFString which should be used to specify + the Unicode characters the character set is filled with. + If this parameter is not a valid CFString, the behavior + is undefined. + @result A reference to the new immutable CFCharacterSet. +*/ +CF_EXPORT +CFCharacterSetRef CFCharacterSetCreateWithCharactersInString(CFAllocatorRef alloc, CFStringRef theString); + +/*! + @function CFCharacterSetCreateWithBitmapRepresentation + Creates a new immutable character set with the bitmap representation in the given data. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theData The CFData which should be used to specify the + bitmap representation of the Unicode character points + the character set is filled with. The bitmap + representation could contain all the Unicode character + range starting from BMP to Plane 16. The first 8192 bytes + of the data represent the BMP range. The BMP range 8192 + bytes can be followed by zero to sixteen 8192 byte + bitmaps, each one with the plane index byte prepended. + For example, the bitmap representing the BMP and Plane 2 + has the size of 16385 bytes (8192 bytes for BMP, 1 byte + index + 8192 bytes bitmap for Plane 2). The plane index + byte, in this case, contains the integer value two. If + this parameter is not a valid CFData or it contains a + Plane index byte outside of the valid Plane range + (1 to 16), the behavior is undefined. + @result A reference to the new immutable CFCharacterSet. +*/ +CF_EXPORT +CFCharacterSetRef CFCharacterSetCreateWithBitmapRepresentation(CFAllocatorRef alloc, CFDataRef theData); + +/*! + @function CFCharacterSetCreateInvertedSet + Creates a new immutable character set that is the invert of the specified character set. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theSet The CFCharacterSet which is to be inverted. If this + parameter is not a valid CFCharacterSet, the behavior is + undefined. + @result A reference to the new immutable CFCharacterSet. +*/ +CF_EXPORT CFCharacterSetRef CFCharacterSetCreateInvertedSet(CFAllocatorRef alloc, CFCharacterSetRef theSet); + +/*! + @function CFCharacterSetIsSupersetOfSet + Reports whether or not the character set is a superset of the character set specified as the second parameter. + @param theSet The character set to be checked for the membership of theOtherSet. + If this parameter is not a valid CFCharacterSet, the behavior is undefined. + @param theOtherSet The character set to be checked whether or not it is a subset of theSet. + If this parameter is not a valid CFCharacterSet, the behavior is undefined. +*/ +CF_EXPORT Boolean CFCharacterSetIsSupersetOfSet(CFCharacterSetRef theSet, CFCharacterSetRef theOtherSet); + +/*! + @function CFCharacterSetHasMemberInPlane + Reports whether or not the character set contains at least one member character in the specified plane. + @param theSet The character set to be checked for the membership. If this + parameter is not a valid CFCharacterSet, the behavior is undefined. + @param thePlane The plane number to be checked for the membership. + The valid value range is from 0 to 16. If the value is outside of the valid + plane number range, the behavior is undefined. +*/ +CF_EXPORT Boolean CFCharacterSetHasMemberInPlane(CFCharacterSetRef theSet, CFIndex thePlane); + +/*! + @function CFCharacterSetCreateMutable + Creates a new empty mutable character set. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @result A reference to the new mutable CFCharacterSet. +*/ +CF_EXPORT +CFMutableCharacterSetRef CFCharacterSetCreateMutable(CFAllocatorRef alloc); + +/*! + @function CFCharacterSetCreateCopy + Creates a new character set with the values from the given character set. This function tries to compact the backing store where applicable. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theSet The CFCharacterSet which is to be copied. If this + parameter is not a valid CFCharacterSet, the behavior is + undefined. + @result A reference to the new CFCharacterSet. +*/ +CF_EXPORT +CFCharacterSetRef CFCharacterSetCreateCopy(CFAllocatorRef alloc, CFCharacterSetRef theSet); + +/*! + @function CFCharacterSetCreateMutableCopy + Creates a new mutable character set with the values from the given character set. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theSet The CFCharacterSet which is to be copied. If this + parameter is not a valid CFCharacterSet, the behavior is + undefined. + @result A reference to the new mutable CFCharacterSet. +*/ +CF_EXPORT +CFMutableCharacterSetRef CFCharacterSetCreateMutableCopy(CFAllocatorRef alloc, CFCharacterSetRef theSet); + +/*! + @function CFCharacterSetIsCharacterMember + Reports whether or not the Unicode character is in the character set. + @param theSet The character set to be searched. If this parameter + is not a valid CFCharacterSet, the behavior is undefined. + @param theChar The Unicode character for which to test against the + character set. Note that this function takes 16-bit Unicode + character value; hence, it does not support access to the + non-BMP planes. + @result true, if the value is in the character set, otherwise false. +*/ +CF_EXPORT +Boolean CFCharacterSetIsCharacterMember(CFCharacterSetRef theSet, UniChar theChar); + +/*! + @function CFCharacterSetIsLongCharacterMember + Reports whether or not the UTF-32 character is in the character set. + @param theSet The character set to be searched. If this parameter + is not a valid CFCharacterSet, the behavior is undefined. + @param theChar The UTF-32 character for which to test against the + character set. + @result true, if the value is in the character set, otherwise false. +*/ +CF_EXPORT Boolean CFCharacterSetIsLongCharacterMember(CFCharacterSetRef theSet, UTF32Char theChar); + +/*! + @function CFCharacterSetCreateBitmapRepresentation + Creates a new immutable data with the bitmap representation from the given character set. + @param alloc The CFAllocator which should be used to allocate + memory for the array and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theSet The CFCharacterSet which is to be used create the + bitmap representation from. Refer to the comments for + CFCharacterSetCreateWithBitmapRepresentation for the + detailed discussion of the bitmap representation format. + If this parameter is not a valid CFCharacterSet, the + behavior is undefined. + @result A reference to the new immutable CFData. +*/ +CF_EXPORT +CFDataRef CFCharacterSetCreateBitmapRepresentation(CFAllocatorRef alloc, CFCharacterSetRef theSet); + +/*! + @function CFCharacterSetAddCharactersInRange + Adds the given range to the character set. + @param theSet The character set to which the range is to be added. + If this parameter is not a valid mutable CFCharacterSet, + the behavior is undefined. + @param theRange The range to add to the character set. It accepts + the range in 32-bit in the UTF-32 format. The valid + character point range is from 0x00000 to 0x10FFFF. If the + range is outside of the valid Unicode character point, + the behavior is undefined. +*/ +CF_EXPORT +void CFCharacterSetAddCharactersInRange(CFMutableCharacterSetRef theSet, CFRange theRange); + +/*! + @function CFCharacterSetRemoveCharactersInRange + Removes the given range from the charaacter set. + @param theSet The character set from which the range is to be + removed. If this parameter is not a valid mutable + CFCharacterSet, the behavior is undefined. + @param theRange The range to remove from the character set. + It accepts the range in 32-bit in the UTF-32 format. + The valid character point range is from 0x00000 to 0x10FFFF. + If the range is outside of the valid Unicode character point, + the behavior is undefined. +*/ +CF_EXPORT +void CFCharacterSetRemoveCharactersInRange(CFMutableCharacterSetRef theSet, CFRange theRange); + +/*! + @function CFCharacterSetAddCharactersInString + Adds the characters in the given string to the charaacter set. + @param theSet The character set to which the characters in the + string are to be added. If this parameter is not a + valid mutable CFCharacterSet, the behavior is undefined. + @param theString The string to add to the character set. + If this parameter is not a valid CFString, the behavior + is undefined. +*/ +CF_EXPORT +void CFCharacterSetAddCharactersInString(CFMutableCharacterSetRef theSet, CFStringRef theString); + +/*! + @function CFCharacterSetRemoveCharactersInString + Removes the characters in the given string from the charaacter set. + @param theSet The character set from which the characters in the + string are to be remove. If this parameter is not a + valid mutable CFCharacterSet, the behavior is undefined. + @param theString The string to remove from the character set. + If this parameter is not a valid CFString, the behavior + is undefined. +*/ +CF_EXPORT +void CFCharacterSetRemoveCharactersInString(CFMutableCharacterSetRef theSet, CFStringRef theString); + +/*! + @function CFCharacterSetUnion + Forms the union with the given character set. + @param theSet The destination character set into which the + union of the two character sets is stored. If this + parameter is not a valid mutable CFCharacterSet, the + behavior is undefined. + @param theOtherSet The character set with which the union is + formed. If this parameter is not a valid CFCharacterSet, + the behavior is undefined. +*/ +CF_EXPORT +void CFCharacterSetUnion(CFMutableCharacterSetRef theSet, CFCharacterSetRef theOtherSet); + +/*! + @function CFCharacterSetIntersect + Forms the intersection with the given character set. + @param theSet The destination character set into which the + intersection of the two character sets is stored. + If this parameter is not a valid mutable CFCharacterSet, + the behavior is undefined. + @param theOtherSet The character set with which the intersection + is formed. If this parameter is not a valid CFCharacterSet, + the behavior is undefined. +*/ +CF_EXPORT +void CFCharacterSetIntersect(CFMutableCharacterSetRef theSet, CFCharacterSetRef theOtherSet); + +/*! + @function CFCharacterSetInvert + Inverts the content of the given character set. + @param theSet The character set to be inverted. + If this parameter is not a valid mutable CFCharacterSet, + the behavior is undefined. +*/ +CF_EXPORT +void CFCharacterSetInvert(CFMutableCharacterSetRef theSet); + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFCHARACTERSET__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFData.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFData.h new file mode 100644 index 0000000..3c73a1e --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFData.h @@ -0,0 +1,78 @@ +/* CFData.h + Copyright (c) 1998-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFDATA__) +#define __COREFOUNDATION_CFDATA__ 1 + +#include "CFBase.h" + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +typedef const struct CF_BRIDGED_TYPE(NSData) __CFData * CFDataRef; +typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableData) __CFData * CFMutableDataRef; + +CF_EXPORT +CFTypeID CFDataGetTypeID(void); + +CF_EXPORT +CFDataRef CFDataCreate(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length); + +CF_EXPORT +CFDataRef CFDataCreateWithBytesNoCopy(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length, CFAllocatorRef bytesDeallocator); + /* Pass kCFAllocatorNull as bytesDeallocator to assure the bytes aren't freed */ + +CF_EXPORT +CFDataRef CFDataCreateCopy(CFAllocatorRef allocator, CFDataRef theData); + +CF_EXPORT +CFMutableDataRef CFDataCreateMutable(CFAllocatorRef allocator, CFIndex capacity); + +CF_EXPORT +CFMutableDataRef CFDataCreateMutableCopy(CFAllocatorRef allocator, CFIndex capacity, CFDataRef theData); + +CF_EXPORT +CFIndex CFDataGetLength(CFDataRef theData); + +CF_EXPORT +const UInt8 *CFDataGetBytePtr(CFDataRef theData); + +CF_EXPORT +UInt8 *CFDataGetMutableBytePtr(CFMutableDataRef theData); + +CF_EXPORT +void CFDataGetBytes(CFDataRef theData, CFRange range, UInt8 *buffer); + +CF_EXPORT +void CFDataSetLength(CFMutableDataRef theData, CFIndex length); + +CF_EXPORT +void CFDataIncreaseLength(CFMutableDataRef theData, CFIndex extraLength); + +CF_EXPORT +void CFDataAppendBytes(CFMutableDataRef theData, const UInt8 *bytes, CFIndex length); + +CF_EXPORT +void CFDataReplaceBytes(CFMutableDataRef theData, CFRange range, const UInt8 *newBytes, CFIndex newLength); + +CF_EXPORT +void CFDataDeleteBytes(CFMutableDataRef theData, CFRange range); + +typedef CF_OPTIONS(CFOptionFlags, CFDataSearchFlags) { + kCFDataSearchBackwards = 1UL << 0, + kCFDataSearchAnchored = 1UL << 1 +} API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)); + +CF_EXPORT +CFRange CFDataFind(CFDataRef theData, CFDataRef dataToFind, CFRange searchRange, CFDataSearchFlags compareOptions) API_AVAILABLE(macos(10.6), ios(4.0), watchos(2.0), tvos(9.0)); + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFDATA__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFDictionary.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFDictionary.h new file mode 100644 index 0000000..c8a8dfb --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFDictionary.h @@ -0,0 +1,673 @@ +/* CFDictionary.h + Copyright (c) 1998-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +/*! + @header CFDictionary + CFDictionary implements a container which pairs pointer-sized keys + with pointer-sized values. Values are accessed via arbitrary + user-defined keys. A CFDictionary differs from a CFArray in that + the key used to access a particular value in the dictionary remains + the same as values are added to or removed from the dictionary, + unless a value associated with its particular key is replaced or + removed. In a CFArray, the key (or index) used to retrieve a + particular value can change over time as values are added to or + deleted from the array. Also unlike an array, there is no ordering + among values in a dictionary. To enable later retrieval of a value, + the key of the key-value pair should be constant (or treated as + constant); if the key changes after being used to put a value in + the dictionary, the value may not be retrievable. The keys of a + dictionary form a set; that is, no two keys which are equal to + one another are present in the dictionary at any time. + + Dictionaries come in two flavors, immutable, which cannot have + values added to them or removed from them after the dictionary is + created, and mutable, to which you can add values or from which + remove values. Mutable dictionaries can have an unlimited number + of values (or rather, limited only by constraints external to + CFDictionary, like the amount of available memory). + + As with all CoreFoundation collection types, dictionaries maintain + hard references on the values you put in them, but the retaining and + releasing functions are user-defined callbacks that can actually do + whatever the user wants (for example, nothing). + + Although a particular implementation of CFDictionary may not use + hashing and a hash table for storage of the values, the keys have + a hash-code generating function defined for them, and a function + to test for equality of two keys. These two functions together + must maintain the invariant that if equal(X, Y), then hash(X) == + hash(Y). Note that the converse will not generally be true (but + the contrapositive, if hash(X) != hash(Y), then !equal(X, Y), + will be as required by Boolean logic). If the hash() and equal() + key callbacks are NULL, the key is used as a pointer-sized integer, + and pointer equality is used. Care should be taken to provide a + hash() callback which will compute sufficiently dispersed hash + codes for the key set for best performance. + + Computational Complexity + The access time for a value in the dictionary is guaranteed to be at + worst O(N) for any implementation, current and future, but will + often be O(1) (constant time). Insertion or deletion operations + will typically be constant time as well, but are O(N*N) in the + worst case in some implementations. Access of values through a key + is faster than accessing values directly (if there are any such + operations). Dictionaries will tend to use significantly more memory + than a array with the same number of values. +*/ + +#if !defined(__COREFOUNDATION_CFDICTIONARY__) +#define __COREFOUNDATION_CFDICTIONARY__ 1 + +#include "CFBase.h" + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +/*! + @typedef CFDictionaryKeyCallBacks + Structure containing the callbacks for keys of a CFDictionary. + @field version The version number of the structure type being passed + in as a parameter to the CFDictionary creation functions. + This structure is version 0. + @field retain The callback used to add a retain for the dictionary + on keys as they are used to put values into the dictionary. + This callback returns the value to use as the key in the + dictionary, which is usually the value parameter passed to + this callback, but may be a different value if a different + value should be used as the key. The dictionary's allocator + is passed as the first argument. + @field release The callback used to remove a retain previously added + for the dictionary from keys as their values are removed from + the dictionary. The dictionary's allocator is passed as the + first argument. + @field copyDescription The callback used to create a descriptive + string representation of each key in the dictionary. This + is used by the CFCopyDescription() function. + @field equal The callback used to compare keys in the dictionary for + equality. + @field hash The callback used to compute a hash code for keys as they + are used to access, add, or remove values in the dictionary. +*/ +typedef const void * (*CFDictionaryRetainCallBack)(CFAllocatorRef allocator, const void *value); +typedef void (*CFDictionaryReleaseCallBack)(CFAllocatorRef allocator, const void *value); +typedef CFStringRef (*CFDictionaryCopyDescriptionCallBack)(const void *value); +typedef Boolean (*CFDictionaryEqualCallBack)(const void *value1, const void *value2); +typedef CFHashCode (*CFDictionaryHashCallBack)(const void *value); +typedef struct { + CFIndex version; + CFDictionaryRetainCallBack retain; + CFDictionaryReleaseCallBack release; + CFDictionaryCopyDescriptionCallBack copyDescription; + CFDictionaryEqualCallBack equal; + CFDictionaryHashCallBack hash; +} CFDictionaryKeyCallBacks; + +/*! + @constant kCFTypeDictionaryKeyCallBacks + Predefined CFDictionaryKeyCallBacks structure containing a + set of callbacks appropriate for use when the keys of a + CFDictionary are all CFTypes. +*/ +CF_EXPORT +const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks; + +/*! + @constant kCFCopyStringDictionaryKeyCallBacks + Predefined CFDictionaryKeyCallBacks structure containing a + set of callbacks appropriate for use when the keys of a + CFDictionary are all CFStrings, which may be mutable and + need to be copied in order to serve as constant keys for + the values in the dictionary. +*/ +CF_EXPORT +const CFDictionaryKeyCallBacks kCFCopyStringDictionaryKeyCallBacks; + +/*! + @typedef CFDictionaryValueCallBacks + Structure containing the callbacks for values of a CFDictionary. + @field version The version number of the structure type being passed + in as a parameter to the CFDictionary creation functions. + This structure is version 0. + @field retain The callback used to add a retain for the dictionary + on values as they are put into the dictionary. + This callback returns the value to use as the value in the + dictionary, which is usually the value parameter passed to + this callback, but may be a different value if a different + value should be added to the dictionary. The dictionary's + allocator is passed as the first argument. + @field release The callback used to remove a retain previously added + for the dictionary from values as they are removed from + the dictionary. The dictionary's allocator is passed as the + first argument. + @field copyDescription The callback used to create a descriptive + string representation of each value in the dictionary. This + is used by the CFCopyDescription() function. + @field equal The callback used to compare values in the dictionary for + equality in some operations. +*/ +typedef struct { + CFIndex version; + CFDictionaryRetainCallBack retain; + CFDictionaryReleaseCallBack release; + CFDictionaryCopyDescriptionCallBack copyDescription; + CFDictionaryEqualCallBack equal; +} CFDictionaryValueCallBacks; + +/*! + @constant kCFTypeDictionaryValueCallBacks + Predefined CFDictionaryValueCallBacks structure containing a set + of callbacks appropriate for use when the values in a CFDictionary + are all CFTypes. +*/ +CF_EXPORT +const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks; + +/*! + @typedef CFDictionaryApplierFunction + Type of the callback function used by the apply functions of + CFDictionarys. + @param key The current key for the value. + @param value The current value from the dictionary. + @param context The user-defined context parameter given to the apply + function. +*/ +typedef void (*CFDictionaryApplierFunction)(const void *key, const void *value, void *context); + +/*! + @typedef CFDictionaryRef + This is the type of a reference to immutable CFDictionarys. +*/ +typedef const struct CF_BRIDGED_TYPE(NSDictionary) __CFDictionary * CFDictionaryRef; + +/*! + @typedef CFMutableDictionaryRef + This is the type of a reference to mutable CFDictionarys. +*/ +typedef struct CF_BRIDGED_MUTABLE_TYPE(NSMutableDictionary) __CFDictionary * CFMutableDictionaryRef; + +/*! + @function CFDictionaryGetTypeID + Returns the type identifier of all CFDictionary instances. +*/ +CF_EXPORT +CFTypeID CFDictionaryGetTypeID(void); + +/*! + @function CFDictionaryCreate + Creates a new immutable dictionary with the given values. + @param allocator The CFAllocator which should be used to allocate + memory for the dictionary and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param keys A C array of the pointer-sized keys to be used for + the parallel C array of values to be put into the dictionary. + This parameter may be NULL if the numValues parameter is 0. + This C array is not changed or freed by this function. If + this parameter is not a valid pointer to a C array of at + least numValues pointers, the behavior is undefined. + @param values A C array of the pointer-sized values to be in the + dictionary. This parameter may be NULL if the numValues + parameter is 0. This C array is not changed or freed by + this function. If this parameter is not a valid pointer to + a C array of at least numValues pointers, the behavior is + undefined. + @param numValues The number of values to copy from the keys and + values C arrays into the CFDictionary. This number will be + the count of the dictionary. If this parameter is + negative, or greater than the number of values actually + in the keys or values C arrays, the behavior is undefined. + @param keyCallBacks A pointer to a CFDictionaryKeyCallBacks structure + initialized with the callbacks for the dictionary to use on + each key in the dictionary. The retain callback will be used + within this function, for example, to retain all of the new + keys from the keys C array. A copy of the contents of the + callbacks structure is made, so that a pointer to a structure + on the stack can be passed in, or can be reused for multiple + dictionary creations. If the version field of this + callbacks structure is not one of the defined ones for + CFDictionary, the behavior is undefined. The retain field may + be NULL, in which case the CFDictionary will do nothing to add + a retain to the keys of the contained values. The release field + may be NULL, in which case the CFDictionary will do nothing + to remove the dictionary's retain (if any) on the keys when the + dictionary is destroyed or a key-value pair is removed. If the + copyDescription field is NULL, the dictionary will create a + simple description for a key. If the equal field is NULL, the + dictionary will use pointer equality to test for equality of + keys. If the hash field is NULL, a key will be converted from + a pointer to an integer to compute the hash code. This callbacks + parameter itself may be NULL, which is treated as if a valid + structure of version 0 with all fields NULL had been passed in. + Otherwise, if any of the fields are not valid pointers to + functions of the correct type, or this parameter is not a + valid pointer to a CFDictionaryKeyCallBacks callbacks structure, + the behavior is undefined. If any of the keys put into the + dictionary is not one understood by one of the callback functions + the behavior when that callback function is used is undefined. + @param valueCallBacks A pointer to a CFDictionaryValueCallBacks structure + initialized with the callbacks for the dictionary to use on + each value in the dictionary. The retain callback will be used + within this function, for example, to retain all of the new + values from the values C array. A copy of the contents of the + callbacks structure is made, so that a pointer to a structure + on the stack can be passed in, or can be reused for multiple + dictionary creations. If the version field of this callbacks + structure is not one of the defined ones for CFDictionary, the + behavior is undefined. The retain field may be NULL, in which + case the CFDictionary will do nothing to add a retain to values + as they are put into the dictionary. The release field may be + NULL, in which case the CFDictionary will do nothing to remove + the dictionary's retain (if any) on the values when the + dictionary is destroyed or a key-value pair is removed. If the + copyDescription field is NULL, the dictionary will create a + simple description for a value. If the equal field is NULL, the + dictionary will use pointer equality to test for equality of + values. This callbacks parameter itself may be NULL, which is + treated as if a valid structure of version 0 with all fields + NULL had been passed in. Otherwise, + if any of the fields are not valid pointers to functions + of the correct type, or this parameter is not a valid + pointer to a CFDictionaryValueCallBacks callbacks structure, + the behavior is undefined. If any of the values put into the + dictionary is not one understood by one of the callback functions + the behavior when that callback function is used is undefined. + @result A reference to the new immutable CFDictionary. +*/ +CF_EXPORT +CFDictionaryRef CFDictionaryCreate(CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks); + +/*! + @function CFDictionaryCreateCopy + Creates a new immutable dictionary with the key-value pairs from + the given dictionary. + @param allocator The CFAllocator which should be used to allocate + memory for the dictionary and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param theDict The dictionary which is to be copied. The keys and values + from the dictionary are copied as pointers into the new + dictionary (that is, the values themselves are copied, not + that which the values point to, if anything). However, the + keys and values are also retained by the new dictionary using + the retain function of the original dictionary. + The count of the new dictionary will be the same as the + given dictionary. The new dictionary uses the same callbacks + as the dictionary to be copied. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @result A reference to the new immutable CFDictionary. +*/ +CF_EXPORT +CFDictionaryRef CFDictionaryCreateCopy(CFAllocatorRef allocator, CFDictionaryRef theDict); + +/*! + @function CFDictionaryCreateMutable + Creates a new mutable dictionary. + @param allocator The CFAllocator which should be used to allocate + memory for the dictionary and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param capacity A hint about the number of values that will be held + by the CFDictionary. Pass 0 for no hint. The implementation may + ignore this hint, or may use it to optimize various + operations. A dictionary's actual capacity is only limited by + address space and available memory constraints). If this + parameter is negative, the behavior is undefined. + @param keyCallBacks A pointer to a CFDictionaryKeyCallBacks structure + initialized with the callbacks for the dictionary to use on + each key in the dictionary. A copy of the contents of the + callbacks structure is made, so that a pointer to a structure + on the stack can be passed in, or can be reused for multiple + dictionary creations. If the version field of this + callbacks structure is not one of the defined ones for + CFDictionary, the behavior is undefined. The retain field may + be NULL, in which case the CFDictionary will do nothing to add + a retain to the keys of the contained values. The release field + may be NULL, in which case the CFDictionary will do nothing + to remove the dictionary's retain (if any) on the keys when the + dictionary is destroyed or a key-value pair is removed. If the + copyDescription field is NULL, the dictionary will create a + simple description for a key. If the equal field is NULL, the + dictionary will use pointer equality to test for equality of + keys. If the hash field is NULL, a key will be converted from + a pointer to an integer to compute the hash code. This callbacks + parameter itself may be NULL, which is treated as if a valid + structure of version 0 with all fields NULL had been passed in. + Otherwise, if any of the fields are not valid pointers to + functions of the correct type, or this parameter is not a + valid pointer to a CFDictionaryKeyCallBacks callbacks structure, + the behavior is undefined. If any of the keys put into the + dictionary is not one understood by one of the callback functions + the behavior when that callback function is used is undefined. + @param valueCallBacks A pointer to a CFDictionaryValueCallBacks structure + initialized with the callbacks for the dictionary to use on + each value in the dictionary. The retain callback will be used + within this function, for example, to retain all of the new + values from the values C array. A copy of the contents of the + callbacks structure is made, so that a pointer to a structure + on the stack can be passed in, or can be reused for multiple + dictionary creations. If the version field of this callbacks + structure is not one of the defined ones for CFDictionary, the + behavior is undefined. The retain field may be NULL, in which + case the CFDictionary will do nothing to add a retain to values + as they are put into the dictionary. The release field may be + NULL, in which case the CFDictionary will do nothing to remove + the dictionary's retain (if any) on the values when the + dictionary is destroyed or a key-value pair is removed. If the + copyDescription field is NULL, the dictionary will create a + simple description for a value. If the equal field is NULL, the + dictionary will use pointer equality to test for equality of + values. This callbacks parameter itself may be NULL, which is + treated as if a valid structure of version 0 with all fields + NULL had been passed in. Otherwise, + if any of the fields are not valid pointers to functions + of the correct type, or this parameter is not a valid + pointer to a CFDictionaryValueCallBacks callbacks structure, + the behavior is undefined. If any of the values put into the + dictionary is not one understood by one of the callback functions + the behavior when that callback function is used is undefined. + @result A reference to the new mutable CFDictionary. +*/ +CF_EXPORT +CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks); + +/*! + @function CFDictionaryCreateMutableCopy + Creates a new mutable dictionary with the key-value pairs from + the given dictionary. + @param allocator The CFAllocator which should be used to allocate + memory for the dictionary and its storage for values. This + parameter may be NULL in which case the current default + CFAllocator is used. If this reference is not a valid + CFAllocator, the behavior is undefined. + @param capacity A hint about the number of values that will be held + by the CFDictionary. Pass 0 for no hint. The implementation may + ignore this hint, or may use it to optimize various + operations. A dictionary's actual capacity is only limited by + address space and available memory constraints). + This parameter must be greater than or equal + to the count of the dictionary which is to be copied, or the + behavior is undefined. If this parameter is negative, the + behavior is undefined. + @param theDict The dictionary which is to be copied. The keys and values + from the dictionary are copied as pointers into the new + dictionary (that is, the values themselves are copied, not + that which the values point to, if anything). However, the + keys and values are also retained by the new dictionary using + the retain function of the original dictionary. + The count of the new dictionary will be the same as the + given dictionary. The new dictionary uses the same callbacks + as the dictionary to be copied. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @result A reference to the new mutable CFDictionary. +*/ +CF_EXPORT +CFMutableDictionaryRef CFDictionaryCreateMutableCopy(CFAllocatorRef allocator, CFIndex capacity, CFDictionaryRef theDict); + +/*! + @function CFDictionaryGetCount + Returns the number of values currently in the dictionary. + @param theDict The dictionary to be queried. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @result The number of values in the dictionary. +*/ +CF_EXPORT +CFIndex CFDictionaryGetCount(CFDictionaryRef theDict); + +/*! + @function CFDictionaryGetCountOfKey + Counts the number of times the given key occurs in the dictionary. + @param theDict The dictionary to be searched. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param key The key for which to find matches in the dictionary. The + hash() and equal() key callbacks provided when the dictionary + was created are used to compare. If the hash() key callback + was NULL, the key is treated as a pointer and converted to + an integer. If the equal() key callback was NULL, pointer + equality (in C, ==) is used. If key, or any of the keys in + the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @result Returns 1 if a matching key is used by the dictionary, + 0 otherwise. +*/ +CF_EXPORT +CFIndex CFDictionaryGetCountOfKey(CFDictionaryRef theDict, const void *key); + +/*! + @function CFDictionaryGetCountOfValue + Counts the number of times the given value occurs in the dictionary. + @param theDict The dictionary to be searched. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param value The value for which to find matches in the dictionary. The + equal() callback provided when the dictionary was created is + used to compare. If the equal() value callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values in + the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @result The number of times the given value occurs in the dictionary. +*/ +CF_EXPORT +CFIndex CFDictionaryGetCountOfValue(CFDictionaryRef theDict, const void *value); + +/*! + @function CFDictionaryContainsKey + Reports whether or not the key is in the dictionary. + @param theDict The dictionary to be searched. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param key The key for which to find matches in the dictionary. The + hash() and equal() key callbacks provided when the dictionary + was created are used to compare. If the hash() key callback + was NULL, the key is treated as a pointer and converted to + an integer. If the equal() key callback was NULL, pointer + equality (in C, ==) is used. If key, or any of the keys in + the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @result true, if the key is in the dictionary, otherwise false. +*/ +CF_EXPORT +Boolean CFDictionaryContainsKey(CFDictionaryRef theDict, const void *key); + +/*! + @function CFDictionaryContainsValue + Reports whether or not the value is in the dictionary. + @param theDict The dictionary to be searched. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param value The value for which to find matches in the dictionary. The + equal() callback provided when the dictionary was created is + used to compare. If the equal() callback was NULL, pointer + equality (in C, ==) is used. If value, or any of the values + in the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @result true, if the value is in the dictionary, otherwise false. +*/ +CF_EXPORT +Boolean CFDictionaryContainsValue(CFDictionaryRef theDict, const void *value); + +/*! + @function CFDictionaryGetValue + Retrieves the value associated with the given key. + @param theDict The dictionary to be queried. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param key The key for which to find a match in the dictionary. The + hash() and equal() key callbacks provided when the dictionary + was created are used to compare. If the hash() key callback + was NULL, the key is treated as a pointer and converted to + an integer. If the equal() key callback was NULL, pointer + equality (in C, ==) is used. If key, or any of the keys in + the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @result The value with the given key in the dictionary, or NULL if + no key-value pair with a matching key exists. Since NULL + can be a valid value in some dictionaries, the function + CFDictionaryGetValueIfPresent() must be used to distinguish + NULL-no-found from NULL-is-the-value. +*/ +CF_EXPORT +const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key); + +/*! + @function CFDictionaryGetValueIfPresent + Retrieves the value associated with the given key. + @param theDict The dictionary to be queried. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param key The key for which to find a match in the dictionary. The + hash() and equal() key callbacks provided when the dictionary + was created are used to compare. If the hash() key callback + was NULL, the key is treated as a pointer and converted to + an integer. If the equal() key callback was NULL, pointer + equality (in C, ==) is used. If key, or any of the keys in + the dictionary, are not understood by the equal() callback, + the behavior is undefined. + @param value A pointer to memory which should be filled with the + pointer-sized value if a matching key is found. If no key + match is found, the contents of the storage pointed to by + this parameter are undefined. This parameter may be NULL, + in which case the value from the dictionary is not returned + (but the return value of this function still indicates + whether or not the key-value pair was present). + @result true, if a matching key was found, false otherwise. +*/ +CF_EXPORT +Boolean CFDictionaryGetValueIfPresent(CFDictionaryRef theDict, const void *key, const void **value); + +/*! + @function CFDictionaryGetKeysAndValues + Fills the two buffers with the keys and values from the dictionary. + @param theDict The dictionary to be queried. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param keys A C array of pointer-sized values to be filled with keys + from the dictionary. The keys and values C arrays are parallel + to each other (that is, the items at the same indices form a + key-value pair from the dictionary). This parameter may be NULL + if the keys are not desired. If this parameter is not a valid + pointer to a C array of at least CFDictionaryGetCount() pointers, + or NULL, the behavior is undefined. + @param values A C array of pointer-sized values to be filled with values + from the dictionary. The keys and values C arrays are parallel + to each other (that is, the items at the same indices form a + key-value pair from the dictionary). This parameter may be NULL + if the values are not desired. If this parameter is not a valid + pointer to a C array of at least CFDictionaryGetCount() pointers, + or NULL, the behavior is undefined. +*/ +CF_EXPORT +void CFDictionaryGetKeysAndValues(CFDictionaryRef theDict, const void **keys, const void **values); + +/*! + @function CFDictionaryApplyFunction + Calls a function once for each value in the dictionary. + @param theDict The dictionary to be queried. If this parameter is + not a valid CFDictionary, the behavior is undefined. + @param applier The callback function to call once for each value in + the dictionary. If this parameter is not a + pointer to a function of the correct prototype, the behavior + is undefined. If there are keys or values which the + applier function does not expect or cannot properly apply + to, the behavior is undefined. + @param context A pointer-sized user-defined value, which is passed + as the third parameter to the applier function, but is + otherwise unused by this function. If the context is not + what is expected by the applier function, the behavior is + undefined. +*/ +CF_EXPORT +void CFDictionaryApplyFunction(CFDictionaryRef theDict, CFDictionaryApplierFunction CF_NOESCAPE applier, void *context); + +/*! + @function CFDictionaryAddValue + Adds the key-value pair to the dictionary if no such key already exists. + @param theDict The dictionary to which the value is to be added. If this + parameter is not a valid mutable CFDictionary, the behavior is + undefined. + @param key The key of the value to add to the dictionary. The key is + retained by the dictionary using the retain callback provided + when the dictionary was created. If the key is not of the sort + expected by the retain callback, the behavior is undefined. If + a key which matches this key is already present in the dictionary, + this function does nothing ("add if absent"). + @param value The value to add to the dictionary. The value is retained + by the dictionary using the retain callback provided when the + dictionary was created. If the value is not of the sort expected + by the retain callback, the behavior is undefined. +*/ +CF_EXPORT +void CFDictionaryAddValue(CFMutableDictionaryRef theDict, const void *key, const void *value); + +/*! + @function CFDictionarySetValue + Sets the value of the key in the dictionary. + @param theDict The dictionary to which the value is to be set. If this + parameter is not a valid mutable CFDictionary, the behavior is + undefined. + @param key The key of the value to set into the dictionary. If a key + which matches this key is already present in the dictionary, only + the value is changed ("add if absent, replace if present"). If + no key matches the given key, the key-value pair is added to the + dictionary. If added, the key is retained by the dictionary, + using the retain callback provided + when the dictionary was created. If the key is not of the sort + expected by the key retain callback, the behavior is undefined. + @param value The value to add to or replace into the dictionary. The value + is retained by the dictionary using the retain callback provided + when the dictionary was created, and the previous value if any is + released. If the value is not of the sort expected by the + retain or release callbacks, the behavior is undefined. +*/ +CF_EXPORT +void CFDictionarySetValue(CFMutableDictionaryRef theDict, const void *key, const void *value); + +/*! + @function CFDictionaryReplaceValue + Replaces the value of the key in the dictionary. + @param theDict The dictionary to which the value is to be replaced. If this + parameter is not a valid mutable CFDictionary, the behavior is + undefined. + @param key The key of the value to replace in the dictionary. If a key + which matches this key is present in the dictionary, the value + is changed to the given value, otherwise this function does + nothing ("replace if present"). + @param value The value to replace into the dictionary. The value + is retained by the dictionary using the retain callback provided + when the dictionary was created, and the previous value is + released. If the value is not of the sort expected by the + retain or release callbacks, the behavior is undefined. +*/ +CF_EXPORT +void CFDictionaryReplaceValue(CFMutableDictionaryRef theDict, const void *key, const void *value); + +/*! + @function CFDictionaryRemoveValue + Removes the value of the key from the dictionary. + @param theDict The dictionary from which the value is to be removed. If this + parameter is not a valid mutable CFDictionary, the behavior is + undefined. + @param key The key of the value to remove from the dictionary. If a key + which matches this key is present in the dictionary, the key-value + pair is removed from the dictionary, otherwise this function does + nothing ("remove if present"). +*/ +CF_EXPORT +void CFDictionaryRemoveValue(CFMutableDictionaryRef theDict, const void *key); + +/*! + @function CFDictionaryRemoveAllValues + Removes all the values from the dictionary, making it empty. + @param theDict The dictionary from which all of the values are to be + removed. If this parameter is not a valid mutable + CFDictionary, the behavior is undefined. +*/ +CF_EXPORT +void CFDictionaryRemoveAllValues(CFMutableDictionaryRef theDict); + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFDICTIONARY__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFNumber.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFNumber.h new file mode 100644 index 0000000..6d91fac --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFNumber.h @@ -0,0 +1,128 @@ +/* CFNumber.h + Copyright (c) 1999-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFNUMBER__) +#define __COREFOUNDATION_CFNUMBER__ 1 + +#include "CFBase.h" + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +typedef const struct CF_BRIDGED_TYPE(NSNumber) __CFBoolean * CFBooleanRef; + +CF_EXPORT +const CFBooleanRef kCFBooleanTrue; +CF_EXPORT +const CFBooleanRef kCFBooleanFalse; + +CF_EXPORT +CFTypeID CFBooleanGetTypeID(void); + +CF_EXPORT +Boolean CFBooleanGetValue(CFBooleanRef boolean); + +typedef CF_ENUM(CFIndex, CFNumberType) { + /* Fixed-width types */ + kCFNumberSInt8Type = 1, + kCFNumberSInt16Type = 2, + kCFNumberSInt32Type = 3, + kCFNumberSInt64Type = 4, + kCFNumberFloat32Type = 5, + kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */ + /* Basic C types */ + kCFNumberCharType = 7, + kCFNumberShortType = 8, + kCFNumberIntType = 9, + kCFNumberLongType = 10, + kCFNumberLongLongType = 11, + kCFNumberFloatType = 12, + kCFNumberDoubleType = 13, + /* Other */ + kCFNumberCFIndexType = 14, + kCFNumberNSIntegerType API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 15, + kCFNumberCGFloatType API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 16, + kCFNumberMaxType = 16 +}; + +typedef const struct CF_BRIDGED_TYPE(NSNumber) __CFNumber * CFNumberRef; + +CF_EXPORT +const CFNumberRef kCFNumberPositiveInfinity; +CF_EXPORT +const CFNumberRef kCFNumberNegativeInfinity; +CF_EXPORT +const CFNumberRef kCFNumberNaN; + +CF_EXPORT +CFTypeID CFNumberGetTypeID(void); + +/* + Creates a CFNumber with the given value. The type of number pointed + to by the valuePtr is specified by type. If type is a floating point + type and the value represents one of the infinities or NaN, the + well-defined CFNumber for that value is returned. If either of + valuePtr or type is an invalid value, the result is undefined. +*/ +CF_EXPORT +CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); + +/* + Returns the storage format of the CFNumber's value. Note that + this is not necessarily the type provided in CFNumberCreate(). +*/ +CF_EXPORT +CFNumberType CFNumberGetType(CFNumberRef number); + +/* + Returns the size in bytes of the type of the number. +*/ +CF_EXPORT +CFIndex CFNumberGetByteSize(CFNumberRef number); + +/* + Returns true if the type of the CFNumber's value is one of + the defined floating point types. +*/ +CF_EXPORT +Boolean CFNumberIsFloatType(CFNumberRef number); + +/* + Copies the CFNumber's value into the space pointed to by + valuePtr, as the specified type. If conversion needs to take + place, the conversion rules follow human expectation and not + C's promotion and truncation rules. If the conversion is + lossy, or the value is out of range, false is returned. Best + attempt at conversion will still be in *valuePtr. +*/ +CF_EXPORT +Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr); + +/* + Compares the two CFNumber instances. If conversion of the + types of the values is needed, the conversion and comparison + follow human expectations and not C's promotion and comparison + rules. Negative zero compares less than positive zero. + Positive infinity compares greater than everything except + itself, to which it compares equal. Negative infinity compares + less than everything except itself, to which it compares equal. + Unlike standard practice, if both numbers are NaN, then they + compare equal; if only one of the numbers is NaN, then the NaN + compares greater than the other number if it is negative, and + smaller than the other number if it is positive. (Note that in + CFEqual() with two CFNumbers, if either or both of the numbers + is NaN, true is returned.) +*/ +CF_EXPORT +CFComparisonResult CFNumberCompare(CFNumberRef number, CFNumberRef otherNumber, void *context); + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFNUMBER__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFRuntime.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFRuntime.h new file mode 100644 index 0000000..887a7eb --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFRuntime.h @@ -0,0 +1,280 @@ +/* CFRuntime.h + Copyright (c) 1999-2019, Apple Inc. All rights reserved. + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFRUNTIME__) +#define __COREFOUNDATION_CFRUNTIME__ 1 + +#include "CFBase.h" +#include "CFDictionary.h" +#include + +#if __has_include() +#include +#endif + +#ifndef __ptrauth_cf_objc_isa_pointer +#define __ptrauth_cf_objc_isa_pointer +#endif + +#ifndef __ptrauth_objc_isa_pointer +#define __ptrauth_objc_isa_pointer +#endif + +CF_EXTERN_C_BEGIN + +#if (TARGET_OS_MAC && !TARGET_OS_IPHONE && !__x86_64h__) + +// Although we no longer support GC, we leave exported symbols in place for now to avoid any lockstep dependency issues. +CF_EXPORT bool kCFUseCollectableAllocator; +CF_EXPORT bool (*__CFObjCIsCollectable)(void *); + +#else + +#define kCFUseCollectableAllocator 0 +#define __CFObjCIsCollectable 0 + +#endif + + +CF_INLINE Boolean _CFAllocatorIsSystemDefault(CFAllocatorRef allocator) { + if (allocator == kCFAllocatorSystemDefault) return true; + if (NULL == allocator || kCFAllocatorDefault == allocator) { + return (kCFAllocatorSystemDefault == CFAllocatorGetDefault()); + } + return false; +} + +#define CF_USING_COLLECTABLE_MEMORY 0 +#define CF_IS_COLLECTABLE_ALLOCATOR(allocator) (0 && allocator) // prevent allocator from being claimed to be un-used +#define CF_IS_COLLECTABLE(obj) (0 && obj) // prevent obj from being claimed to be un-used + +enum { + _kCFRuntimeNotATypeID = 0 +}; + +enum { // Version field constants + _kCFRuntimeScannedObject = (1UL << 0), + _kCFRuntimeResourcefulObject = (1UL << 2), // tells CFRuntime to make use of the reclaim field + _kCFRuntimeCustomRefCount = (1UL << 3), // tells CFRuntime to make use of the refcount field + _kCFRuntimeRequiresAlignment = (1UL << 4), // tells CFRuntime to make use of the requiredAlignment field +}; + +typedef struct __CFRuntimeClass { + CFIndex version; + const char *className; // must be a pure ASCII string, nul-terminated + void (*init)(CFTypeRef cf); + CFTypeRef (*copy)(CFAllocatorRef allocator, CFTypeRef cf); + void (*finalize)(CFTypeRef cf); + Boolean (*equal)(CFTypeRef cf1, CFTypeRef cf2); + CFHashCode (*hash)(CFTypeRef cf); + CFStringRef (*copyFormattingDesc)(CFTypeRef cf, CFDictionaryRef formatOptions); // return str with retain + CFStringRef (*copyDebugDesc)(CFTypeRef cf); // return str with retain + +#define CF_RECLAIM_AVAILABLE 1 + void (*reclaim)(CFTypeRef cf); // Or in _kCFRuntimeResourcefulObject in the .version to indicate this field should be used + +#define CF_REFCOUNT_AVAILABLE 1 + uint32_t (*refcount)(intptr_t op, CFTypeRef cf); // Or in _kCFRuntimeCustomRefCount in the .version to indicate this field should be used + // this field must be non-NULL when _kCFRuntimeCustomRefCount is in the .version field + // - if the callback is passed 1 in 'op' it should increment the 'cf's reference count and return 0 + // - if the callback is passed 0 in 'op' it should return the 'cf's reference count, up to 32 bits + // - if the callback is passed -1 in 'op' it should decrement the 'cf's reference count; if it is now zero, 'cf' should be cleaned up and deallocated; then return 0 + // remember to use saturation arithmetic logic and stop incrementing and decrementing when the ref count hits UINT32_MAX, or you will have a security bug + // remember that reference count incrementing/decrementing must be done thread-safely/atomically + // objects should be created/initialized with a custom ref-count of 1 by the class creation functions + // do not attempt to use any bits within the CFRuntimeBase for your reference count; store that in some additional field in your CF object + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#define CF_REQUIRED_ALIGNMENT_AVAILABLE 1 + uintptr_t requiredAlignment; // Or in _kCFRuntimeRequiresAlignment in the .version field to indicate this field should be used; the allocator to _CFRuntimeCreateInstance() will be ignored in this case; if this is less than the minimum alignment the system supports, you'll get higher alignment; if this is not an alignment the system supports (e.g., most systems will only support powers of two, or if it is too high), the result (consequences) will be up to CF or the system to decide + +} CFRuntimeClass; + +#define RADAR_5115468_FIXED 1 + +/* Note that CF runtime class registration and unregistration is not currently + * thread-safe, which should not currently be a problem, as long as unregistration + * is done only when valid to do so. + */ + +CF_EXPORT CFTypeID _CFRuntimeRegisterClass(const CFRuntimeClass * const cls); + /* Registers a new class with the CF runtime. Pass in a + * pointer to a CFRuntimeClass structure. The pointer is + * remembered by the CF runtime -- the structure is NOT + * copied. + * + * - version field must be zero currently. + * - className field points to a null-terminated C string + * containing only ASCII (0 - 127) characters; this field + * may NOT be NULL. + * - init field points to a function which classes can use to + * apply some generic initialization to instances as they + * are created; this function is called by both + * _CFRuntimeCreateInstance and _CFRuntimeInitInstance; if + * this field is NULL, no function is called; the instance + * has been initialized enough that the polymorphic funcs + * CFGetTypeID(), CFRetain(), CFRelease(), CFGetRetainCount(), + * and CFGetAllocator() are valid on it when the init + * function if any is called. + * - copy field should always be NULL. Generic copying of CF + * objects has never been defined (and is unlikely). + * - finalize field points to a function which destroys an + * instance when the retain count has fallen to zero; if + * this is NULL, finalization does nothing. Note that if + * the class-specific functions which create or initialize + * instances more fully decide that a half-initialized + * instance must be destroyed, the finalize function for + * that class has to be able to deal with half-initialized + * instances. The finalize function should NOT destroy the + * memory for the instance itself; that is done by the + * CF runtime after this finalize callout returns. + * - equal field points to an equality-testing function; this + * field may be NULL, in which case only pointer/reference + * equality is performed on instances of this class. + * Pointer equality is tested, and the type IDs are checked + * for equality, before this function is called (so, the + * two instances are not pointer-equal but are of the same + * class before this function is called). + * NOTE: the equal function must implement an immutable + * equality relation, satisfying the reflexive, symmetric, + * and transitive properties, and remains the same across + * time and immutable operations (that is, if equal(A,B) at + * some point, then later equal(A,B) provided neither + * A or B has been mutated). + * - hash field points to a hash-code-computing function for + * instances of this class; this field may be NULL in which + * case the pointer value of an instance is converted into + * a hash. + * NOTE: the hash function and equal function must satisfy + * the relationship "equal(A,B) implies hash(A) == hash(B)"; + * that is, if two instances are equal, their hash codes must + * be equal too. (However, the converse is not true!) + * - copyFormattingDesc field points to a function returning a + * CFStringRef with a human-readable description of the + * instance; if this is NULL, the type does not have special + * human-readable string-formats. + * - copyDebugDesc field points to a function returning a + * CFStringRef with a debugging description of the instance; + * if this is NULL, a simple description is generated. + * + * This function returns _kCFRuntimeNotATypeID on failure, or + * on success, returns the CFTypeID for the new class. This + * CFTypeID is what the class uses to allocate or initialize + * instances of the class. It is also returned from the + * conventional *GetTypeID() function, which returns the + * class's CFTypeID so that clients can compare the + * CFTypeID of instances with that of a class. + * + * The function to compute a human-readable string is very + * optional, and is really only interesting for classes, + * like strings or numbers, where it makes sense to format + * the instance using just its contents. + */ + +CF_EXPORT const CFRuntimeClass * _CFRuntimeGetClassWithTypeID(CFTypeID typeID); + /* Returns the pointer to the CFRuntimeClass which was + * assigned the specified CFTypeID. + */ + +CF_EXPORT void _CFRuntimeUnregisterClassWithTypeID(CFTypeID typeID); + /* Unregisters the class with the given type ID. It is + * undefined whether type IDs are reused or not (expect + * that they will be). + * + * Whether or not unregistering the class is a good idea or + * not is not CF's responsibility. In particular you must + * be quite sure all instances are gone, and there are no + * valid weak refs to such in other threads. + */ + +/* All CF "instances" start with this structure. Never refer to + * these fields directly -- they are for CF's use and may be added + * to or removed or change format without warning. Binary + * compatibility for uses of this struct is not guaranteed from + * release to release. + */ +#if DEPLOYMENT_RUNTIME_SWIFT + +typedef struct __attribute__((__aligned__(8))) __CFRuntimeBase { + // This matches the isa and retain count storage in Swift + __ptrauth_cf_objc_isa_pointer uintptr_t _cfisa; + uintptr_t _swift_rc; + // This is for CF's use, and must match __NSCFType/_CFInfo layout + _Atomic(uint64_t) _cfinfoa; +} CFRuntimeBase; + +#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0x0000000000000080ULL} + +#else +typedef struct __CFRuntimeBase { + __ptrauth_cf_objc_isa_pointer uintptr_t _cfisa; +#if defined(__LP64__) || defined(__LLP64__) + _Atomic(uint64_t) _cfinfoa; +#else + _Atomic(uint32_t) _cfinfoa; +#endif +} CFRuntimeBase; + +#if TARGET_RT_64_BIT +#define INIT_CFRUNTIME_BASE(...) {0, 0x0000000000000080ULL} +#else +#define INIT_CFRUNTIME_BASE(...) {0, 0x00000080UL} +#endif + +#endif + +CF_EXPORT CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CFIndex extraBytes, unsigned char *category); + /* Creates a new CF instance of the class specified by the + * given CFTypeID, using the given allocator, and returns it. + * If the allocator returns NULL, this function returns NULL. + * A CFRuntimeBase structure is initialized at the beginning + * of the returned instance. extraBytes is the additional + * number of bytes to allocate for the instance (BEYOND that + * needed for the CFRuntimeBase). If the specified CFTypeID + * is unknown to the CF runtime, this function returns NULL. + * The base header is initialized and the extra bytes if + * requested will be zeroed. + * All instances created with this function must be destroyed + * only through use of the CFRelease() function -- instances + * must not be destroyed by using CFAllocatorDeallocate() + * directly, even in the initialization or creation functions + * of a class. Pass NULL for the category parameter. + */ + +CF_EXPORT void _CFRuntimeSetInstanceTypeID(CFTypeRef cf, CFTypeID typeID); + /* This function changes the typeID of the given instance. + * If the specified CFTypeID is unknown to the CF runtime, + * this function does nothing. This function CANNOT be used + * to initialize an instance. It is for advanced usages such + * as faulting. You cannot change the CFTypeID of an object + * of a _kCFRuntimeCustomRefCount class, or to a + * _kCFRuntimeCustomRefCount class. + */ + +#if DEPLOYMENT_RUNTIME_SWIFT +#else +CF_EXPORT void _CFRuntimeInitStaticInstance(void *memory, CFTypeID typeID); + /* This function initializes a memory block to be a constant + * (unreleaseable) CF object of the given typeID. + * If the specified CFTypeID is unknown to the CF runtime, + * this function does nothing. The memory block should + * be a chunk of in-binary writeable static memory, and at + * least as large as sizeof(CFRuntimeBase) on the platform + * the code is being compiled for. The init function of the + * CFRuntimeClass is invoked on the memory as well, if the + * class has one. Static instances cannot be initialized to + * _kCFRuntimeCustomRefCount classes. + */ +#define CF_HAS_INIT_STATIC_INSTANCE 1 +#endif + +CF_EXTERN_C_END + +#endif /* ! __COREFOUNDATION_CFRUNTIME__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFString.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFString.h new file mode 100644 index 0000000..2add693 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFString.h @@ -0,0 +1,915 @@ +/* CFString.h + Copyright (c) 1998-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_CFSTRING__) +#define __COREFOUNDATION_CFSTRING__ 1 + +#include "CFTargetConditionals.h" + +#include "CFBase.h" +#include "CFArray.h" +#include "CFData.h" +#include "CFDictionary.h" +#include "CFCharacterSet.h" +//#include "CFLocale.h" +#include + +CF_IMPLICIT_BRIDGING_ENABLED +CF_EXTERN_C_BEGIN + +/* +Please note: CFStrings are conceptually an array of Unicode characters. +However, in general, how a CFString stores this array is an implementation +detail. For instance, CFString might choose to use an array of 8-bit characters +to store its contents, or it might use multiple blocks of memory, or whatever. +This is especially true since CFString is toll-free bridged with NSString, enabling +any NSString instance to be used as a CFString. Furthermore, the implementation +may change depending on the default system encoding, the user's language, +or even a release or update of the OS. + +What this means is that you should use the following advanced functions with care: + + CFStringGetPascalStringPtr() + CFStringGetCStringPtr() + CFStringGetCharactersPtr() + +These functions are provided for optimization only. They will either return the desired +pointer quickly, in constant time, or they return NULL. They might choose to return NULL +for many reasons; for instance it's possible that for users running in different +languages these sometimes return NULL; or in a future OS release the first two might +switch to always returning NULL. Never observing NULL returns in your usages of these +functions does not mean they won't ever return NULL. In fact, this happened with the +introduction of tagged pointer strings in OS X 10.10, and a year later iOS 9. +(But please note the CFStringGetCharactersPtr() exception mentioned further below.) + +In your usages of these functions, if you get a NULL return, use the non-Ptr version +of the functions as shown in this example: + + char buffer[BUFSIZE]; + const char *ptr = CFStringGetCStringPtr(str, encoding); + if (ptr == NULL) { + if (CFStringGetCString(str, buffer, BUFSIZE, encoding)) ptr = buffer; + } + +Note that CFStringGetCString() or CFStringGetPascalString() calls might still fail --- but +that will happen in two circumstances only: The conversion from the UniChar contents of CFString +to the specified encoding fails, or the buffer is too small. If they fail, that means +the conversion was not possible. + +If you need a copy of the buffer in the above example, you might consider simply calling +CFStringGetCString() in all cases --- CFStringGetCStringPtr() is simply an optimization. + +In addition, the following functions, which create immutable CFStrings from developer +supplied buffers without copying the buffers, might have to actually copy +under certain circumstances (If they do copy, the buffer will be dealt with by the +"contentsDeallocator" argument.): + + CFStringCreateWithPascalStringNoCopy() + CFStringCreateWithCStringNoCopy() + CFStringCreateWithCharactersNoCopy() + +You should of course never depend on the backing store of these CFStrings being +what you provided, and in other no circumstance should you change the contents +of that buffer (given that would break the invariant about the CFString being immutable). + +Having said all this, there are actually ways to create a CFString where the backing store +is external, and can be manipulated by the developer or CFString itself: + + CFStringCreateMutableWithExternalCharactersNoCopy() + CFStringSetExternalCharactersNoCopy() + +A "contentsAllocator" is used to realloc or free the backing store by CFString. +kCFAllocatorNull can be provided to assure CFString will never realloc or free the buffer. +Developer can call CFStringSetExternalCharactersNoCopy() to update +CFString's idea of what's going on, if the buffer is changed externally. In these +strings, CFStringGetCharactersPtr() is guaranteed to return the external buffer. + +These functions are here to allow wrapping a buffer of UniChar characters in a CFString, +allowing the buffer to passed into CFString functions and also manipulated via CFString +mutation functions. In general, developers should not use this technique for all strings, +as it prevents CFString from using certain optimizations. +*/ + +/* Identifier for character encoding; the values are the same as Text Encoding Converter TextEncoding. +*/ +typedef UInt32 CFStringEncoding; + +/* Platform-independent built-in encodings; always available on all platforms. + Call CFStringGetSystemEncoding() to get the default system encoding. +*/ +#define kCFStringEncodingInvalidId (0xffffffffU) +typedef CF_ENUM(CFStringEncoding, CFStringBuiltInEncodings) { + kCFStringEncodingMacRoman = 0, + kCFStringEncodingWindowsLatin1 = 0x0500, /* ANSI codepage 1252 */ + kCFStringEncodingISOLatin1 = 0x0201, /* ISO 8859-1 */ + kCFStringEncodingNextStepLatin = 0x0B01, /* NextStep encoding*/ + kCFStringEncodingASCII = 0x0600, /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */ + kCFStringEncodingUnicode = 0x0100, /* kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */ + kCFStringEncodingUTF8 = 0x08000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */ + kCFStringEncodingNonLossyASCII = 0x0BFF, /* 7bit Unicode variants used by Cocoa & Java */ + + kCFStringEncodingUTF16 = 0x0100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16Format (alias of kCFStringEncodingUnicode) */ + kCFStringEncodingUTF16BE = 0x10000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16BEFormat */ + kCFStringEncodingUTF16LE = 0x14000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF16LEFormat */ + + kCFStringEncodingUTF32 = 0x0c000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF32Format */ + kCFStringEncodingUTF32BE = 0x18000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat */ + kCFStringEncodingUTF32LE = 0x1c000100 /* kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat */ +}; + + +/* CFString type ID */ +CF_EXPORT +CFTypeID CFStringGetTypeID(void); + +/* CFSTR() allows creation of compile-time constant CFStringRefs; the argument +should be a constant C-string. + +CFSTR(), not being a "Copy" or "Create" function, does not return a new +reference for you. So, you should not release the return value. This is +much like constant C or Pascal strings --- when you use "hello world" +in a program, you do not free it. + +However, strings returned from CFSTR() can be retained and released in a +properly nested fashion, just like any other CF type. That is, if you pass +a CFSTR() return value to a function such as SetMenuItemWithCFString(), the +function can retain it, then later, when it's done with it, it can release it. + +Non-7 bit characters (that is, above 127) in CFSTR() are supported, although care must +be taken in dealing with files containing them. If you can trust your editor and tools +to deal with non-ASCII characters in the source code, then you can use them directly +in CFSTR(); otherwise, you can represent such characters with their escaped octal +equivalents in the encoding the compiler will use to interpret them (for instance, +O-umlaut is \303\226 in UTF-8). UTF-8 is the recommended encoding here, +since it is the default choice with Mac OS X developer tools. +*/ + +#if DEPLOYMENT_RUNTIME_SWIFT + #if TARGET_OS_MAC + #define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN + #else + #define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN + #endif + +CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[]; +#endif + +#if DEPLOYMENT_RUNTIME_SWIFT + +struct __CFConstStr { + struct { + __ptrauth_cf_objc_isa_pointer uintptr_t _cfisa; + uintptr_t _swift_rc; + uint64_t _cfinfoa; + } _base; + uint8_t *_ptr; +#if TARGET_RT_64_BIT && defined(__BIG_ENDIAN__) + uint64_t _length; +#else // 32-bit: + uint32_t _length; +#endif // TARGET_RT_64_BIT && defined(__BIG_ENDIAN__) +}; + +#if __BIG_ENDIAN__ +#define CFSTR(cStr) ({ \ + static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ + (CFStringRef)&str; \ +}) +#else // Little endian: +#define CFSTR(cStr) ({ \ + static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ + (CFStringRef)&str; \ +}) +#endif // __BIG_ENDIAN__ + +#else + +#ifdef __CONSTANT_CFSTRINGS__ +#define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr "")) +#else +#define CFSTR(cStr) __CFStringMakeConstantString("" cStr "") +#endif + +#endif + +#if defined(__GNUC__) && (__GNUC__*10+__GNUC_MINOR__ >= 42) && defined(__APPLE_CC__) && (__APPLE_CC__ > 1) && !defined(__INTEL_COMPILER) && TARGET_OS_MAC +#define CF_FORMAT_FUNCTION(F,A) __attribute__((format(CFString, F, A))) +#define CF_FORMAT_ARGUMENT(A) __attribute__((format_arg(A))) +#else +#define CF_FORMAT_FUNCTION(F,A) +#define CF_FORMAT_ARGUMENT(A) +#endif + +/*** Immutable string creation functions ***/ + +/* Functions to create basic immutable strings. The provided allocator is used for all memory activity in these functions. +*/ + +/* The following four functions copy the provided buffer into CFString's internal storage. */ +CF_EXPORT +CFStringRef CFStringCreateWithPascalString(CFAllocatorRef alloc, ConstStr255Param pStr, CFStringEncoding encoding); + +CF_EXPORT +CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding); + +/* The following takes an explicit length, and allows you to specify whether the data is an external format --- that is, whether to pay attention to the BOM character (if any) and do byte swapping if necessary +*/ +CF_EXPORT +CFStringRef CFStringCreateWithBytes(CFAllocatorRef alloc, const UInt8 *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean isExternalRepresentation); + +CF_EXPORT +CFStringRef CFStringCreateWithCharacters(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars); + + +/* These functions try not to copy the provided buffer. The buffer will be deallocated +with the provided contentsDeallocator when it's no longer needed; to not free +the buffer, specify kCFAllocatorNull here. As usual, NULL means default allocator. + +NOTE: Do not count on these buffers as being used by the string; +in some cases the CFString might free the buffer and use something else +(for instance if it decides to always use Unicode encoding internally). + +NOTE: If you are not transferring ownership of the buffer to the CFString +(for instance, you supplied contentsDeallocator = kCFAllocatorNull), it is your +responsibility to assure the buffer does not go away during the lifetime of the string. +If the string is retained or copied, its lifetime might extend in ways you cannot +predict. So, for strings created with buffers whose lifetimes you cannot +guarantee, you need to be extremely careful --- do not hand it out to any +APIs which might retain or copy the strings. +*/ +CF_EXPORT +CFStringRef CFStringCreateWithPascalStringNoCopy(CFAllocatorRef alloc, ConstStr255Param pStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator); + +CF_EXPORT +CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator); + +/* The following takes an explicit length, and allows you to specify whether the data is an external format --- that is, whether to pay attention to the BOM character (if any) and do byte swapping if necessary +*/ +CF_EXPORT +CFStringRef CFStringCreateWithBytesNoCopy(CFAllocatorRef alloc, const UInt8 *bytes, CFIndex numBytes, CFStringEncoding encoding, Boolean isExternalRepresentation, CFAllocatorRef contentsDeallocator); + +CF_EXPORT +CFStringRef CFStringCreateWithCharactersNoCopy(CFAllocatorRef alloc, const UniChar *chars, CFIndex numChars, CFAllocatorRef contentsDeallocator); + +/* Create copies of part or all of the string. +*/ +CF_EXPORT +CFStringRef CFStringCreateWithSubstring(CFAllocatorRef alloc, CFStringRef str, CFRange range); + +CF_EXPORT +CFStringRef CFStringCreateCopy(CFAllocatorRef alloc, CFStringRef theString); + +/* These functions create a CFString from the provided printf-like format string and arguments. +*/ +CF_EXPORT +CFStringRef CFStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, ...) CF_FORMAT_FUNCTION(3,4); + +CF_EXPORT +CFStringRef CFStringCreateWithFormatAndArguments(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, va_list arguments) CF_FORMAT_FUNCTION(3,0); + +/* Functions to create mutable strings. "maxLength", if not 0, is a hard bound on the length of the string. If 0, there is no limit on the length. +*/ +CF_EXPORT +CFMutableStringRef CFStringCreateMutable(CFAllocatorRef alloc, CFIndex maxLength); + +CF_EXPORT +CFMutableStringRef CFStringCreateMutableCopy(CFAllocatorRef alloc, CFIndex maxLength, CFStringRef theString); + +/* This function creates a mutable string that has a developer supplied and directly editable backing store. +The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the +externalCharactersAllocator will be consulted for more memory. When the CFString is deallocated, the +buffer will be freed with the externalCharactersAllocator. If you provide kCFAllocatorNull here, and the buffer +needs to grow, then CFString will switch to using the default allocator. See comments at top of this file for more info. +*/ +CF_EXPORT +CFMutableStringRef CFStringCreateMutableWithExternalCharactersNoCopy(CFAllocatorRef alloc, UniChar *chars, CFIndex numChars, CFIndex capacity, CFAllocatorRef externalCharactersAllocator); + +/*** Basic accessors for the contents ***/ + +/* Number of 16-bit Unicode characters in the string. +*/ +CF_EXPORT +CFIndex CFStringGetLength(CFStringRef theString); + +/* Extracting the contents of the string. For obtaining multiple characters, calling +CFStringGetCharacters() is more efficient than multiple calls to CFStringGetCharacterAtIndex(). +If the length of the string is not known (so you can't use a fixed size buffer for CFStringGetCharacters()), +another method is to use is CFStringGetCharacterFromInlineBuffer() (see further below). +*/ +CF_EXPORT +UniChar CFStringGetCharacterAtIndex(CFStringRef theString, CFIndex idx); + +CF_EXPORT +void CFStringGetCharacters(CFStringRef theString, CFRange range, UniChar *buffer); + + +/*** Conversion to other encodings ***/ + +/* These two convert into the provided buffer; they return false if conversion isn't possible +(due to conversion error, or not enough space in the provided buffer). +These functions do zero-terminate or put the length byte; the provided bufferSize should include +space for this (so pass 256 for Str255). More sophisticated usages can go through CFStringGetBytes(). +These functions are equivalent to calling CFStringGetBytes() with +the range of the string; lossByte = 0; and isExternalRepresentation = false; +if successful, they then insert the leading length or terminating zero, as desired. +*/ +CF_EXPORT +Boolean CFStringGetPascalString(CFStringRef theString, StringPtr buffer, CFIndex bufferSize, CFStringEncoding encoding); + +CF_EXPORT +Boolean CFStringGetCString(CFStringRef theString, char *buffer, CFIndex bufferSize, CFStringEncoding encoding); + +/* These functions attempt to return in O(1) time the desired format for the string. +Note that although this means a pointer to the internal structure is being returned, +this can't always be counted on. Please see note at the top of the file for more +details. +*/ +CF_EXPORT +ConstStringPtr CFStringGetPascalStringPtr(CFStringRef theString, CFStringEncoding encoding); /* May return NULL at any time; be prepared for NULL, if not now, in some other time or place. See discussion at top of this file. */ + +CF_EXPORT +const char *CFStringGetCStringPtr(CFStringRef theString, CFStringEncoding encoding); /* May return NULL at any time; be prepared for NULL, if not now, in some other time or place. See discussion at top of this file. */ + +CF_EXPORT +const UniChar *CFStringGetCharactersPtr(CFStringRef theString); /* May return NULL at any time; be prepared for NULL, if not now, in some other time or place. See discussion at top of this file. */ + +/* The primitive conversion routine; allows you to convert a string piece at a time + into a fixed size buffer. Returns number of characters converted. + Characters that cannot be converted to the specified encoding are represented + with the byte specified by lossByte; if lossByte is 0, then lossy conversion + is not allowed and conversion stops, returning partial results. + Pass buffer==NULL if you don't care about the converted string (but just the convertability, + or number of bytes required). + maxBufLength indicates the maximum number of bytes to generate. It is ignored when buffer==NULL. + Does not zero-terminate. If you want to create Pascal or C string, allow one extra byte at start or end. + Setting isExternalRepresentation causes any extra bytes that would allow + the data to be made persistent to be included; for instance, the Unicode BOM. Note that + CFString prepends UTF encoded data with the Unicode BOM + when generating external representation if the target encoding allows. It's important to note that + only UTF-8, UTF-16, and UTF-32 define the handling of the byte order mark character, and the "LE" + and "BE" variants of UTF-16 and UTF-32 don't. +*/ +CF_EXPORT +CFIndex CFStringGetBytes(CFStringRef theString, CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, UInt8 *buffer, CFIndex maxBufLen, CFIndex *usedBufLen); + +/* Convenience functions String <-> Data. These generate "external" formats, that is, formats that + can be written out to disk. For instance, if the encoding is Unicode, + CFStringCreateFromExternalRepresentation() pays attention to the BOM character (if any) + and does byte swapping if necessary. Similarly CFStringCreateExternalRepresentation() will + include a BOM character if appropriate. See CFStringGetBytes() for more on this and lossByte. +*/ +CF_EXPORT +CFStringRef CFStringCreateFromExternalRepresentation(CFAllocatorRef alloc, CFDataRef data, CFStringEncoding encoding); /* May return NULL on conversion error */ + +CF_EXPORT +CFDataRef CFStringCreateExternalRepresentation(CFAllocatorRef alloc, CFStringRef theString, CFStringEncoding encoding, UInt8 lossByte); /* May return NULL on conversion error */ + +/* Hints about the contents of a string +*/ +CF_EXPORT +CFStringEncoding CFStringGetSmallestEncoding(CFStringRef theString); /* Result in O(n) time max */ + +CF_EXPORT +CFStringEncoding CFStringGetFastestEncoding(CFStringRef theString); /* Result in O(1) time max */ + +/* General encoding info +*/ +CF_EXPORT +CFStringEncoding CFStringGetSystemEncoding(void); /* The default encoding for the system; untagged 8-bit characters are usually in this encoding */ + +CF_EXPORT +CFIndex CFStringGetMaximumSizeForEncoding(CFIndex length, CFStringEncoding encoding); /* Max bytes a string of specified length (in UniChars) will take up if encoded */ + + +/*** FileSystem path conversion functions ***/ + +/* Extract the contents of the string as a NULL-terminated 8-bit string appropriate for passing to POSIX APIs (for example, normalized for HFS+). The string is zero-terminated. false will be returned if the conversion results don't fit into the buffer. Use CFStringGetMaximumSizeOfFileSystemRepresentation() if you want to make sure the buffer is of sufficient length. +*/ +CF_EXPORT +Boolean CFStringGetFileSystemRepresentation(CFStringRef string, char *buffer, CFIndex maxBufLen); + +/* Get the upper bound on the number of bytes required to hold the file system representation for the string. This result is returned quickly as a very rough approximation, and could be much larger than the actual space required. The result includes space for the zero termination. If you are allocating a buffer for long-term keeping, it's recommended that you reallocate it smaller (to be the right size) after calling CFStringGetFileSystemRepresentation(). +*/ +CF_EXPORT +CFIndex CFStringGetMaximumSizeOfFileSystemRepresentation(CFStringRef string); + +/* Create a CFString from the specified zero-terminated POSIX file system representation. If the conversion fails (possible due to bytes in the buffer not being a valid sequence of bytes for the appropriate character encoding), NULL is returned. +*/ +CF_EXPORT +CFStringRef CFStringCreateWithFileSystemRepresentation(CFAllocatorRef alloc, const char *buffer); + + +/*** Comparison functions. ***/ + +/* Find and compare flags; these are OR'ed together and provided as CFStringCompareFlags in the various functions. +*/ +typedef CF_OPTIONS(CFOptionFlags, CFStringCompareFlags) { + kCFCompareCaseInsensitive = 1, + kCFCompareBackwards = 4, /* Starting from the end of the string */ + kCFCompareAnchored = 8, /* Only at the specified starting point */ + kCFCompareNonliteral = 16, /* If specified, loose equivalence is performed (o-umlaut == o, umlaut) */ + kCFCompareLocalized = 32, /* User's default locale is used for the comparisons */ + kCFCompareNumerically = 64, /* Numeric comparison is used; that is, Foo2.txt < Foo7.txt < Foo25.txt */ + kCFCompareDiacriticInsensitive API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 128, /* If specified, ignores diacritics (o-umlaut == o) */ + kCFCompareWidthInsensitive API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 256, /* If specified, ignores width differences ('a' == UFF41) */ + kCFCompareForcedOrdering API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)) = 512 /* If specified, comparisons are forced to return either kCFCompareLessThan or kCFCompareGreaterThan if the strings are equivalent but not strictly equal, for stability when sorting (e.g. "aaa" > "AAA" with kCFCompareCaseInsensitive specified) */ +}; + +///* The main comparison routine; compares specified range of the first string to (the full range of) the second string. +// locale == NULL indicates canonical locale (the return value from CFLocaleGetSystem()). +// kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3 +// kCFCompareBackwards and kCFCompareAnchored are not applicable. +// rangeToCompare applies to the first string; that is, only the substring of theString1 specified by rangeToCompare is compared against all of theString2. +//*/ +//CF_EXPORT +//CFComparisonResult CFStringCompareWithOptionsAndLocale(CFStringRef theString1, CFStringRef theString2, CFRange rangeToCompare, CFStringCompareFlags compareOptions, CFLocaleRef locale) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); + +/* Comparison convenience. Uses the current user locale (the return value from CFLocaleCopyCurrent()) if kCFCompareLocalized. Refer to CFStringCompareWithOptionsAndLocale() for more info. +*/ +CF_EXPORT +CFComparisonResult CFStringCompareWithOptions(CFStringRef theString1, CFStringRef theString2, CFRange rangeToCompare, CFStringCompareFlags compareOptions); + +/* Comparison convenience suitable for passing as sorting functions. + kCFCompareNumerically, added in 10.2, does not work if kCFCompareLocalized is specified on systems before 10.3 + kCFCompareBackwards and kCFCompareAnchored are not applicable. +*/ +CF_EXPORT +CFComparisonResult CFStringCompare(CFStringRef theString1, CFStringRef theString2, CFStringCompareFlags compareOptions); + +///* CFStringFindWithOptionsAndLocale() returns the found range in the CFRange * argument; you can pass NULL for simple discovery check. +// locale == NULL indicates canonical locale (the return value from CFLocaleGetSystem()). +// If stringToFind is the empty string (zero length), nothing is found. +// Ignores the kCFCompareNumerically option. +// Only the substring of theString specified by rangeToSearch is searched for stringToFind. +//*/ +//CF_EXPORT +//Boolean CFStringFindWithOptionsAndLocale(CFStringRef theString, CFStringRef stringToFind, CFRange rangeToSearch, CFStringCompareFlags searchOptions, CFLocaleRef locale, CFRange *result) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); + +/* Find convenience. Uses the current user locale (the return value from CFLocaleCopyCurrent()) if kCFCompareLocalized. Refer to CFStringFindWithOptionsAndLocale() for more info. +*/ +CF_EXPORT +Boolean CFStringFindWithOptions(CFStringRef theString, CFStringRef stringToFind, CFRange rangeToSearch, CFStringCompareFlags searchOptions, CFRange *result); + +/* CFStringCreateArrayWithFindResults() returns an array of CFRange pointers, or NULL if there are no matches. + Overlapping instances are not found; so looking for "AA" in "AAA" finds just one range. + Post 10.1: If kCFCompareBackwards is provided, the scan is done from the end (which can give a different result), and + the results are stored in the array backwards (last found range in slot 0). + If stringToFind is the empty string (zero length), nothing is found. + kCFCompareAnchored causes just the consecutive instances at start (or end, if kCFCompareBackwards) to be reported. So, searching for "AB" in "ABABXAB..." you just get the first two occurrences. + Ignores the kCFCompareNumerically option. + Only the substring of theString specified by rangeToSearch is searched for stringToFind. +*/ +CF_EXPORT +CFArrayRef CFStringCreateArrayWithFindResults(CFAllocatorRef alloc, CFStringRef theString, CFStringRef stringToFind, CFRange rangeToSearch, CFStringCompareFlags compareOptions); + +/* Find conveniences; see comments above concerning empty string and options. +*/ +CF_EXPORT +CFRange CFStringFind(CFStringRef theString, CFStringRef stringToFind, CFStringCompareFlags compareOptions); + +CF_EXPORT +Boolean CFStringHasPrefix(CFStringRef theString, CFStringRef prefix); + +CF_EXPORT +Boolean CFStringHasSuffix(CFStringRef theString, CFStringRef suffix); + +/*! + @function CFStringGetRangeOfComposedCharactersAtIndex + Returns the range of the composed character sequence at the specified index. + @param theString The CFString which is to be searched. If this + parameter is not a valid CFString, the behavior is + undefined. + @param theIndex The index of the character contained in the + composed character sequence. If the index is + outside the index space of the string (0 to N-1 inclusive, + where N is the length of the string), the behavior is + undefined. + @result The range of the composed character sequence. +*/ +CF_EXPORT CFRange CFStringGetRangeOfComposedCharactersAtIndex(CFStringRef theString, CFIndex theIndex); + +/*! + @function CFStringFindCharacterFromSet + Query the range of the first character contained in the specified character set. + @param theString The CFString which is to be searched. If this + parameter is not a valid CFString, the behavior is + undefined. + @param theSet The CFCharacterSet against which the membership + of characters is checked. If this parameter is not a valid + CFCharacterSet, the behavior is undefined. + @param rangeToSearch The range of characters within the string to search. If + the range location or end point (defined by the location + plus length minus 1) are outside the index space of the + string (0 to N-1 inclusive, where N is the length of the + string), the behavior is undefined. If the range length is + negative, the behavior is undefined. The range may be empty + (length 0), in which case no search is performed. + @param searchOptions The bitwise-or'ed option flags to control + the search behavior. The supported options are + kCFCompareBackwards andkCFCompareAnchored. + If other option flags are specified, the behavior + is undefined. + @param result The pointer to a CFRange supplied by the caller in + which the search result is stored. Note that the length + of this range can be more than 1, if for instance the + result is a composed character. If a pointer to an invalid + memory is specified, the behavior is undefined. + @result true, if at least a character which is a member of the character + set is found and result is filled, otherwise, false. +*/ +CF_EXPORT Boolean CFStringFindCharacterFromSet(CFStringRef theString, CFCharacterSetRef theSet, CFRange rangeToSearch, CFStringCompareFlags searchOptions, CFRange *result); + +/* Find range of bounds of the line(s) that span the indicated range (startIndex, numChars), + taking into account various possible line separator sequences (CR, CRLF, LF, and Unicode NextLine, LineSeparator, ParagraphSeparator). + All return values are "optional" (provide NULL if you don't want them) + lineBeginIndex: index of first character in line + lineEndIndex: index of first character of the next line (including terminating line separator characters) + contentsEndIndex: index of the first line separator character + Thus, lineEndIndex - lineBeginIndex is the number of chars in the line, including the line separators + contentsEndIndex - lineBeginIndex is the number of chars in the line w/out the line separators +*/ +CF_EXPORT +void CFStringGetLineBounds(CFStringRef theString, CFRange range, CFIndex *lineBeginIndex, CFIndex *lineEndIndex, CFIndex *contentsEndIndex); + +/* Same as CFStringGetLineBounds(), however, will only look for paragraphs. Won't stop at Unicode NextLine or LineSeparator characters. +*/ +CF_EXPORT +void CFStringGetParagraphBounds(CFStringRef string, CFRange range, CFIndex *parBeginIndex, CFIndex *parEndIndex, CFIndex *contentsEndIndex) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); + +///*! +// @function CFStringGetHyphenationLocationBeforeIndex +// Retrieve the first potential hyphenation location found before the specified location. +// @param string The CFString which is to be hyphenated. If this +// parameter is not a valid CFString, the behavior is +// undefined. +// @param location An index in the string. If a valid hyphen index is returned, it +// will be before this index. +// @param limitRange The range of characters within the string to search. If +// the range location or end point (defined by the location +// plus length minus 1) are outside the index space of the +// string (0 to N-1 inclusive, where N is the length of the +// string), the behavior is undefined. If the range length is +// negative, the behavior is undefined. The range may be empty +// (length 0), in which case no hyphen location is generated. +// @param options Reserved for future use. +// @param locale Specifies which language's hyphenation conventions to use. +// This must be a valid locale. Hyphenation data is not available +// for all locales. You can use CFStringIsHyphenationAvailableForLocale +// to test for availability of hyphenation data. +// @param character The suggested hyphen character to insert. Pass NULL if you +// do not need this information. +// @result an index in the string where it is appropriate to insert a hyphen, if +// one exists; else kCFNotFound +//*/ +//CF_EXPORT +//CFIndex CFStringGetHyphenationLocationBeforeIndex(CFStringRef string, CFIndex location, CFRange limitRange, CFOptionFlags options, CFLocaleRef locale, UTF32Char *character) API_AVAILABLE(macos(10.7), ios(4.2), watchos(2.0), tvos(9.0)); + +//CF_EXPORT +//Boolean CFStringIsHyphenationAvailableForLocale(CFLocaleRef locale) API_AVAILABLE(macos(10.7), ios(4.3), watchos(2.0), tvos(9.0)); + +/*** Exploding and joining strings with a separator string ***/ + +CF_EXPORT +CFStringRef CFStringCreateByCombiningStrings(CFAllocatorRef alloc, CFArrayRef theArray, CFStringRef separatorString); /* Empty array returns empty string; one element array returns the element */ + +CF_EXPORT +CFArrayRef CFStringCreateArrayBySeparatingStrings(CFAllocatorRef alloc, CFStringRef theString, CFStringRef separatorString); /* No separators in the string returns array with that string; string == sep returns two empty strings */ + + +/*** Parsing non-localized numbers from strings ***/ + +CF_EXPORT +SInt32 CFStringGetIntValue(CFStringRef str); /* Skips whitespace; returns 0 on error, MAX or -MAX on overflow */ + +CF_EXPORT +double CFStringGetDoubleValue(CFStringRef str); /* Skips whitespace; returns 0.0 on error */ + + +/*** MutableString functions ***/ + +/* CFStringAppend("abcdef", "xxxxx") -> "abcdefxxxxx" + CFStringDelete("abcdef", CFRangeMake(2, 3)) -> "abf" + CFStringReplace("abcdef", CFRangeMake(2, 3), "xxxxx") -> "abxxxxxf" + CFStringReplaceAll("abcdef", "xxxxx") -> "xxxxx" +*/ +CF_EXPORT +void CFStringAppend(CFMutableStringRef theString, CFStringRef appendedString); + +CF_EXPORT +void CFStringAppendCharacters(CFMutableStringRef theString, const UniChar *chars, CFIndex numChars); + +CF_EXPORT +void CFStringAppendPascalString(CFMutableStringRef theString, ConstStr255Param pStr, CFStringEncoding encoding); + +CF_EXPORT +void CFStringAppendCString(CFMutableStringRef theString, const char *cStr, CFStringEncoding encoding); + +CF_EXPORT +void CFStringAppendFormat(CFMutableStringRef theString, CFDictionaryRef formatOptions, CFStringRef format, ...) CF_FORMAT_FUNCTION(3,4); + +CF_EXPORT +void CFStringAppendFormatAndArguments(CFMutableStringRef theString, CFDictionaryRef formatOptions, CFStringRef format, va_list arguments) CF_FORMAT_FUNCTION(3,0); + +CF_EXPORT +void CFStringInsert(CFMutableStringRef str, CFIndex idx, CFStringRef insertedStr); + +CF_EXPORT +void CFStringDelete(CFMutableStringRef theString, CFRange range); + +CF_EXPORT +void CFStringReplace(CFMutableStringRef theString, CFRange range, CFStringRef replacement); + +CF_EXPORT +void CFStringReplaceAll(CFMutableStringRef theString, CFStringRef replacement); /* Replaces whole string */ + +/* Replace all occurrences of target in rangeToSearch of theString with replacement. + Pays attention to kCFCompareCaseInsensitive, kCFCompareBackwards, kCFCompareNonliteral, and kCFCompareAnchored. + kCFCompareBackwards can be used to do the replacement starting from the end, which could give a different result. + ex. AAAAA, replace AA with B -> BBA or ABB; latter if kCFCompareBackwards + kCFCompareAnchored assures only anchored but multiple instances are found (the instances must be consecutive at start or end) + ex. AAXAA, replace A with B -> BBXBB or BBXAA; latter if kCFCompareAnchored + Returns number of replacements performed. +*/ +CF_EXPORT +CFIndex CFStringFindAndReplace(CFMutableStringRef theString, CFStringRef stringToFind, CFStringRef replacementString, CFRange rangeToSearch, CFStringCompareFlags compareOptions); + + +/* This function will make the contents of a mutable CFString point directly at the specified UniChar array. + It works only with CFStrings created with CFStringCreateMutableWithExternalCharactersNoCopy(). + This function does not free the previous buffer. + The string will be manipulated within the provided buffer (if any) until it outgrows capacity; then the + externalCharactersAllocator will be consulted for more memory. + See comments at the top of this file for more info. +*/ +CF_EXPORT +void CFStringSetExternalCharactersNoCopy(CFMutableStringRef theString, UniChar *chars, CFIndex length, CFIndex capacity); /* Works only on specially created mutable strings! */ + +/* CFStringPad() will pad or cut down a string to the specified size. + The pad string is used as the fill string; indexIntoPad specifies which character to start with. + CFStringPad("abc", " ", 9, 0) -> "abc " + CFStringPad("abc", ". ", 9, 1) -> "abc . . ." + CFStringPad("abcdef", ?, 3, ?) -> "abc" + + CFStringTrim() will trim the specified string from both ends of the string. + CFStringTrimWhitespace() will do the same with white space characters (tab, newline, etc) + CFStringTrim(" abc ", " ") -> "abc" + CFStringTrim("* * * *abc * ", "* ") -> "*abc " +*/ +CF_EXPORT +void CFStringPad(CFMutableStringRef theString, CFStringRef padString, CFIndex length, CFIndex indexIntoPad); + +CF_EXPORT +void CFStringTrim(CFMutableStringRef theString, CFStringRef trimString); + +CF_EXPORT +void CFStringTrimWhitespace(CFMutableStringRef theString); + +//CF_EXPORT +//void CFStringLowercase(CFMutableStringRef theString, CFLocaleRef locale); + +//CF_EXPORT +//void CFStringUppercase(CFMutableStringRef theString, CFLocaleRef locale); + +//CF_EXPORT +//void CFStringCapitalize(CFMutableStringRef theString, CFLocaleRef locale); + +/*! + @typedef CFStringNormalizationForm + This is the type of Unicode normalization forms as described in + Unicode Technical Report #15. To normalize for use with file + system calls, use CFStringGetFileSystemRepresentation(). +*/ +typedef CF_ENUM(CFIndex, CFStringNormalizationForm) { + kCFStringNormalizationFormD = 0, // Canonical Decomposition + kCFStringNormalizationFormKD, // Compatibility Decomposition + kCFStringNormalizationFormC, // Canonical Decomposition followed by Canonical Composition + kCFStringNormalizationFormKC // Compatibility Decomposition followed by Canonical Composition +}; + +/*! + @function CFStringNormalize + Normalizes the string into the specified form as described in + Unicode Technical Report #15. + @param theString The string which is to be normalized. If this + parameter is not a valid mutable CFString, the behavior is + undefined. + @param theForm The form into which the string is to be normalized. + If this parameter is not a valid CFStringNormalizationForm value, + the behavior is undefined. +*/ +CF_EXPORT void CFStringNormalize(CFMutableStringRef theString, CFStringNormalizationForm theForm); + + +///*! +// @function CFStringFold +// Folds the string into the form specified by the flags. +// Character foldings are operations that convert any of a set of characters +// sharing similar semantics into a single representative from that set. +// This function can be used to preprocess strings that are to be compared, +// searched, or indexed. +// Note that folding does not include normalization, so it is necessary +// to use CFStringNormalize in addition to CFStringFold in order to obtain +// the effect of kCFCompareNonliteral. +// @param theString The string which is to be folded. If this parameter is not +// a valid mutable CFString, the behavior is undefined. +// @param theFlags The equivalency flags which describes the character folding form. +// Only those flags containing the word "insensitive" are recognized here; other flags are ignored. +// Folding with kCFCompareCaseInsensitive removes case distinctions in accordance with the mapping +// specified by ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt. Folding with +// kCFCompareDiacriticInsensitive removes distinctions of accents and other diacritics. Folding +// with kCFCompareWidthInsensitive removes character width distinctions by mapping characters in +// the range U+FF00-U+FFEF to their ordinary equivalents. +// @param theLocale The locale tailoring the character folding behavior. If NULL, +// it's considered to be the system locale returned from CFLocaleGetSystem(). +// If non-NULL and not a valid CFLocale object, the behavior is undefined. +//*/ +// +//CF_EXPORT +//void CFStringFold(CFMutableStringRef theString, CFStringCompareFlags theFlags, CFLocaleRef theLocale) API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); + +/* Perform string transliteration. The transformation represented by transform is applied to the given range of string, modifying it in place. Only the specified range will be modified, but the transform may look at portions of the string outside that range for context. NULL range pointer causes the whole string to be transformed. On return, range is modified to reflect the new range corresponding to the original range. reverse indicates that the inverse transform should be used instead, if it exists. If the transform is successful, true is returned; if unsuccessful, false. Reasons for the transform being unsuccessful include an invalid transform identifier, or attempting to reverse an irreversible transform. + +You can pass one of the predefined transforms below, or any valid ICU transform ID as defined in the ICU User Guide. Note that we do not support arbitrary set of ICU transform rules. +*/ +CF_EXPORT +Boolean CFStringTransform(CFMutableStringRef string, CFRange *range, CFStringRef transform, Boolean reverse); + +/* Transform identifiers for CFStringTransform() +*/ +CF_EXPORT const CFStringRef kCFStringTransformStripCombiningMarks; +CF_EXPORT const CFStringRef kCFStringTransformToLatin; +CF_EXPORT const CFStringRef kCFStringTransformFullwidthHalfwidth; +CF_EXPORT const CFStringRef kCFStringTransformLatinKatakana; +CF_EXPORT const CFStringRef kCFStringTransformLatinHiragana; +CF_EXPORT const CFStringRef kCFStringTransformHiraganaKatakana; +CF_EXPORT const CFStringRef kCFStringTransformMandarinLatin; +CF_EXPORT const CFStringRef kCFStringTransformLatinHangul; +CF_EXPORT const CFStringRef kCFStringTransformLatinArabic; +CF_EXPORT const CFStringRef kCFStringTransformLatinHebrew; +CF_EXPORT const CFStringRef kCFStringTransformLatinThai; +CF_EXPORT const CFStringRef kCFStringTransformLatinCyrillic; +CF_EXPORT const CFStringRef kCFStringTransformLatinGreek; +CF_EXPORT const CFStringRef kCFStringTransformToXMLHex; +CF_EXPORT const CFStringRef kCFStringTransformToUnicodeName; +CF_EXPORT const CFStringRef kCFStringTransformStripDiacritics API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); + + +/*** General encoding related functionality ***/ + +/* This returns availability of the encoding on the system +*/ +CF_EXPORT +Boolean CFStringIsEncodingAvailable(CFStringEncoding encoding); + +/* This function returns list of available encodings. The returned list is terminated with kCFStringEncodingInvalidId and owned by the system. +*/ +CF_EXPORT +const CFStringEncoding *CFStringGetListOfAvailableEncodings(void); + +/* Returns name of the encoding; non-localized. +*/ +CF_EXPORT +CFStringRef CFStringGetNameOfEncoding(CFStringEncoding encoding); + +/* ID mapping functions from/to Cocoa NSStringEncoding. Returns kCFStringEncodingInvalidId if no mapping exists. +*/ +CF_EXPORT +unsigned long CFStringConvertEncodingToNSStringEncoding(CFStringEncoding encoding); + +CF_EXPORT +CFStringEncoding CFStringConvertNSStringEncodingToEncoding(unsigned long encoding); + +/* ID mapping functions from/to Microsoft Windows codepage (covers both OEM & ANSI). Returns kCFStringEncodingInvalidId if no mapping exists. +*/ +CF_EXPORT +UInt32 CFStringConvertEncodingToWindowsCodepage(CFStringEncoding encoding); + +CF_EXPORT +CFStringEncoding CFStringConvertWindowsCodepageToEncoding(UInt32 codepage); + +/* ID mapping functions from/to IANA registery charset names. Returns kCFStringEncodingInvalidId if no mapping exists. +*/ +CF_EXPORT +CFStringEncoding CFStringConvertIANACharSetNameToEncoding(CFStringRef theString); + +CF_EXPORT +CFStringRef CFStringConvertEncodingToIANACharSetName(CFStringEncoding encoding); + +/* Returns the most compatible MacOS script value for the input encoding */ +/* i.e. kCFStringEncodingMacRoman -> kCFStringEncodingMacRoman */ +/* kCFStringEncodingWindowsLatin1 -> kCFStringEncodingMacRoman */ +/* kCFStringEncodingISO_2022_JP -> kCFStringEncodingMacJapanese */ +CF_EXPORT +CFStringEncoding CFStringGetMostCompatibleMacStringEncoding(CFStringEncoding encoding); + + + +/* The next two functions allow fast access to the contents of a string, + assuming you are doing sequential or localized accesses. To use, call + CFStringInitInlineBuffer() with a CFStringInlineBuffer (on the stack, say), + and a range in the string to look at. Then call CFStringGetCharacterFromInlineBuffer() + as many times as you want, with a index into that range (relative to the start + of that range). These are INLINE functions and will end up calling CFString only + once in a while, to fill a buffer. CFStringGetCharacterFromInlineBuffer() returns 0 if + a location outside the original range is specified. +*/ +#define __kCFStringInlineBufferLength 64 +typedef struct { + UniChar buffer[__kCFStringInlineBufferLength]; + CFStringRef theString; + const UniChar *directUniCharBuffer; + const char *directCStringBuffer; + CFRange rangeToBuffer; /* Range in string to buffer */ + CFIndex bufferedRangeStart; /* Start of range currently buffered (relative to rangeToBuffer.location) */ + CFIndex bufferedRangeEnd; /* bufferedRangeStart + number of chars actually buffered */ +} CFStringInlineBuffer; + +#if defined(CF_INLINE) +CF_INLINE void CFStringInitInlineBuffer(CFStringRef str, CFStringInlineBuffer *buf, CFRange range) { + buf->theString = str; + buf->rangeToBuffer = range; + buf->directCStringBuffer = (buf->directUniCharBuffer = CFStringGetCharactersPtr(str)) ? NULL : CFStringGetCStringPtr(str, kCFStringEncodingASCII); + buf->bufferedRangeStart = buf->bufferedRangeEnd = 0; +} + +CF_INLINE UniChar CFStringGetCharacterFromInlineBuffer(CFStringInlineBuffer *buf, CFIndex idx) { + if (idx < 0 || idx >= buf->rangeToBuffer.length) return 0; + if (buf->directUniCharBuffer) return buf->directUniCharBuffer[idx + buf->rangeToBuffer.location]; + if (buf->directCStringBuffer) return (UniChar)(buf->directCStringBuffer[idx + buf->rangeToBuffer.location]); + if (idx >= buf->bufferedRangeEnd || idx < buf->bufferedRangeStart) { + if ((buf->bufferedRangeStart = idx - 4) < 0) buf->bufferedRangeStart = 0; + buf->bufferedRangeEnd = buf->bufferedRangeStart + __kCFStringInlineBufferLength; + if (buf->bufferedRangeEnd > buf->rangeToBuffer.length) buf->bufferedRangeEnd = buf->rangeToBuffer.length; + CFStringGetCharacters(buf->theString, CFRangeMake(buf->rangeToBuffer.location + buf->bufferedRangeStart, buf->bufferedRangeEnd - buf->bufferedRangeStart), buf->buffer); + } + return buf->buffer[idx - buf->bufferedRangeStart]; +} + +#else +/* If INLINE functions are not available, we do somewhat less powerful macros that work similarly (except be aware that the buf argument is evaluated multiple times). +*/ +#define CFStringInitInlineBuffer(str, buf, range) \ + do {(buf)->theString = str; (buf)->rangeToBuffer = range; (buf)->directCStringBuffer = ((buf)->directUniCharBuffer = CFStringGetCharactersPtr(str)) ? NULL : CFStringGetCStringPtr(str, kCFStringEncodingASCII);} while (0) + +#define CFStringGetCharacterFromInlineBuffer(buf, idx) \ + (((idx) < 0 || (idx) >= (buf)->rangeToBuffer.length) ? 0 : ((buf)->directUniCharBuffer ? (buf)->directUniCharBuffer[(idx) + (buf)->rangeToBuffer.location] : ((buf)->directCStringBuffer ? (UniChar)((buf)->directCStringBuffer[(idx) + (buf)->rangeToBuffer.location]) : CFStringGetCharacterAtIndex((buf)->theString, (idx) + (buf)->rangeToBuffer.location)))) + +#endif /* CF_INLINE */ + + + +/* UTF-16 surrogate support + */ +CF_INLINE Boolean CFStringIsSurrogateHighCharacter(UniChar character) { + return ((character >= 0xD800UL) && (character <= 0xDBFFUL) ? true : false); +} + +CF_INLINE Boolean CFStringIsSurrogateLowCharacter(UniChar character) { + return ((character >= 0xDC00UL) && (character <= 0xDFFFUL) ? true : false); +} + +CF_INLINE UTF32Char CFStringGetLongCharacterForSurrogatePair(UniChar surrogateHigh, UniChar surrogateLow) { + return (UTF32Char)(((surrogateHigh - 0xD800UL) << 10) + (surrogateLow - 0xDC00UL) + 0x0010000UL); +} + +// Maps a UTF-32 character to a pair of UTF-16 surrogate characters. The buffer pointed by surrogates has to have space for at least 2 UTF-16 characters. Returns true if mapped to a surrogate pair. +CF_INLINE Boolean CFStringGetSurrogatePairForLongCharacter(UTF32Char character, UniChar *surrogates) { + if ((character > 0xFFFFUL) && (character < 0x110000UL)) { // Non-BMP character + character -= 0x10000; + if (NULL != surrogates) { + surrogates[0] = (UniChar)((character >> 10) + 0xD800UL); + surrogates[1] = (UniChar)((character & 0x3FF) + 0xDC00UL); + } + return true; + } else { + if (NULL != surrogates) *surrogates = (UniChar)character; + return false; + } +} + +/* Rest of the stuff in this file is private and should not be used directly +*/ +/* For debugging only; output goes to stderr + Use CFShow() to printf the description of any CFType; + Use CFShowStr() to printf detailed info about a CFString +*/ +CF_EXPORT +void CFShow(CFTypeRef obj); + +CF_EXPORT +void CFShowStr(CFStringRef str); + +/* This function is private and should not be used directly */ +CF_EXPORT +CFStringRef __CFStringMakeConstantString(const char *cStr) CF_FORMAT_ARGUMENT(1); /* Private; do not use */ + +CF_EXTERN_C_END +CF_IMPLICIT_BRIDGING_DISABLED + +#endif /* ! __COREFOUNDATION_CFSTRING__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFTargetConditionals.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFTargetConditionals.h new file mode 100644 index 0000000..4714be2 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CFTargetConditionals.h @@ -0,0 +1,283 @@ +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// + +/* + File: TargetConditionals.h + + Contains: Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone + + Note: TargetConditionals.h in 3.4 Universal Interfaces works + with all compilers. This header only recognizes compilers + known to run on Mac OS X. + +*/ + +#if __has_include() +#include +#else + +#ifndef __TARGETCONDITIONALS__ +#define __TARGETCONDITIONALS__ +/**************************************************************************************************** + + TARGET_CPU_* + These conditionals specify which microprocessor instruction set is being + generated. At most one of these is true, the rest are false. + + TARGET_CPU_PPC - Compiler is generating PowerPC instructions for 32-bit mode + TARGET_CPU_PPC64 - Compiler is generating PowerPC instructions for 64-bit mode + TARGET_CPU_68K - Compiler is generating 680x0 instructions + TARGET_CPU_X86 - Compiler is generating x86 instructions + TARGET_CPU_ARM - Compiler is generating ARM instructions + TARGET_CPU_MIPS - Compiler is generating MIPS instructions + TARGET_CPU_SPARC - Compiler is generating Sparc instructions + TARGET_CPU_ALPHA - Compiler is generating Dec Alpha instructions + TARGET_CPU_WASM32 - Compiler is generating WebAssembly instructions for 32-bit mode + + + TARGET_OS_* + These conditionals specify in which Operating System the generated code will + run. Indention is used to show which conditionals are evolutionary subclasses. + + The MAC/WIN32/UNIX conditionals are mutually exclusive. + The IOS/TV/WATCH conditionals are mutually exclusive. + + + TARGET_OS_WIN32 - Generated code will run under 32-bit Windows + TARGET_OS_UNIX - Generated code will run under some Unix (not OSX) + TARGET_OS_CYGWIN - Generated code will run under 64-bit Cygwin + TARGET_OS_WASI - Generated code will run under WebAssembly System Interface + TARGET_OS_MAC - Generated code will run under Mac OS X variant + TARGET_OS_IPHONE - Generated code for firmware, devices, or simulator + TARGET_OS_IOS - Generated code will run under iOS + TARGET_OS_TV - Generated code will run under Apple TV OS + TARGET_OS_WATCH - Generated code will run under Apple Watch OS + TARGET_OS_SIMULATOR - Generated code will run under a simulator + TARGET_OS_EMBEDDED - Generated code for firmware + + TARGET_IPHONE_SIMULATOR - DEPRECATED: Same as TARGET_OS_SIMULATOR + TARGET_OS_NANO - DEPRECATED: Same as TARGET_OS_WATCH + + TARGET_RT_* + These conditionals specify in which runtime the generated code will + run. This is needed when the OS and CPU support more than one runtime + (e.g. Mac OS X supports CFM and mach-o). + + TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers + TARGET_RT_BIG_ENDIAN - Generated code uses big endian format for integers + TARGET_RT_64_BIT - Generated code uses 64-bit pointers + TARGET_RT_MAC_CFM - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used + TARGET_RT_MAC_MACHO - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used + + +****************************************************************************************************/ + +#if __APPLE__ +#define TARGET_OS_DARWIN 1 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __ANDROID__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 1 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __linux__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __CYGWIN__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 1 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 1 +#define TARGET_OS_WASI 0 +#elif _WIN32 || _WIN64 +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 1 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __unix__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 1 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 0 +#elif __wasi__ +#define TARGET_OS_DARWIN 0 +#define TARGET_OS_LINUX 0 +#define TARGET_OS_WINDOWS 0 +#define TARGET_OS_BSD 0 +#define TARGET_OS_ANDROID 0 +#define TARGET_OS_CYGWIN 0 +#define TARGET_OS_WASI 1 +#else +#error unknown operating system +#endif + +#define TARGET_OS_WIN32 TARGET_OS_WINDOWS +#define TARGET_OS_MAC TARGET_OS_DARWIN +#define TARGET_OS_OSX TARGET_OS_DARWIN + +// iOS, watchOS, and tvOS are not supported +#define TARGET_OS_IPHONE 0 +#define TARGET_OS_IOS 0 +#define TARGET_OS_WATCH 0 +#define TARGET_OS_TV 0 + +#if __x86_64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 1 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __arm64__ || __aarch64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 1 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __mips64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 1 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __powerpc64__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 1 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __i386__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 1 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __arm__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 1 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __mips__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 1 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __powerpc__ +#define TARGET_CPU_PPC 1 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 0 +#elif __s390x__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 1 +#define TARGET_CPU_WASM32 0 +#elif __wasm32__ +#define TARGET_CPU_PPC 0 +#define TARGET_CPU_PPC64 0 +#define TARGET_CPU_X86 0 +#define TARGET_CPU_X86_64 0 +#define TARGET_CPU_ARM 0 +#define TARGET_CPU_ARM64 0 +#define TARGET_CPU_MIPS 0 +#define TARGET_CPU_MIPS64 0 +#define TARGET_CPU_S390X 0 +#define TARGET_CPU_WASM32 1 +#else +#error unknown architecture +#endif + +#if __LITTLE_ENDIAN__ +#define TARGET_RT_LITTLE_ENDIAN 1 +#define TARGET_RT_BIG_ENDIAN 0 +#elif __BIG_ENDIAN__ +#define TARGET_RT_LITTLE_ENDIAN 0 +#define TARGET_RT_BIG_ENDIAN 1 +#else +#error unknown endian +#endif + +#if __LP64__ || __LLP64__ || __POINTER_WIDTH__-0 == 64 +#define TARGET_RT_64_BIT 1 +#else +#define TARGET_RT_64_BIT 0 +#endif + +#endif /* __TARGETCONDITIONALS__ */ + +#endif // __has_include diff --git a/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CoreFoundation.h b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CoreFoundation.h new file mode 100644 index 0000000..5ca1382 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/SwiftCorelibsCoreFoundation/CoreFoundation.h @@ -0,0 +1,56 @@ +/* CoreFoundation.h + Copyright (c) 1998-2019, Apple Inc. and the Swift project authors + + Portions Copyright (c) 2014-2019, Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +*/ + +#if !defined(__COREFOUNDATION_COREFOUNDATION__) +#define __COREFOUNDATION_COREFOUNDATION__ 1 +#define __COREFOUNDATION__ 1 + +#if !defined(CF_EXCLUDE_CSTD_HEADERS) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if !defined(__wasi__) +#include +#endif +#include +#include +#include +#include +#include +#include + +#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) + +#include +#include +#include + +#endif + +#endif + +#include "CFBase.h" +#include "CFArray.h" +#include "CFCharacterSet.h" +#include "CFData.h" +#include "CFDictionary.h" +#include "CFNumber.h" +#include "CFString.h" + +#if TARGET_OS_OSX || TARGET_OS_IPHONE +#endif + +#endif /* ! __COREFOUNDATION_COREFOUNDATION__ */ diff --git a/Sources/SwiftCorelibsCoreFoundation/include/module.modulemap b/Sources/SwiftCorelibsCoreFoundation/include/module.modulemap new file mode 100644 index 0000000..f1c2bf8 --- /dev/null +++ b/Sources/SwiftCorelibsCoreFoundation/include/module.modulemap @@ -0,0 +1,5 @@ +module SwiftCorelibsCoreFoundation { + header "SwiftCorelibsCoreFoundation/CoreFoundation.h" + + export * +} diff --git a/Sources/Utilities/HashTable.cpp b/Sources/Utilities/HashTable.cpp index a0b63aa..119f26d 100644 --- a/Sources/Utilities/HashTable.cpp +++ b/Sources/Utilities/HashTable.cpp @@ -1,6 +1,7 @@ #include "Utilities/HashTable.h" #include +#include #include "Utilities/Heap.h" @@ -103,7 +104,7 @@ void UntypedTable::create_buckets() { size_t num_buckets = (1 << initial_bucket_mask_width); _buckets = _heap->alloc(num_buckets); - std::memset(_buckets, 0, sizeof(Bucket) * num_buckets); + memset(_buckets, 0, sizeof(Bucket) * num_buckets); } void UntypedTable::grow_buckets() { @@ -126,7 +127,7 @@ void UntypedTable::grow_buckets() { } new_buckets = _heap->alloc(num_buckets); } - std::memset(new_buckets, 0, sizeof(Bucket) * num_buckets); + memset(new_buckets, 0, sizeof(Bucket) * num_buckets); // redistribute old buckets into new if (new_buckets) { diff --git a/Sources/Utilities/Heap.cpp b/Sources/Utilities/Heap.cpp index 4205268..ffe759b 100644 --- a/Sources/Utilities/Heap.cpp +++ b/Sources/Utilities/Heap.cpp @@ -1,6 +1,7 @@ #include "Utilities/Heap.h" #include +#include namespace util { diff --git a/Sources/Utilities/include/Utilities/Base.h b/Sources/Utilities/include/Utilities/Base.h new file mode 100644 index 0000000..3d561d0 --- /dev/null +++ b/Sources/Utilities/include/Utilities/Base.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include + +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif +#ifndef __has_extension +#define __has_extension(x) 0 +#endif + +#if __has_feature(assume_nonnull) +#define UTIL_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define UTIL_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") +#else +#define UTIL_ASSUME_NONNULL_BEGIN +#define UTIL_ASSUME_NONNULL_END +#endif + +#if !__has_feature(nullability) +#ifndef _Nullable +#define _Nullable +#endif +#ifndef _Nonnull +#define _Nonnull +#endif +#ifndef _Null_unspecified +#define _Null_unspecified +#endif +#endif diff --git a/Sources/Utilities/include/Utilities/CFPointer.h b/Sources/Utilities/include/Utilities/CFPointer.h index 36d962c..48aed93 100644 --- a/Sources/Utilities/include/Utilities/CFPointer.h +++ b/Sources/Utilities/include/Utilities/CFPointer.h @@ -1,9 +1,16 @@ #pragma once -#include #include -CF_ASSUME_NONNULL_BEGIN +#if __APPLE__ +#include +#else +#include +#endif + +#include + +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -93,4 +100,4 @@ template class cf_ptr { } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/FreeDeleter.h b/Sources/Utilities/include/Utilities/FreeDeleter.h index ab82bc3..1cf7641 100644 --- a/Sources/Utilities/include/Utilities/FreeDeleter.h +++ b/Sources/Utilities/include/Utilities/FreeDeleter.h @@ -1,9 +1,10 @@ #pragma once -#include #include -CF_ASSUME_NONNULL_BEGIN +#include + +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -18,4 +19,4 @@ class free_deleter { } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/HashTable.h b/Sources/Utilities/include/Utilities/HashTable.h index 03e088e..5bbd98a 100644 --- a/Sources/Utilities/include/Utilities/HashTable.h +++ b/Sources/Utilities/include/Utilities/HashTable.h @@ -1,10 +1,10 @@ #pragma once -#include +#include -#include +#include -CF_ASSUME_NONNULL_BEGIN +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -125,4 +125,4 @@ template class Table : public UntypedTable { } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/Heap.h b/Sources/Utilities/include/Utilities/Heap.h index 4447678..19413a7 100644 --- a/Sources/Utilities/include/Utilities/Heap.h +++ b/Sources/Utilities/include/Utilities/Heap.h @@ -1,10 +1,10 @@ #pragma once -#include +#include -#include +#include -CF_ASSUME_NONNULL_BEGIN +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -72,4 +72,4 @@ template class InlineHeap : public Heap { } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/List.h b/Sources/Utilities/include/Utilities/List.h index 7a0b956..10b244f 100644 --- a/Sources/Utilities/include/Utilities/List.h +++ b/Sources/Utilities/include/Utilities/List.h @@ -1,11 +1,11 @@ #pragma once -#include +#include -#include +#include #include -CF_ASSUME_NONNULL_BEGIN +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -170,4 +170,4 @@ void UInt64ForwardList::pop_front() { ForwardList::pop_front(); } } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/ObjCPointer.h b/Sources/Utilities/include/Utilities/ObjCPointer.h index 8e8363f..1fbdc0e 100644 --- a/Sources/Utilities/include/Utilities/ObjCPointer.h +++ b/Sources/Utilities/include/Utilities/ObjCPointer.h @@ -1,9 +1,12 @@ #pragma once -#include +#ifdef __OBJC__ + #include -CF_ASSUME_NONNULL_BEGIN +#include + +UTIL_ASSUME_NONNULL_BEGIN // Redeclare APIs from the Objective-C runtime. // These functions are not available through public headers, but are guaranteed @@ -99,4 +102,6 @@ template class objc_ptr { } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END + +#endif diff --git a/Sources/Utilities/include/Utilities/SwiftBridging.h b/Sources/Utilities/include/Utilities/SwiftBridging.h deleted file mode 100644 index fbe64f8..0000000 --- a/Sources/Utilities/include/Utilities/SwiftBridging.h +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (C) 2025 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#if __has_include() - -#include - -#ifndef SWIFT_NONESCAPABLE -#define SWIFT_NONESCAPABLE -#endif - -#ifndef SWIFT_ESCAPABLE -#define SWIFT_ESCAPABLE -#endif - -#ifndef SWIFT_RETURNS_UNRETAINED -#define SWIFT_RETURNS_UNRETAINED -#endif - -#ifndef SWIFT_ESCAPABLE_IF -#define SWIFT_ESCAPABLE_IF(...) -#endif - -#ifndef SWIFT_PRIVATE_FILEID -#define SWIFT_PRIVATE_FILEID(_fileID) -#endif - -#else - -// Copied from https://github.com/swiftlang/swift/blob/ff8b9f145320b02bc6de75163d78528f210bdba6/lib/ClangImporter/SwiftBridging/swift/bridging - -// -*- C++ -*- -//===------------------ bridging - C++ and Swift Interop --------*- C++ -*-===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// -// -// This file provides common utilities and annotations that are useful for C++ -// codebases that interoperate with Swift. -// -//===----------------------------------------------------------------------===// -#ifndef SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H -#define SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H - -#ifdef __has_attribute -#define _CXX_INTEROP_HAS_ATTRIBUTE(x) __has_attribute(x) -#else -#define _CXX_INTEROP_HAS_ATTRIBUTE(x) 0 -#endif - -#if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr) - -/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of all -/// of the objects it references. Such type should not reference any objects whose -/// lifetime is controlled externally. This annotation allows Swift to import methods -/// that return a `class` or `struct` type that is annotated with this macro. -#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned"))) - -/// Specifies that a C++ method returns a value that is presumed to contain -/// objects whose lifetime is not dependent on `this` or other parameters passed -/// to the method. -#define SWIFT_RETURNS_INDEPENDENT_VALUE __attribute__((swift_attr("import_unsafe"))) - -#define _CXX_INTEROP_STRINGIFY(_x) #_x - -#define _CXX_INTEROP_CONCAT_(a,b,c,d,e,f,g,i,j,k,l,m,n,o,p,...) \ - #a "," #b "," #c "," #d "," #e "," #f "," #g "," #i "," #j "," #k "," \ - #l "," #m "," #n "," #o "," #p -#define _CXX_INTEROP_CONCAT(...) \ - _CXX_INTEROP_CONCAT_(__VA_ARGS__,,,,,,,,,,,,,,,,,) - -/// Specifies that a C++ `class` or `struct` is reference-counted using -/// the given `retain` and `release` functions. This annotation lets Swift import -/// such a type as reference counted type in Swift, taking advantage of Swift's -/// automatic reference counting. -/// -/// This example shows how to use this macro to let Swift know that -/// a non-copyable reference counted C++ class can be imported as a reference counted type in Swift: -/// ```c++ -/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject) -/// SharedObject : NonCopyable, IntrusiveReferenceCounted { -/// public: -/// static SharedObject* create(); -/// void doSomething(); -/// }; -/// -/// void retainSharedObject(SharedObject *); -/// void releaseSharedObject(SharedObject *); -/// ``` -/// -/// Then, the Swift programmer would be able to use it in the following manner: -/// -/// ```swift -/// let object = SharedObject.create() -/// object.doSomething() -/// // The Swift compiler will release object here. -/// ``` -#define SWIFT_SHARED_REFERENCE(_retain, _release) \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release)))) - -/// Specifies that a C++ `class` or `struct` is a reference type whose lifetime -/// is presumed to be immortal, i.e. the reference to such object is presumed to -/// always be valid. This annotation lets Swift import such a type as a reference -/// type in Swift. -//// -/// This example shows how to use this macro to let Swift know that -/// a non-copyable singleton C++ class can be imported as a reference type in Swift: -/// ```c++ -/// class SWIFT_IMMORTAL_REFERENCE -/// LoggerSingleton : NonCopyable { -/// public: -/// static LoggerSingleton &getInstance(); -/// void log(int x); -/// }; -/// ``` -/// -/// Then, the Swift programmer would be able to use it in the following manner: -/// -/// ```swift -/// let logger = LoggerSingleton.getInstance() -/// logger.log(123) -/// ``` -#define SWIFT_IMMORTAL_REFERENCE \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:immortal)))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:immortal)))) - -/// Specifies that a C++ `class` or `struct` is a reference type whose lifetime -/// is not managed automatically. The programmer must validate that any reference -/// to such object is valid themselves. This annotation lets Swift import such a type as a reference type in Swift. -#define SWIFT_UNSAFE_REFERENCE \ - __attribute__((swift_attr("import_reference"))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:immortal)))) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:immortal)))) \ - __attribute__((swift_attr("unsafe"))) - -/// Specifies a name that will be used in Swift for this declaration instead of its original name. -#define SWIFT_NAME(_name) __attribute__((swift_name(#_name))) - -/// Specifies that a specific C++ `class` or `struct` conforms to a -/// a specific Swift protocol. -/// -/// This example shows how to use this macro to conform a class template to a Swift protocol: -/// ``` -/// template -/// class SWIFT_CONFORMS_TO_PROTOCOL(SwiftModule.ProtocolName) -/// CustomClass {}; -/// ``` -#define SWIFT_CONFORMS_TO_PROTOCOL(_moduleName_protocolName) \ - __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(conforms_to:_moduleName_protocolName)))) - -/// Specifies that a specific C++ method should be imported as a computed -/// property. If this macro is specified on a getter, a getter will be -/// synthesized. If this macro is specified on a setter, both a getter and -/// setter will be synthesized. -/// -/// For example: -/// ``` -/// int getX() SWIFT_COMPUTED_PROPERTY; -/// ``` -/// Will be imported as `var x: CInt {...}`. -#define SWIFT_COMPUTED_PROPERTY \ - __attribute__((swift_attr("import_computed_property"))) - -/// Specifies that a specific **constant** C++ member function should be imported as -/// `mutating` Swift method. This annotation should be added to constant C++ member functions -/// that mutate `mutable` fields in a C++ object, to let Swift know that this function is still mutating -/// and thus that it should become a `mutating` method in Swift. -#define SWIFT_MUTATING \ - __attribute__((swift_attr("mutating"))) - -/// Specifies that a specific c++ type such class or struct should be imported as type marked -/// as `@unchecked Sendable` type in swift. If this annotation is used, the type is therefore allowed to -/// use safely across async contexts. -/// -/// For example -/// ``` -/// class SWIFT_UNCHECKED_SENDABLE CustomUserType -/// { ... } -/// ``` -/// Will be imported as `struct CustomUserType: @unchecked Sendable` -#define SWIFT_UNCHECKED_SENDABLE \ - __attribute__((swift_attr("@Sendable"))) - -/// Specifies that a specific c++ type such class or struct should be imported -/// as a non-copyable Swift value type. -#define SWIFT_NONCOPYABLE \ - __attribute__((swift_attr("~Copyable"))) - -/// Specifies that a specific c++ type such class or struct should be imported -/// as a non-escapable Swift value type when the non-escapable language feature -/// is enabled. -#define SWIFT_NONESCAPABLE \ - __attribute__((swift_attr("~Escapable"))) - -/// Specifies that a specific c++ type such class or struct should be imported -/// as a escapable Swift value. While this matches the default behavior, -/// in safe mode interop mode it ensures that the type is not marked as -/// unsafe. -#define SWIFT_ESCAPABLE \ - __attribute__((swift_attr("Escapable"))) - -/// Specifies that a C++ `class` or `struct` should be imported as a escapable -/// Swift value if all of the specified template arguments are escapable. -#define SWIFT_ESCAPABLE_IF(...) \ - __attribute__((swift_attr("escapable_if:" _CXX_INTEROP_CONCAT(__VA_ARGS__)))) - -/// Specifies that the return value is passed as owned for C++ functions and -/// methods returning types annotated as `SWIFT_SHARED_REFERENCE` -#define SWIFT_RETURNS_RETAINED __attribute__((swift_attr("returns_retained"))) -/// Specifies that the return value is passed as unowned for C++ functions and -/// methods returning types annotated as `SWIFT_SHARED_REFERENCE` -#define SWIFT_RETURNS_UNRETAINED \ - __attribute__((swift_attr("returns_unretained"))) - -/// Applied to a C++ foreign reference type annotated with -/// SWIFT_SHARED_REFERENCE. Indicates that C++ APIs returning this type are -/// assumed to return an unowned (+0) value by default, unless explicitly annotated -/// with SWIFT_RETURNS_RETAINED. -/// -/// For example: -/// ```c++ -/// struct SWIFT_SHARED_REFERENCE(retainBar, releaseBar) -/// SWIFT_RETURNED_AS_UNRETAINED_BY_DEFAULT -/// Bar { ... }; -/// ``` -/// -/// In Swift, C++ APIs returning `Bar*` will be assumed to return an unowned -/// value. -#define SWIFT_RETURNED_AS_UNRETAINED_BY_DEFAULT \ - __attribute__((swift_attr("returned_as_unretained_by_default"))) - -/// Specifies that the non-public members of a C++ class, struct, or union can -/// be accessed from extensions of that type, in the given file ID. -/// -/// In other words, Swift's access controls will behave as if the non-public -/// members of the annotated C++ class were privated declared in the specified -/// Swift source file, rather than in a C++ header file/Clang module. -/// -/// For example, we can annotate a C++ class definition like this: -/// -/// ```c++ -/// class SWIFT_PRIVATE_FILEID("MySwiftModule/MySwiftFile.swift") -/// MyCxxClass { -/// private: -/// void privateMethod(); -/// int privateStorage; -/// }; -/// ``` -/// -/// Then, Swift extensions of `MyCxxClass` in `MySwiftModule/MySwiftFile.swift` -/// are allowed to access `privateMethod()` and `privateStorage`: -/// -/// ```swift -/// //-- MySwiftModule/SwiftFile.swift -/// extension MyCxxClass { -/// func ext() { -/// privateMethod() -/// print("\(privateStorage)") -/// } -/// } -/// ``` -/// -/// Non-public access is still forbidden outside of extensions and outside of -/// the designated file ID. -#define SWIFT_PRIVATE_FILEID(_fileID) \ - __attribute__((swift_attr("private_fileid:" _fileID))) - -#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr) - -// Empty defines for compilers that don't support `attribute(swift_attr)`. -#define SWIFT_SELF_CONTAINED -#define SWIFT_RETURNS_INDEPENDENT_VALUE -#define SWIFT_SHARED_REFERENCE(_retain, _release) -#define SWIFT_IMMORTAL_REFERENCE -#define SWIFT_UNSAFE_REFERENCE -#define SWIFT_NAME(_name) -#define SWIFT_CONFORMS_TO_PROTOCOL(_moduleName_protocolName) -#define SWIFT_COMPUTED_PROPERTY -#define SWIFT_MUTATING -#define SWIFT_UNCHECKED_SENDABLE -#define SWIFT_NONCOPYABLE -#define SWIFT_NONESCAPABLE -#define SWIFT_ESCAPABLE -#define SWIFT_ESCAPABLE_IF(...) -#define SWIFT_RETURNS_RETAINED -#define SWIFT_RETURNS_UNRETAINED -#define SWIFT_PRIVATE_FILEID(_fileID) - -#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr) - -#undef _CXX_INTEROP_HAS_ATTRIBUTE - -#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H - -#endif diff --git a/Sources/Utilities/include/Utilities/TaggedPointer.h b/Sources/Utilities/include/Utilities/TaggedPointer.h index ef74fee..6f3f6fd 100644 --- a/Sources/Utilities/include/Utilities/TaggedPointer.h +++ b/Sources/Utilities/include/Utilities/TaggedPointer.h @@ -1,8 +1,8 @@ #pragma once -#include +#include -CF_ASSUME_NONNULL_BEGIN +UTIL_ASSUME_NONNULL_BEGIN namespace util { @@ -26,10 +26,10 @@ template class tagged_ptr { T *_Nullable get() { return reinterpret_cast(_value & ~mask); }; const T *_Nullable get() const { return reinterpret_cast(_value & ~mask); }; - bool operator==(nullptr_t) const noexcept { return _value == 0; }; - bool operator!=(nullptr_t) const noexcept { return _value != 0; }; + bool operator==(std::nullptr_t) const noexcept { return _value == 0; }; + bool operator!=(std::nullptr_t) const noexcept { return _value != 0; }; }; } // namespace util -CF_ASSUME_NONNULL_END +UTIL_ASSUME_NONNULL_END diff --git a/Sources/Utilities/include/Utilities/Utilities.h b/Sources/Utilities/include/Utilities/Utilities.h index bb03247..6b675e3 100644 --- a/Sources/Utilities/include/Utilities/Utilities.h +++ b/Sources/Utilities/include/Utilities/Utilities.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/Sources/Utilities/include/module.modulemap b/Sources/Utilities/include/module.modulemap index aaa7a3f..633820b 100644 --- a/Sources/Utilities/include/module.modulemap +++ b/Sources/Utilities/include/module.modulemap @@ -1,4 +1,6 @@ module Utilities { header "Utilities/Utilities.h" requires cplusplus + + export * }