diff options
| author | kovan <xaum.io@gmail.com> | 2026-02-03 15:34:08 +0100 |
|---|---|---|
| committer | Sean Liao <sean@liao.dev> | 2026-03-11 16:45:41 -0700 |
| commit | 26d5e160750b34a537cce0f1bfd47f663a110d27 (patch) | |
| tree | a67de423adcb64ed9ec9a6d82aa1d28f560c0d70 /src/runtime | |
| parent | 6b7763407c83e9014c94997f1d454b175a6ea601 (diff) | |
| download | go-26d5e160750b34a537cce0f1bfd47f663a110d27.tar.xz | |
runtime/cgo: clarify pinning requirement in Handle example
Add a comment to the void* example in the Handle documentation
highlighting that if the C code keeps the pointer after the call
returns, runtime.Pinner should be used to pin it.
The existing documentation already mentions this requirement in prose
(lines 69-73), but adding a comment directly in the example makes it
more visible and less likely to be missed when copying the example.
Fixes #68044
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change-Id: I20a5b1ad10de1b441980dc7ed3185720e77912bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/741443
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/cgo/handle.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/runtime/cgo/handle.go b/src/runtime/cgo/handle.go index 7d6dd9146c..813f557bc2 100644 --- a/src/runtime/cgo/handle.go +++ b/src/runtime/cgo/handle.go @@ -97,6 +97,9 @@ import ( // func main() { // val := "hello Go" // h := cgo.NewHandle(val) +// // In this example, unsafe.Pointer(&h) is valid because myprint +// // does not keep a copy of the pointer. If the C code keeps the +// // pointer after the call returns, use runtime.Pinner to pin it. // C.myprint(unsafe.Pointer(&h)) // // Output: hello Go // } |
