diff options
author | Russ Cox <rsc@golang.org> | 2013-09-24 15:52:48 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2013-09-24 15:52:48 -0400 |
commit | 75cfd88bf2d2181102c4652ef173fa2acc6a8fc8 (patch) | |
tree | 39e324d85fd1219599217744e60d05a539d520ac /src/cmd/cgo | |
parent | 751e7cd5c7ecda6b06b20f44a4a386e8a18d0918 (diff) | |
download | go-75cfd88bf2d2181102c4652ef173fa2acc6a8fc8.tar.gz |
cmd/cgo: retain Go pointer passed to C call for duration of call
Fixes issue 6397.
R=golang-dev, bradfitz, iant
CC=golang-dev
https://codereview.appspot.com/13858043
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/out.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 9cf8dc55b..d41dc1565 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -413,7 +413,17 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name) { if argSize == 0 { argSize++ } - fmt.Fprintf(fc, "·%s(struct{uint8 x[%d];}p)\n", n.Mangle, argSize) + // TODO(rsc): The struct here should declare pointers only where + // there are pointers in the actual argument frame. + // This is a workaround for golang.org/issue/6397. + fmt.Fprintf(fc, "·%s(struct{", n.Mangle) + if n := argSize / p.PtrSize; n > 0 { + fmt.Fprintf(fc, "void *y[%d];", n) + } + if n := argSize % p.PtrSize; n > 0 { + fmt.Fprintf(fc, "uint8 x[%d];", n) + } + fmt.Fprintf(fc, "}p)\n") fmt.Fprintf(fc, "{\n") fmt.Fprintf(fc, "\truntime·cgocall(_cgo%s%s, &p);\n", cPrefix, n.Mangle) if n.AddError { |