mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: retain Go pointer passed to C call for duration of call
Fixes #6397. R=golang-dev, bradfitz, iant CC=golang-dev https://golang.org/cl/13858043
This commit is contained in:
parent
7616c94921
commit
5639d2754b
2 changed files with 25 additions and 6 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue