Skip to content

Commit 42fcc50

Browse files
committed
address comments.
Signed-off-by: doujiang24 <doujiang24@gmail.com>
1 parent 766ea1b commit 42fcc50

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/cmd/cgo/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ For example:
436436
// #cgo noescape cFunctionName
437437
438438
When a Go function calls a C function, it prepares for the C function to
439-
call back to a Go function. the #cgo nocallback directive may be used to
439+
call back to a Go function. The #cgo nocallback directive may be used to
440440
tell the compiler that these preparations are not necessary.
441441
If the nocallback directive is used and the C function does call back into
442442
Go code, the program will panic.

src/cmd/cgo/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ func (p *Package) writeDefsFunc(fgo2 io.Writer, n *Name, callsMalloc *bool) {
644644
fmt.Fprintf(fgo2, "\t_Cgo_no_callback(false)\n")
645645
}
646646

647-
// use _Cgo_keepalive instead of _Cgo_use when noescape & nocallback exist,
647+
// Use _Cgo_keepalive instead of _Cgo_use when noescape & nocallback exist,
648648
// so that the compiler won't force to escape them to heap.
649-
// instead, make the compiler keep them alive by using _Cgo_keepalive.
649+
// Instead, make the compiler keep them alive by using _Cgo_keepalive.
650650
touchFunc := "_Cgo_use"
651651
if p.noEscapes[n.C] && p.noCallbacks[n.C] {
652652
touchFunc = "_Cgo_keepalive"

src/runtime/cgo.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ var cgoHasExtraM bool
7373
func cgoUse(any) { throw("cgoUse should not be called") }
7474

7575
// cgoKeepAlive is called by cgo-generated code (using go:linkname to get at
76-
// an unexported name). Unlike cgoUse The calls serve one purposes:
77-
// 1) they keep the argument alive until the call site; the call is emitted after
78-
// the end of the (presumed) use of the argument by C.
79-
// cgoKeepAlive should not actually be called (see cgoAlwaysFalse).
76+
// an unexported name). This call keeps its argument alive until the call site;
77+
// cgo emits the call after the last possible use of the argument by C code.
78+
// cgoKeepAlive is marked in the cgo-generated code as //go:noescape, so
79+
// unlike cgoUse it does not force the argument to escape to the heap.
80+
// This is used to implement the #cgo noescape directive.
8081
func cgoKeepAlive(any) { throw("cgoKeepAlive should not be called") }
8182

8283
// cgoAlwaysFalse is a boolean value that is always false.

src/runtime/testdata/testprogcgo/issue63739.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
package main
66

7-
// This is for issue #56378.
8-
// After we retiring _Cgo_use for parameters, the compiler will treat the
9-
// parameters, start from the second, as non-alive. Then, they will be marked
10-
// as scalar in stackmap, which means the pointer won't be copied correctly
11-
// in copystack.
7+
// This is for issue #63739.
8+
// Ensure that parameters are kept alive until the end of the C call. If not,
9+
// then a stack copy at just the right time while calling into C might think
10+
// that any stack pointers are not alive and fail to update them, causing the C
11+
// function to see the old, no longer correct, pointer values.
1212

1313
/*
1414
int add_from_multiple_pointers(int *a, int *b, int *c) {

0 commit comments

Comments
 (0)