Skip to content

Fix warning: overlapping access to 'self' #1337

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 2 commits into from
Nov 29, 2017

Conversation

ianpartridge
Copy link
Contributor

Warning: Overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable

There are more of these in the codebase, but here's a fix for a few.

> Overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable
@@ -583,8 +583,9 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
var at: CFAbsoluteTime = date.timeIntervalSinceReferenceDate

let res: Bool = withUnsafeMutablePointer(to: &at) { t in
let copy = vector
return vector.withUnsafeMutableBufferPointer { (vectorBuffer: inout UnsafeMutableBufferPointer<Int32>) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would let count = Int32(vector.count) be better to reduce the size of the copy?

mutatingHello.withUnsafeMutableBytes { (bytes : UnsafeMutablePointer<UInt8>) in
XCTAssertEqual(bytes.pointee, 0x68, "First byte should be 0x68")

// Mutate it
bytes.pointee = 0x67
XCTAssertEqual(bytes.pointee, 0x67, "First byte should be 0x67")
XCTAssertEqual(mutatingHello[0], 0x67, "First byte accessed via other method should still be 0x67")
XCTAssertEqual(copy[0], 0x67, "First byte accessed via other method should still be 0x67")

Copy link
Contributor

@spevans spevans Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this copy making the test redundant?
Would moving the XCTAssertEqual(mutatingHello[0] ... outside of the closure give the same effect?

@ianpartridge
Copy link
Contributor Author

@swift-ci please test

@spevans
Copy link
Contributor

spevans commented Nov 27, 2017

Those fixes look good.

@ianpartridge
Copy link
Contributor Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit 03e2846 into swiftlang:master Nov 29, 2017
@ianpartridge ianpartridge deleted the exclusive-access branch November 29, 2017 21:15
devincoughlin added a commit to devincoughlin/swift-corelibs-foundation that referenced this pull request Apr 13, 2018
Fix an exclusivity warning in TestNSData by moving assertions outside
outside of a withUnsafeMutableByte() closure. This mirrors the approach
taken by swiftlang#1337
to avoid the analogous warning in a similar test in this file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants