@@ -16,11 +16,11 @@ class Missile {
16
16
UnsafeMutableRawPointerExtraTestSuite . test ( " initializeMemory " ) {
17
17
Missile . missilesLaunched = 0
18
18
do {
19
- let sizeInBytes = 3 * strideof ( Missile . self )
19
+ let sizeInBytes = 3 * MemoryLayout < Missile> . stride
20
20
var p1 = UnsafeMutableRawPointer . allocate (
21
- bytes: sizeInBytes, alignedTo: alignof ( Missile . self ) )
21
+ bytes: sizeInBytes, alignedTo: MemoryLayout < Missile> . alignment )
22
22
defer {
23
- p1. deallocate ( bytes: sizeInBytes, alignedTo: alignof ( Missile . self ) )
23
+ p1. deallocate ( bytes: sizeInBytes, alignedTo: MemoryLayout < Missile> . alignment )
24
24
}
25
25
var ptrM = p1. initializeMemory ( as: Missile . self, to: Missile ( 1 ) )
26
26
p1. initializeMemory ( as: Missile . self, at: 1 , count: 2 , to: Missile ( 2 ) )
@@ -29,9 +29,9 @@ UnsafeMutableRawPointerExtraTestSuite.test("initializeMemory") {
29
29
expectEqual ( 2 , ptrM [ 2 ] . number)
30
30
31
31
var p2 = UnsafeMutableRawPointer . allocate (
32
- bytes: sizeInBytes, alignedTo: alignof ( Missile . self ) )
32
+ bytes: sizeInBytes, alignedTo: MemoryLayout < Missile> . alignment )
33
33
defer {
34
- p2. deallocate ( bytes: sizeInBytes, alignedTo: alignof ( Missile . self ) )
34
+ p2. deallocate ( bytes: sizeInBytes, alignedTo: MemoryLayout < Missile> . alignment )
35
35
}
36
36
let ptrM2 = p2. moveInitializeMemory ( as: Missile . self, from: ptrM, count: 3 )
37
37
defer {
@@ -55,11 +55,11 @@ UnsafeMutableRawPointerExtraTestSuite.test("initializeMemory") {
55
55
}
56
56
57
57
UnsafeMutableRawPointerExtraTestSuite . test ( " bindMemory " ) {
58
- let sizeInBytes = 3 * strideof ( Int . self )
58
+ let sizeInBytes = 3 * MemoryLayout < Int> . stride
59
59
var p1 = UnsafeMutableRawPointer . allocate (
60
- bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
60
+ bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
61
61
defer {
62
- p1. deallocate ( bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
62
+ p1. deallocate ( bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
63
63
}
64
64
let ptrI = p1. bindMemory ( to: Int . self, capacity: 3 )
65
65
ptrI. initialize ( from: 1 ... 3 )
@@ -72,33 +72,33 @@ UnsafeMutableRawPointerExtraTestSuite.test("bindMemory") {
72
72
}
73
73
74
74
UnsafeMutableRawPointerExtraTestSuite . test ( " load/store " ) {
75
- let sizeInBytes = 3 * strideof ( Int . self )
75
+ let sizeInBytes = 3 * MemoryLayout < Int> . stride
76
76
var p1 = UnsafeMutableRawPointer . allocate (
77
- bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
77
+ bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
78
78
defer {
79
- p1. deallocate ( bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
79
+ p1. deallocate ( bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
80
80
}
81
81
let ptrI = p1. initializeMemory ( as: Int . self, from: 1 ... 3 )
82
82
defer {
83
83
ptrI. deinitialize ( count: 3 )
84
84
}
85
85
expectEqual ( 1 , p1. load ( as: Int . self) )
86
- expectEqual ( 2 , p1. load ( fromByteOffset: strideof ( Int . self ) , as: Int . self) )
87
- expectEqual ( 3 , p1. load ( fromByteOffset: 2 * strideof ( Int . self ) , as: Int . self) )
86
+ expectEqual ( 2 , p1. load ( fromByteOffset: MemoryLayout < Int> . stride , as: Int . self) )
87
+ expectEqual ( 3 , p1. load ( fromByteOffset: 2 * MemoryLayout < Int> . stride , as: Int . self) )
88
88
p1. storeBytes ( of: 4 , as: Int . self)
89
- p1. storeBytes ( of: 5 , toByteOffset: strideof ( Int . self ) , as: Int . self)
90
- p1. storeBytes ( of: 6 , toByteOffset: 2 * strideof ( Int . self ) , as: Int . self)
89
+ p1. storeBytes ( of: 5 , toByteOffset: MemoryLayout < Int> . stride , as: Int . self)
90
+ p1. storeBytes ( of: 6 , toByteOffset: 2 * MemoryLayout < Int> . stride , as: Int . self)
91
91
expectEqual ( 4 , p1. load ( as: Int . self) )
92
- expectEqual ( 5 , p1. load ( fromByteOffset: strideof ( Int . self ) , as: Int . self) )
93
- expectEqual ( 6 , p1. load ( fromByteOffset: 2 * strideof ( Int . self ) , as: Int . self) )
92
+ expectEqual ( 5 , p1. load ( fromByteOffset: MemoryLayout < Int> . stride , as: Int . self) )
93
+ expectEqual ( 6 , p1. load ( fromByteOffset: 2 * MemoryLayout < Int> . stride , as: Int . self) )
94
94
}
95
95
96
96
UnsafeMutableRawPointerExtraTestSuite . test ( " copyBytes " ) {
97
- let sizeInBytes = 4 * strideof ( Int . self )
97
+ let sizeInBytes = 4 * MemoryLayout < Int> . stride
98
98
var rawPtr = UnsafeMutableRawPointer . allocate (
99
- bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
99
+ bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
100
100
defer {
101
- rawPtr. deallocate ( bytes: sizeInBytes, alignedTo: alignof ( Int . self ) )
101
+ rawPtr. deallocate ( bytes: sizeInBytes, alignedTo: MemoryLayout < Int> . alignment )
102
102
}
103
103
let ptrI = rawPtr. initializeMemory ( as: Int . self, count: 4 , to: 42 )
104
104
defer {
@@ -108,32 +108,32 @@ UnsafeMutableRawPointerExtraTestSuite.test("copyBytes") {
108
108
// Right overlap
109
109
ptrI [ 0 ] = 1
110
110
ptrI [ 1 ] = 2
111
- ( rawPtr + strideof ( Int . self ) ) . copyBytes (
112
- from: roPtr, count: 2 * strideof ( Int . self ) )
111
+ ( rawPtr + MemoryLayout < Int > . stride ) . copyBytes (
112
+ from: roPtr, count: 2 * MemoryLayout < Int> . stride )
113
113
expectEqual ( 1 , ptrI [ 1 ] )
114
114
expectEqual ( 2 , ptrI [ 2 ] )
115
115
116
116
// Left overlap
117
117
ptrI [ 1 ] = 2
118
118
ptrI [ 2 ] = 3
119
119
rawPtr. copyBytes (
120
- from: roPtr + strideof ( Int . self ) , count: 2 * strideof ( Int . self ) )
120
+ from: roPtr + MemoryLayout < Int> . stride , count: 2 * MemoryLayout < Int> . stride )
121
121
expectEqual ( 2 , ptrI [ 0 ] )
122
122
expectEqual ( 3 , ptrI [ 1 ] )
123
123
124
124
// Disjoint:
125
125
ptrI [ 2 ] = 2
126
126
ptrI [ 3 ] = 3
127
127
rawPtr. copyBytes (
128
- from: roPtr + 2 * strideof ( Int . self ) , count: 2 * strideof ( Int . self ) )
128
+ from: roPtr + 2 * MemoryLayout < Int> . stride , count: 2 * MemoryLayout < Int> . stride )
129
129
expectEqual ( 2 , ptrI [ 0 ] )
130
130
expectEqual ( 3 , ptrI [ 1 ] )
131
131
132
132
// Backwards
133
133
ptrI [ 0 ] = 0
134
134
ptrI [ 1 ] = 1
135
- ( rawPtr + 2 * strideof ( Int . self ) ) . copyBytes (
136
- from: roPtr, count: 2 * strideof ( Int . self ) )
135
+ ( rawPtr + 2 * MemoryLayout < Int > . stride ) . copyBytes (
136
+ from: roPtr, count: 2 * MemoryLayout < Int> . stride )
137
137
expectEqual ( 0 , ptrI [ 2 ] )
138
138
expectEqual ( 1 , ptrI [ 3 ] )
139
139
}
0 commit comments