Panic when trying to use uninitialized or deleted Pigosat objects#6
Merged
wkschwartz merged 4 commits intomasterfrom Feb 13, 2015
Merged
Panic when trying to use uninitialized or deleted Pigosat objects#6wkschwartz merged 4 commits intomasterfrom
wkschwartz merged 4 commits intomasterfrom
Conversation
Similar to @justinfx/pigosata755660 but use simpler syntax in isReady function (boolean expressions return a boolean value) and call it isReady rather than isValid because there's already the NotReady status constant.
I can't think of a good way to test this. Open to suggestions.
Owner
Author
|
35d2c7f is wrong. The whole point of func (p *Pigosat) readyRead() (unlock func()) {
// No race here because the pointer p cannot magically change if it's nil.
if p == nil {
return nil
}
p.lock.RLock()
if p.p == nil {
p.lock.RUnlock()
return nil
}
return p.lock.RUnlock
}Then it's used like func (p *Pigosat) Print(file *os.File) error {
unlock := readyRead()
if unlock == nil {
return nil
}
defer unlock()
// ...
} |
(Except for extra calls to Delete, which is a no op). This is much simpler than returning errors for what is a pretty difficult programming error to make. The prior behavior of returning a variety of zero values just wasn't helpful for debugging.
Owner
Author
|
The real issue is that having default return values for when |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on justinfx/pigosat@a755660. Open to suggestions about how to test 35d2c7f.