Skip to content

[Foundation] Address exclusivity violation in Data #15823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2018
Merged
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
13 changes: 11 additions & 2 deletions stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1762,14 +1762,23 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
}

public struct Iterator : IteratorProtocol {
private let _data: Data
// Both _data and _endIdx should be 'let' rather than 'var'.
// They are 'var' so that the stored properties can be read
// independently of the other contents of the struct. This prevents
// an exclusivity violation when reading '_endIdx' and '_data'
// while simultaneously mutating '_buffer' with the call to
// withUnsafeMutablePointer(). Once we support accessing struct
// let properties independently we should make these variables
// 'let' again.

private var _data: Data
private var _buffer: (
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
private var _idx: Data.Index
private let _endIdx: Data.Index
private var _endIdx: Data.Index

fileprivate init(_ data: Data) {
_data = data
Expand Down