Skip to content

Commit a8e532b

Browse files
ianlancetaylorgopherbot
authored andcommitted
runtime/cgo: clarify that C code must not retain pointer
For #71566 Change-Id: I6dc365dd799d7b506b4a55895f1736d3dfd4684b Reviewed-on: https://go-review.googlesource.com/c/go/+/647095 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]>
1 parent 4cc7705 commit a8e532b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/runtime/cgo/handle.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ import (
6161
// }
6262
//
6363
// Some C functions accept a void* argument that points to an arbitrary
64-
// data value supplied by the caller. It is not safe to coerce a [cgo.Handle]
64+
// data value supplied by the caller. It is not safe to coerce a Handle
6565
// (an integer) to a Go [unsafe.Pointer], but instead we can pass the address
6666
// of the cgo.Handle to the void* parameter, as in this variant of the
67-
// previous example:
67+
// previous example.
68+
//
69+
// Note that, as described in the [cmd/cgo] documentation,
70+
// the C code must not keep a copy of the Go pointer that it receives,
71+
// unless the memory is explicitly pinned using [runtime.Pinner].
72+
// This example is OK because the C function myprint does not keep
73+
// a copy of the pointer.
6874
//
6975
// package main
7076
//

0 commit comments

Comments
 (0)