summaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2016-04-12 19:17:59 -0400
committerPietro Gagliardi <[email protected]>2016-04-12 19:17:59 -0400
commit53722b5b08344442a2e67b2bca3fd01776f96d3e (patch)
tree75e350889b35baa751b8b51b914b3c52711c8008 /util.go
parent439f3f476c2b8fa2bd51bbb6257c3bf7c1208254 (diff)
Started the safer malloc() system.
Diffstat (limited to 'util.go')
-rw-r--r--util.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/util.go b/util.go
index cfcb677..2f181c4 100644
--- a/util.go
+++ b/util.go
@@ -7,8 +7,22 @@ import (
)
// #include <stdlib.h>
+// // TODO remove when switching to Go 1.7
+// #include <string.h>
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))
}