github.com/aloncn/graphics-go@v0.0.1/src/runtime/cgo/gcc_util.c (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build cgo 6 7 #include "libcgo.h" 8 9 /* Stub for calling malloc from Go */ 10 void 11 x_cgo_malloc(void *p) 12 { 13 struct a { 14 long long n; 15 void *ret; 16 } *a = p; 17 18 a->ret = malloc(a->n); 19 if(a->ret == NULL && a->n == 0) 20 a->ret = malloc(1); 21 } 22 23 /* Stub for calling free from Go */ 24 void 25 x_cgo_free(void *p) 26 { 27 struct a { 28 void *arg; 29 } *a = p; 30 31 free(a->arg); 32 } 33 34 /* Stub for creating a new thread */ 35 void 36 x_cgo_thread_start(ThreadStart *arg) 37 { 38 ThreadStart *ts; 39 40 /* Make our own copy that can persist after we return. */ 41 ts = malloc(sizeof *ts); 42 if(ts == nil) { 43 fprintf(stderr, "runtime/cgo: out of memory in thread_start\n"); 44 abort(); 45 } 46 *ts = *arg; 47 48 _cgo_sys_thread_start(ts); /* OS-dependent half */ 49 }