]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: cgo: emit no error for calls to C.CBytes
authorAlan Donovan <adonovan@google.com>
Mon, 24 Oct 2016 15:00:19 +0000 (11:00 -0400)
committerAlan Donovan <adonovan@google.com>
Mon, 24 Oct 2016 19:05:50 +0000 (19:05 +0000)
Fixes issue golang/go#17563

Change-Id: Ibb41ea9419907193526cc601f6afd07d8689b1fe
Reviewed-on: https://go-review.googlesource.com/31810
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/vet/cgo.go
src/cmd/vet/testdata/cgo.go

index b896862c8f662872dd029940ae78cc1fc53e0581..d233e9a96020bebffc71518359473df0abc837db 100644 (file)
@@ -38,6 +38,11 @@ func checkCgoCall(f *File, node ast.Node) {
                return
        }
 
+       // A call to C.CBytes passes a pointer but is always safe.
+       if sel.Sel.Name == "CBytes" {
+               return
+       }
+
        for _, arg := range x.Args {
                if !typeOKForCgoCall(cgoBaseType(f, arg)) {
                        f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C")
index 5ce6007fcb4843de7365ae0290707a365be7a213..25d395b1ea89008cb38c62c11a1cae12285696d0 100644 (file)
@@ -51,4 +51,6 @@ func CgoTests() {
        var st2 struct{ i int }
        C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2)))
        C.f(unsafe.Pointer(&st2))
+
+       C.CBytes([]byte("hello"))
 }