diff options
| author | Ian Lance Taylor <iant@golang.org> | 2025-02-05 17:22:43 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-02-06 05:37:51 -0800 |
| commit | a8e532b0f234b3bbf7a1cdcd4213d154e82ba08e (patch) | |
| tree | 7f775c1959a86df9e7e19ff7cea024405ec99d22 /src/runtime | |
| parent | 4cc7705e56be24d5719b59cb369ce4d40643983c (diff) | |
| download | go-a8e532b0f234b3bbf7a1cdcd4213d154e82ba08e.tar.xz | |
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 <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/cgo/handle.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/runtime/cgo/handle.go b/src/runtime/cgo/handle.go index 59b65da2b6..7d6dd9146c 100644 --- a/src/runtime/cgo/handle.go +++ b/src/runtime/cgo/handle.go @@ -61,10 +61,16 @@ import ( // } // // Some C functions accept a void* argument that points to an arbitrary -// data value supplied by the caller. It is not safe to coerce a [cgo.Handle] +// data value supplied by the caller. It is not safe to coerce a Handle // (an integer) to a Go [unsafe.Pointer], but instead we can pass the address // of the cgo.Handle to the void* parameter, as in this variant of the -// previous example: +// previous example. +// +// Note that, as described in the [cmd/cgo] documentation, +// the C code must not keep a copy of the Go pointer that it receives, +// unless the memory is explicitly pinned using [runtime.Pinner]. +// This example is OK because the C function myprint does not keep +// a copy of the pointer. // // package main // |
