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

Fixed Exclusive Access to Memory bug #1489

Merged
merged 4 commits into from Feb 11, 2018

Conversation

Projects
None yet
5 participants
@SandorDobi
Copy link
Contributor

SandorDobi commented Feb 9, 2018

The last swift snapshot (2018-02-08) start to enforce the Exclusive Access to Memory (SE-0176) this cause to fail to build vapor Validation sources.
This PR is fixing that.

left.codingPath = codingPath + left.codingPath
right.codingPath = codingPath + right.codingPath
if var left = self.left, var right = self.right {
left.codingPath = codingPath + self.left!.codingPath

This comment has been minimized.

@tanner0101

tanner0101 Feb 10, 2018

Member

we need to avoid !

This comment has been minimized.

@SandorDobi

SandorDobi Feb 10, 2018

Author Contributor

Yep but that is already safe because of conditional binding, if it is nil then the whole block is skipped....

This comment has been minimized.

@siemensikkema

siemensikkema Feb 10, 2018

Member

@SandorDobi you're totally right that it is safe in this case but we like to avoid it out of principle. @MartinLasek will provide an alternative in 1, 2, 3 .. ;)

This comment has been minimized.

@MartinLasek

MartinLasek Feb 10, 2018

Contributor

One way to solve it without having to force unwrap could be:

var reason: String {
    if let left = left, let right = right {
        var mutableLeft = left, mutableRight = right
        mutableLeft.codingPath = codingPath + left.codingPath
        mutableRight.codingPath = codingPath + right.codingPath
        return "\(mutableLeft.reason) and \(mutableRight.reason)"
    } else if let left = left {
        var mutableLeft = left
        mutableLeft.codingPath = codingPath + left.codingPath
        return mutableLeft.reason
    } else if let right = right {
        var mutableRight = right
        mutableRight.codingPath = codingPath + right.codingPath
        return mutableRight.reason
    } else {
        return ""
    }
}

This comment has been minimized.

@SandorDobi

SandorDobi Feb 10, 2018

Author Contributor

Yep. Sure. I have a rule to avoid temporary variables where it is don't needed.

but understand if You have a strict "no !" policy.
So I'll change PR.

return errors.map { error in
var error = error
error.codingPath = codingPath + error.codingPath
return errors.map { err in

This comment has been minimized.

@MartinLasek

MartinLasek Feb 10, 2018

Contributor

Maybe we can go a consistent way here with a prefix mutable and do it in all the places as well without the bang. Like for this:

var reason: String {
    return errors.map { error in
        var mutableError = error
        mutableError.codingPath = codingPath + error.codingPath
        return mutableError.reason
    }.joined(separator: ", ")
}
left.codingPath = codingPath + left.codingPath
right.codingPath = codingPath + right.codingPath
if var left = self.left, var right = self.right {
left.codingPath = codingPath + self.left!.codingPath

This comment has been minimized.

@MartinLasek

MartinLasek Feb 10, 2018

Contributor

One way to solve it without having to force unwrap could be:

var reason: String {
    if let left = left, let right = right {
        var mutableLeft = left, mutableRight = right
        mutableLeft.codingPath = codingPath + left.codingPath
        mutableRight.codingPath = codingPath + right.codingPath
        return "\(mutableLeft.reason) and \(mutableRight.reason)"
    } else if let left = left {
        var mutableLeft = left
        mutableLeft.codingPath = codingPath + left.codingPath
        return mutableLeft.reason
    } else if let right = right {
        var mutableRight = right
        mutableRight.codingPath = codingPath + right.codingPath
        return mutableRight.reason
    } else {
        return ""
    }
}
@@ -49,9 +49,9 @@ internal struct OrValidatorError: ValidationError {
/// See ValidationError.reason
var reason: String {
var left = self.left
left.codingPath = codingPath + left.codingPath
left.codingPath = codingPath + self.left.codingPath

This comment has been minimized.

@MartinLasek

MartinLasek Feb 10, 2018

Contributor

That approach feels nice 👍

var mutableError = error
mutableError.codingPath = codingPath + error.codingPath
return mutableError.reason
}.joined(separator: ", ")

This comment has been minimized.

@MartinLasek

MartinLasek Feb 10, 2018

Contributor

Attention indentation. 😊

This comment has been minimized.

@SandorDobi

SandorDobi Feb 10, 2018

Author Contributor

Done. Crappy Xcode allways do me some quirks

SandorDobi added some commits Feb 10, 2018

fixing overlapping memory access error and avoiding force unwrapping …
…conditionals as requested and identitation :D

@Joannis Joannis merged commit 9ed8b7c into vapor:beta Feb 11, 2018

1 check passed

ci/circleci: linux Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment