Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/FoundationEssentials/Data/Collections+DataProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

//===--- DataProtocol -----------------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Array: DataProtocol where Element == UInt8 {
public var regions: CollectionOfOne<Array<UInt8>> {
return CollectionOfOne(self)
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension ArraySlice: DataProtocol where Element == UInt8 {
public var regions: CollectionOfOne<ArraySlice<UInt8>> {
return CollectionOfOne(self)
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension ContiguousArray: DataProtocol where Element == UInt8 {
public var regions: CollectionOfOne<ContiguousArray<UInt8>> {
return CollectionOfOne(self)
Expand All @@ -42,14 +42,14 @@ extension ContiguousArray: DataProtocol where Element == UInt8 {
// }
// }

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension EmptyCollection : DataProtocol where Element == UInt8 {
public var regions: EmptyCollection<Data> {
return EmptyCollection<Data>()
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Repeated: DataProtocol where Element == UInt8 {
public typealias Regions = Repeated<Data>

Expand All @@ -61,8 +61,8 @@ extension Repeated: DataProtocol where Element == UInt8 {

//===--- MutableDataProtocol ----------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Array: MutableDataProtocol where Element == UInt8 { }

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension ContiguousArray: MutableDataProtocol where Element == UInt8 { }
22 changes: 11 additions & 11 deletions Sources/FoundationEssentials/Data/ContiguousBytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/// Indicates that the conforming type is a contiguous collection of raw bytes
/// whose underlying storage is directly accessible by withUnsafeBytes.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public protocol ContiguousBytes {
/// Calls the given closure with the contents of underlying storage.
///
Expand All @@ -28,28 +28,28 @@ public protocol ContiguousBytes {
//===--- Collection Conformances ------------------------------------------===//

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Array : ContiguousBytes where Element == UInt8 { }

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension ArraySlice : ContiguousBytes where Element == UInt8 { }

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension ContiguousArray : ContiguousBytes where Element == UInt8 { }

//===--- Pointer Conformances ---------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeRawBufferPointer : ContiguousBytes {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
return try body(self)
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeMutableRawBufferPointer : ContiguousBytes {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
Expand All @@ -58,7 +58,7 @@ extension UnsafeMutableRawBufferPointer : ContiguousBytes {
}

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeBufferPointer : ContiguousBytes where Element == UInt8 {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
Expand All @@ -67,7 +67,7 @@ extension UnsafeBufferPointer : ContiguousBytes where Element == UInt8 {
}

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeMutableBufferPointer : ContiguousBytes where Element == UInt8 {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
Expand All @@ -76,7 +76,7 @@ extension UnsafeMutableBufferPointer : ContiguousBytes where Element == UInt8 {
}

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension EmptyCollection : ContiguousBytes where Element == UInt8 {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
Expand All @@ -85,7 +85,7 @@ extension EmptyCollection : ContiguousBytes where Element == UInt8 {
}

// FIXME: When possible, expand conformance to `where Element : Trivial`.
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension CollectionOfOne : ContiguousBytes where Element == UInt8 {
@inlinable
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
Expand All @@ -98,7 +98,7 @@ extension CollectionOfOne : ContiguousBytes where Element == UInt8 {

//===--- Conditional Conformances -----------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Slice : ContiguousBytes where Base : ContiguousBytes {
public func withUnsafeBytes<ResultType>(_ body: (UnsafeRawBufferPointer) throws -> ResultType) rethrows -> ResultType {
let offset = base.distance(from: base.startIndex, to: self.startIndex)
Expand Down
10 changes: 5 additions & 5 deletions Sources/FoundationEssentials/Data/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Darwin
internal func __DataInvokeDeallocatorVirtualMemory(_ mem: UnsafeMutableRawPointer, _ length: Int) {
guard vm_deallocate(
mach_task_self_,
unsafeBitCast(mem, to: vm_address_t.self),
vm_address_t(UInt(bitPattern: mem)),
vm_size_t(length)) == ERR_SUCCESS else {
fatalError("*** __DataInvokeDeallocatorVirtualMemory(\(mem), \(length)) failed")
}
Expand Down Expand Up @@ -80,7 +80,7 @@ internal func _withStackOrHeapBuffer(capacity: Int, _ body: (UnsafeMutableBuffer
// coexist without a conflicting ObjC class name, so it was renamed.
// The old name must not be used in the new runtime.
@usableFromInline
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
internal final class __DataStorage : @unchecked Sendable {
@usableFromInline static let maxSize = Int.max >> 1
@usableFromInline static let vmOpsThreshold = Platform.pageSize * 4
Expand Down Expand Up @@ -506,7 +506,7 @@ internal final class __DataStorage : @unchecked Sendable {
}

@frozen
@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollection, RangeReplaceableCollection, MutableDataProtocol, ContiguousBytes, Sendable {

public typealias Index = Int
Expand Down Expand Up @@ -2541,7 +2541,7 @@ extension Data {
#endif //!FOUNDATION_FRAMEWORK


@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable {
/// A human-readable description for the data.
public var description: String {
Expand Down Expand Up @@ -2572,7 +2572,7 @@ extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomRe
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Data : Codable {
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
Expand Down
12 changes: 6 additions & 6 deletions Sources/FoundationEssentials/Data/DataProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Glibc

//===--- DataProtocol -----------------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public protocol DataProtocol : RandomAccessCollection where Element == UInt8, SubSequence : DataProtocol {
// FIXME: Remove in favor of opaque type on `regions`.
associatedtype Regions: BidirectionalCollection where Regions.Element : DataProtocol & ContiguousBytes, Regions.Element.SubSequence : ContiguousBytes
Expand Down Expand Up @@ -71,7 +71,7 @@ public protocol DataProtocol : RandomAccessCollection where Element == UInt8, Su

//===--- MutableDataProtocol ----------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public protocol MutableDataProtocol : DataProtocol, MutableCollection, RangeReplaceableCollection {
/// Replaces the contents of the buffer at the given range with zeroes.
///
Expand All @@ -82,7 +82,7 @@ public protocol MutableDataProtocol : DataProtocol, MutableCollection, RangeRepl

//===--- DataProtocol Extensions ------------------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension DataProtocol {
public func firstRange<D: DataProtocol>(of data: D) -> Range<Index>? {
return self.firstRange(of: data, in: self.startIndex ..< self.endIndex)
Expand Down Expand Up @@ -200,7 +200,7 @@ extension DataProtocol {
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension DataProtocol where Self : ContiguousBytes {
public func copyBytes<DestinationType, R: RangeExpression>(to ptr: UnsafeMutableBufferPointer<DestinationType>, from range: R) where R.Bound == Index {
precondition(ptr.baseAddress != nil)
Expand All @@ -216,7 +216,7 @@ extension DataProtocol where Self : ContiguousBytes {

//===--- MutableDataProtocol Extensions -----------------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension MutableDataProtocol {
public mutating func resetBytes<R: RangeExpression>(in range: R) where R.Bound == Index {
let r = range.relative(to: self)
Expand All @@ -227,7 +227,7 @@ extension MutableDataProtocol {

//===--- DataProtocol Conditional Conformances ----------------------------===//

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension Slice : DataProtocol where Base : DataProtocol {
public typealias Regions = [Base.Regions.Element.SubSequence]

Expand Down
4 changes: 2 additions & 2 deletions Sources/FoundationEssentials/Data/Pointers+DataProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
//===----------------------------------------------------------------------===//


@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeRawBufferPointer : DataProtocol {
public var regions: CollectionOfOne<UnsafeRawBufferPointer> {
return CollectionOfOne(self)
}
}

@available(macOS 10.10, iOS 8.0, *)
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
extension UnsafeBufferPointer : DataProtocol where Element == UInt8 {
public var regions: CollectionOfOne<UnsafeBufferPointer<Element>> {
return CollectionOfOne(self)
Expand Down
4 changes: 2 additions & 2 deletions Sources/FoundationEssentials/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ internal struct Platform {
#if canImport(Darwin)
if vm_copy(
mach_task_self_,
unsafeBitCast(source, to: vm_address_t.self),
vm_address_t(UInt(bitPattern: source)),
vm_size_t(length),
unsafeBitCast(dest, to: vm_address_t.self)) != KERN_SUCCESS {
vm_address_t(UInt(bitPattern: dest))) != KERN_SUCCESS {
memmove(dest, source, length)
}
#else
Expand Down
4 changes: 2 additions & 2 deletions Sources/FoundationEssentials/UUID.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
// This source file is part of the Swift open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
Expand All @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

@_implementationOnly import _CShims
@_implementationOnly import _CShims // uuid.h

public typealias uuid_t = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
public typealias uuid_string_t = (Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8, Int8)
Expand Down
Loading