aboutsummaryrefslogtreecommitdiffstats
path: root/cshared/objects.go
diff options
context:
space:
mode:
Diffstat (limited to 'cshared/objects.go')
-rw-r--r--cshared/objects.go7
1 files changed, 7 insertions, 0 deletions
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()