]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: clarify that C code must not retain pointer
authorIan Lance Taylor <iant@golang.org>
Thu, 6 Feb 2025 01:22:43 +0000 (17:22 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 6 Feb 2025 13:37:51 +0000 (05:37 -0800)
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>

src/runtime/cgo/handle.go

index 59b65da2b6d763aeb8d153ed4ebd7384964f37db..7d6dd9146c30d3764c05f2ecd5b327558c398312 100644 (file)
@@ -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
 //