From 53722b5b08344442a2e67b2bca3fd01776f96d3e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 12 Apr 2016 19:17:59 -0400 Subject: Started the safer malloc() system. --- util.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'util.go') diff --git a/util.go b/util.go index cfcb677..2f181c4 100644 --- a/util.go +++ b/util.go @@ -7,8 +7,22 @@ import ( ) // #include +// // TODO remove when switching to Go 1.7 +// #include import "C" +// TODO move this to C.CBytes() when switching to Go 1.7 + +//export uimalloc +func uimalloc(n C.size_t) unsafe.Pointer { + p := C.malloc(n) + if p == nil { + panic("out of memory in uimalloc()") + } + C.memset(p, 0, n) + return p +} + func freestr(str *C.char) { C.free(unsafe.Pointer(str)) } -- cgit v1.2.3