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
|
|
@ -80,5 +80,6 @@ func Test20369(t *testing.T) { test20369(t) }
|
|||
func Test18720(t *testing.T) { test18720(t) }
|
||||
func Test20266(t *testing.T) { test20266(t) }
|
||||
func Test20129(t *testing.T) { test20129(t) }
|
||||
func Test20910(t *testing.T) { test20910(t) }
|
||||
|
||||
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
||||
|
|
|
|||
19
misc/cgo/test/issue20910.c
Normal file
19
misc/cgo/test/issue20910.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "_cgo_export.h"
|
||||
|
||||
/* Test calling a Go function with multiple return values. */
|
||||
|
||||
void
|
||||
callMulti(void)
|
||||
{
|
||||
struct multi_return result = multi();
|
||||
assert(strcmp(result.r0, "multi") == 0);
|
||||
assert(result.r1 == 0);
|
||||
free(result.r0);
|
||||
}
|
||||
19
misc/cgo/test/issue20910.go
Normal file
19
misc/cgo/test/issue20910.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cgotest
|
||||
|
||||
//void callMulti(void);
|
||||
import "C"
|
||||
|
||||
import "testing"
|
||||
|
||||
//export multi
|
||||
func multi() (*C.char, C.int) {
|
||||
return C.CString("multi"), 0
|
||||
}
|
||||
|
||||
func test20910(t *testing.T) {
|
||||
C.callMulti()
|
||||
}
|
||||
|
|
@ -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