mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: unify cgo output for gc and gccgo
When calling a Go function that returns multiple values from C, cgo generates a structure to hold the values. According to the documentation this structure is called `struct <function-name>_return`. When compiling for gccgo the generated structure name is `struct <function-name>_result`. This change updates the output for gccgo to match the documentation and output for gc. Fixes #20910 Change-Id: Iaea8030a695a7aaf9d9f317447fc05615d8e4adc Reviewed-on: https://go-review.googlesource.com/49350 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
b70adbf296
commit
ee714947c5
4 changed files with 42 additions and 3 deletions
|
|
@ -985,7 +985,7 @@ func (p *Package) writeGccgoExports(fgo2, fm, fgcc, fgcch io.Writer) {
|
|||
default:
|
||||
// Declare a result struct.
|
||||
fmt.Fprintf(fgcch, "\n/* Return type for %s */\n", exp.ExpName)
|
||||
fmt.Fprintf(fgcch, "struct %s_result {\n", exp.ExpName)
|
||||
fmt.Fprintf(fgcch, "struct %s_return {\n", exp.ExpName)
|
||||
forFieldList(fntype.Results,
|
||||
func(i int, aname string, atype ast.Expr) {
|
||||
t := p.cgoType(atype)
|
||||
|
|
@ -996,7 +996,7 @@ func (p *Package) writeGccgoExports(fgo2, fm, fgcc, fgcch io.Writer) {
|
|||
fmt.Fprint(fgcch, "\n")
|
||||
})
|
||||
fmt.Fprintf(fgcch, "};\n")
|
||||
fmt.Fprintf(cdeclBuf, "struct %s_result", exp.ExpName)
|
||||
fmt.Fprintf(cdeclBuf, "struct %s_return", exp.ExpName)
|
||||
}
|
||||
|
||||
cRet := cdeclBuf.String()
|
||||
|
|
@ -1022,7 +1022,7 @@ func (p *Package) writeGccgoExports(fgo2, fm, fgcc, fgcch io.Writer) {
|
|||
fmt.Fprintf(fgcch, "\n%s", exp.Doc)
|
||||
}
|
||||
|
||||
fmt.Fprintf(fgcch, "extern %s %s %s;\n", cRet, exp.ExpName, cParams)
|
||||
fmt.Fprintf(fgcch, "extern %s %s%s;\n", cRet, exp.ExpName, cParams)
|
||||
|
||||
// We need to use a name that will be exported by the
|
||||
// Go code; otherwise gccgo will make it static and we
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue