Skip to content

Commit 26e62ed

Browse files
author
Dave Abrahams
committed
Add missing instances of .self
Passing a type as a metatype directly is no longer supported
1 parent 4190fe5 commit 26e62ed

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

stdlib/public/SDK/Dispatch/Data.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
109109
///
110110
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
111111
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
112-
self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * sizeof(SourceType))
112+
self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * sizeof(SourceType.self))
113113
}
114114

115115
private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
@@ -160,9 +160,9 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
160160
precondition(r.endIndex >= 0)
161161
precondition(r.endIndex <= cnt, "The range is outside the bounds of the data")
162162

163-
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * sizeof(DestinationType), r.count))
163+
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * sizeof(DestinationType.self), r.count))
164164
} else {
165-
copyRange = 0..<Swift.min(buffer.count * sizeof(DestinationType), cnt)
165+
copyRange = 0..<Swift.min(buffer.count * sizeof(DestinationType.self), cnt)
166166
}
167167

168168
guard !copyRange.isEmpty else { return 0 }

test/1_stdlib/TestData.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,18 @@ class TestData : TestDataSuper {
397397

398398
func testCopyBytes() {
399399
let c = 10
400-
let underlyingBuffer = malloc(c * strideof(UInt16))!
400+
let underlyingBuffer = malloc(c * strideof(UInt16.self))!
401401
let buffer = UnsafeMutableBufferPointer<UInt16>(start: UnsafeMutablePointer<UInt16>(underlyingBuffer), count: c)
402402

403403
buffer[0] = 0
404404
buffer[1] = 0
405405

406-
var data = Data(capacity: c * strideof(UInt16))!
407-
data.resetBytes(in: 0..<c * strideof(UInt16))
406+
var data = Data(capacity: c * strideof(UInt16.self))!
407+
data.resetBytes(in: 0..<c * strideof(UInt16.self))
408408
data[0] = 0xFF
409409
data[1] = 0xFF
410410
let copiedCount = data.copyBytes(to: buffer)
411-
expectEqual(copiedCount, c * strideof(UInt16))
411+
expectEqual(copiedCount, c * strideof(UInt16.self))
412412

413413
expectEqual(buffer[0], 0xFFFF)
414414
free(underlyingBuffer)
@@ -419,7 +419,7 @@ class TestData : TestDataSuper {
419419
var data = a.withUnsafeBufferPointer {
420420
return Data(buffer: $0)
421421
}
422-
let expectedSize = strideof(UInt8) * a.count
422+
let expectedSize = strideof(UInt8.self) * a.count
423423
expectEqual(expectedSize, data.count)
424424

425425
let underlyingBuffer = unsafeBitCast(malloc(expectedSize - 1)!, to: UnsafeMutablePointer<UInt8>.self)
@@ -443,7 +443,7 @@ class TestData : TestDataSuper {
443443
var data = a.withUnsafeBufferPointer {
444444
return Data(buffer: $0)
445445
}
446-
let expectedSize = strideof(Int32) * a.count
446+
let expectedSize = strideof(Int32.self) * a.count
447447
expectEqual(expectedSize, data.count)
448448

449449
let underlyingBuffer = unsafeBitCast(malloc(expectedSize + 1)!, to: UnsafeMutablePointer<UInt8>.self)
@@ -606,14 +606,14 @@ class TestData : TestDataSuper {
606606
return Data(buffer: $0)
607607
}
608608

609-
var expectedSize = strideof(Int32) * a.count
609+
var expectedSize = strideof(Int32.self) * a.count
610610
expectEqual(expectedSize, data.count)
611611

612612
[false, true].withUnsafeBufferPointer {
613613
data.append($0)
614614
}
615615

616-
expectedSize += strideof(Bool) * 2
616+
expectedSize += strideof(Bool.self) * 2
617617
expectEqual(expectedSize, data.count)
618618

619619
let underlyingBuffer = unsafeBitCast(malloc(expectedSize)!, to: UnsafeMutablePointer<UInt8>.self)
@@ -716,48 +716,48 @@ class TestData : TestDataSuper {
716716
return Data(buffer: $0)
717717
}
718718

719-
expectEqual(data.count, strideof(MyStruct) * 3)
719+
expectEqual(data.count, strideof(MyStruct.self) * 3)
720720

721721

722722
// append
723723
stuff.withUnsafeBufferPointer {
724724
data.append($0)
725725
}
726726

727-
expectEqual(data.count, strideof(MyStruct) * 6)
727+
expectEqual(data.count, strideof(MyStruct.self) * 6)
728728

729729
// copyBytes
730730
do {
731731
// equal size
732-
let underlyingBuffer = malloc(6 * strideof(MyStruct))!
732+
let underlyingBuffer = malloc(6 * strideof(MyStruct.self))!
733733
defer { free(underlyingBuffer) }
734734

735735
let buffer = UnsafeMutableBufferPointer<MyStruct>(start: UnsafeMutablePointer<MyStruct>(underlyingBuffer), count: 6)
736736

737737
let byteCount = data.copyBytes(to: buffer)
738-
expectEqual(6 * strideof(MyStruct), byteCount)
738+
expectEqual(6 * strideof(MyStruct.self), byteCount)
739739
}
740740

741741
do {
742742
// undersized
743-
let underlyingBuffer = malloc(3 * strideof(MyStruct))!
743+
let underlyingBuffer = malloc(3 * strideof(MyStruct.self))!
744744
defer { free(underlyingBuffer) }
745745

746746
let buffer = UnsafeMutableBufferPointer<MyStruct>(start: UnsafeMutablePointer<MyStruct>(underlyingBuffer), count: 3)
747747

748748
let byteCount = data.copyBytes(to: buffer)
749-
expectEqual(3 * strideof(MyStruct), byteCount)
749+
expectEqual(3 * strideof(MyStruct.self), byteCount)
750750
}
751751

752752
do {
753753
// oversized
754-
let underlyingBuffer = malloc(12 * strideof(MyStruct))!
754+
let underlyingBuffer = malloc(12 * strideof(MyStruct.self))!
755755
defer { free(underlyingBuffer) }
756756

757757
let buffer = UnsafeMutableBufferPointer<MyStruct>(start: UnsafeMutablePointer<MyStruct>(underlyingBuffer), count: 6)
758758

759759
let byteCount = data.copyBytes(to: buffer)
760-
expectEqual(6 * strideof(MyStruct), byteCount)
760+
expectEqual(6 * strideof(MyStruct.self), byteCount)
761761
}
762762
}
763763

0 commit comments

Comments
 (0)