Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed noCopy struct into structs, which mustn't be copied
This should help `go vet` detecting invalid structs' copyings. See golang/go#8005 (comment) for details.
- Loading branch information
Showing
8 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ type Args struct { | |
args []argsKV | ||
bufKV argsKV | ||
buf []byte | ||
|
||
noCopy | ||
} | ||
|
||
type argsKV struct { | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,8 @@ type Cookie struct { | |
|
||
bufKV argsKV | ||
buf []byte | ||
|
||
noCopy | ||
} | ||
|
||
// CopyTo copies src cookie to c. | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fasthttp | ||
|
||
// Embed this type into a struct, which mustn't be copied, | ||
// so `go vet` gives a warning if this struct is copied. | ||
// | ||
// See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. | ||
type noCopy struct {} | ||
func (*noCopy) Lock() {} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ type URI struct { | |
requestURI []byte | ||
|
||
h *RequestHeader | ||
|
||
noCopy | ||
} | ||
|
||
// CopyTo copies uri contents to dst. | ||
|
9fa69c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you place the empty struct at the end of another struct it can happen that you increase the size of it.
You should place it at the first position, AFAIK.
9fa69c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, @stemar94 !
The corresponding Go issue. Will move it at the first position.
9fa69c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at 8280b7a
9fa69c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not providing the issue in first place.