mirror of
https://github.com/golang/go.git
synced 2026-04-04 02:10:08 +09:00
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>
This commit is contained in:
@@ -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
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user