Skip to content

Commit a38fe37

Browse files
authored
Merge pull request #15823 from devincoughlin/data-exclusivity-warning
2 parents 28fb34d + 302d827 commit a38fe37

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,14 +1762,23 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
17621762
}
17631763

17641764
public struct Iterator : IteratorProtocol {
1765-
private let _data: Data
1765+
// Both _data and _endIdx should be 'let' rather than 'var'.
1766+
// They are 'var' so that the stored properties can be read
1767+
// independently of the other contents of the struct. This prevents
1768+
// an exclusivity violation when reading '_endIdx' and '_data'
1769+
// while simultaneously mutating '_buffer' with the call to
1770+
// withUnsafeMutablePointer(). Once we support accessing struct
1771+
// let properties independently we should make these variables
1772+
// 'let' again.
1773+
1774+
private var _data: Data
17661775
private var _buffer: (
17671776
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
17681777
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
17691778
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
17701779
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
17711780
private var _idx: Data.Index
1772-
private let _endIdx: Data.Index
1781+
private var _endIdx: Data.Index
17731782

17741783
fileprivate init(_ data: Data) {
17751784
_data = data

0 commit comments

Comments
 (0)