Started the safer malloc() system.
This commit is contained in:
parent
439f3f476c
commit
53722b5b08
5
draw.go
5
draw.go
|
@ -4,12 +4,13 @@ package ui
|
|||
|
||||
// #include <stdlib.h>
|
||||
// #include "ui.h"
|
||||
// // TODO figure this one out
|
||||
// extern void *uimalloc(size_t);
|
||||
// static uiDrawBrush *newBrush(void)
|
||||
// {
|
||||
// uiDrawBrush *b;
|
||||
//
|
||||
// b = (uiDrawBrush *) malloc(sizeof (uiDrawBrush));
|
||||
// // TODO
|
||||
// b = (uiDrawBrush *) uimalloc(sizeof (uiDrawBrush));
|
||||
// return b;
|
||||
// }
|
||||
// static uiDrawBrushGradientStop *newStops(size_t n)
|
||||
|
|
14
util.go
14
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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue