Skip to content
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

stickiness: avoid using unsafe #2023

Merged
merged 1 commit into from
Apr 25, 2018
Merged

stickiness: avoid using unsafe #2023

merged 1 commit into from
Apr 25, 2018

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Apr 24, 2018

App Engine doesn't allow use of unsafe

#2022

App Engine doesn't allow use of unsafe
@menghanl menghanl requested a review from dfawley April 24, 2018 23:48
}
return ""
// No need to check ok because mdKey == "" if ok == false.
mdKey, _ := bp.stickinessMDKey.Load().(string)
Copy link
Member

Choose a reason for hiding this comment

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

return bp.stickinessMDKey.Load().(string)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be nil. We need , _ otherwise it may panic.

oldKeyUnsafePtr := atomic.SwapPointer(&bp.stickinessMDKey, unsafe.Pointer(&newKey))
if ptr := (*string)(oldKeyUnsafePtr); ptr == nil || *ptr != newKey {
// No need to check ok because mdKey == "" if ok == false.
if oldKey, _ := bp.stickinessMDKey.Load().(string); oldKey != newKey {
Copy link
Member

Choose a reason for hiding this comment

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

drop the ", _"; it's cleaner.

@menghanl menghanl merged commit 7263089 into grpc:master Apr 25, 2018
@menghanl menghanl deleted the safe branch April 25, 2018 17:01
menghanl added a commit to menghanl/grpc-go that referenced this pull request Jun 25, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Oct 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants