summaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-26 10:19:10 -0400
committerPietro Gagliardi <[email protected]>2018-08-26 10:19:10 -0400
commit766f9ed028c757561b99e4ed5aa487d381fe80a3 (patch)
treebdbeb748f2a88a47f6b246ffa1a72cd6c0da4689 /util.go
parent62ac2527732a01dfa6bd2c9523215c0ba3816641 (diff)
Migrated util.go and main.go to the new pkgui convention and C file. Also replaced C.CBytes() with C.malloc() (this bumps our minimum version requirement to 1.8, but it's better than keeping a massive slice around at all times).
Diffstat (limited to 'util.go')
-rw-r--r--util.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/util.go b/util.go
new file mode 100644
index 0000000..667f679
--- /dev/null
+++ b/util.go
@@ -0,0 +1,31 @@
+// 12 december 2015
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "pkgui.h"
+import "C"
+
+//export pkguiAlloc
+func pkguiAlloc(n C.size_t) unsafe.Pointer {
+ // cgo turns C.malloc() into a panic-on-OOM version; use it
+ return C.malloc(n)
+}
+
+func freestr(str *C.char) {
+ C.free(unsafe.Pointer(str))
+}
+
+func tobool(b C.int) bool {
+ return b != 0
+}
+
+func frombool(b bool) C.int {
+ if b {
+ return 1
+ }
+ return 0
+}