From da07dca4523ebd25c634152a62cae4a72eb5783f Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Tue, 21 Jun 2016 17:14:53 +0300 Subject: Wrap more objects with CGo --- cshared/objects.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'cshared/objects.go') diff --git a/cshared/objects.go b/cshared/objects.go index 0517449..ae3440d 100644 --- a/cshared/objects.go +++ b/cshared/objects.go @@ -140,6 +140,13 @@ func CopyString(str string) string { return string(buf) } +// https://github.com/golang/go/issues/14838 +func CBytes(bytes []byte) *C.char { + ptr := C.malloc(C.size_t(len(bytes))) + copy((*[1<<30]byte)(ptr)[:], bytes) + return (*C.char)(ptr) +} + func SafeIsNil(v reflect.Value) bool { defer func() { recover() }() return v.IsNil() -- cgit