From 2a3db5c0175e26ba99adca90e5bab6cb4e85cc2d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 20 Oct 2016 22:22:25 -0400 Subject: [PATCH] cmd/cgo: document C.malloc behavior Fixes #16309. Change-Id: Ifcd28b0746e1af30e2519a7b118485aecfb12396 Reviewed-on: https://go-review.googlesource.com/31811 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/doc.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index e6f9173aaf..e5d288167e 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -216,6 +216,13 @@ by making copies of the data. In pseudo-Go definitions: // C data with explicit length to Go []byte func C.GoBytes(unsafe.Pointer, C.int) []byte +As a special case, C.malloc does not call the C library malloc directly +but instead calls a Go helper function that wraps the C library malloc +but guarantees never to return nil. If C's malloc indicates out of memory, +the helper function crashes the program, like when Go itself runs out +of memory. Because C.malloc cannot fail, it has no two-result form +that returns errno. + C references to Go Go functions can be exported for use by C code in the following way: