cmd/cgo: make C function pointers non-assignable

Fixes #7757.
Fixes #8488.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/118690044
This commit is contained in:
Matthew Dempsky 2014-08-12 12:55:12 -07:00 committed by Ian Lance Taylor
parent e4d4787581
commit 11016f62d8
4 changed files with 23 additions and 2 deletions

View file

@ -650,7 +650,13 @@ func (p *Package) rewriteRef(f *File) {
f.Name[fpName] = name
}
r.Name = name
expr = ast.NewIdent(name.Mangle)
// Rewrite into call to _Cgo_ptr to prevent assignments. The _Cgo_ptr
// function is defined in out.go and simply returns its argument. See
// issue 7757.
expr = &ast.CallExpr{
Fun: &ast.Ident{NamePos: (*r.Expr).Pos(), Name: "_Cgo_ptr"},
Args: []ast.Expr{ast.NewIdent(name.Mangle)},
}
} else if r.Name.Kind == "type" {
// Okay - might be new(T)
expr = r.Name.Type.Go