Skip to content

Commit

Permalink
cmd/cgo: updated exported function parameter nams
Browse files Browse the repository at this point in the history
functions exported through cgo will now require that parameter names use
only ASCII characters. this way, the declarations in the exported header
file will retain the proper names for parameters

Fixes: #37746
  • Loading branch information
nathan-fiscaletti committed Mar 9, 2020
1 parent b5c66de commit b7da1b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"regexp"
"sort"
"strings"
"unicode"
)

var (
Expand Down Expand Up @@ -915,7 +916,12 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
if i > 0 || fn.Recv != nil {
s += ", "
}
s += fmt.Sprintf("%s p%d", p.cgoType(atype).C, i)
for j := 0; j < len(aname); j++ {
if aname[j] > unicode.MaxASCII {
fatalf("error: invalid non ASCII character found in cgo exported function parameter: %s", aname)
}
}
s += fmt.Sprintf("%s %s", p.cgoType(atype).C, aname)
})
s += ")"

Expand All @@ -941,7 +947,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
}
forFieldList(fntype.Params,
func(i int, aname string, atype ast.Expr) {
fmt.Fprintf(fgcc, "\ta.p%d = p%d;\n", i, i)
fmt.Fprintf(fgcc, "\ta.p%d = %s;\n", i, aname)
})
fmt.Fprintf(fgcc, "\t_cgo_tsan_release();\n")
fmt.Fprintf(fgcc, "\tcrosscall2(_cgoexp%s_%s, &a, %d, _cgo_ctxt);\n", cPrefix, exp.ExpName, off)
Expand Down

0 comments on commit b7da1b5

Please sign in to comment.