On Wed, Dec 16, 2015 at 10:36 AM, Tim K <
tim....@gmail.com> wrote:
>
> I'm curious to look at the source for C.GoBytes() but not sure where to look
> or how it all works.
The source code is in cmd/cgo/out.go:
//go:linkname _cgo_runtime_gobytes runtime.gobytes
func _cgo_runtime_gobytes(unsafe.Pointer, int) []byte
func _Cfunc_GoBytes(p unsafe.Pointer, l _Ctype_int) []byte {
return _cgo_runtime_gobytes(p, int(l))
}
The call to _cgo_runtime_gobytes will call runtime.gobytes, which is
defined in runtime/string.go.
> Also, is there more documentation/godoc for the C.* helper functions beyond
> this page? For example it was not clear to me whether C.GoBytes() copies
> data or just creates a slice backed by the C bytes. It's probably clear
> though for someone with more C and Go experience than me :-)
The only docs are
https://golang.org/cmd/cgo. That page does say "by
making copies of the data."
Ian