summaryrefslogtreecommitdiff
path: root/src/libcgo/util.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2010-05-30 22:22:47 -0700
committerIan Lance Taylor <iant@golang.org>2010-05-30 22:22:47 -0700
commitb51989bcee8aa7e0742bbcf15a2940aa04f9f244 (patch)
treed9898f7570425a4ddf009de3ae2def4a60cf14db /src/libcgo/util.c
parentbfa103a2fe1fe2872e6539527d1108a501c2f1af (diff)
downloadgolang-b51989bcee8aa7e0742bbcf15a2940aa04f9f244.tar.gz
Correct _cgo_free when C ABI does not pass first arg on stack.
It turns out that _cgo_malloc is used, via cmalloc in runtime/cgocall.c, which is called by code generated by out.go for the ยท_C_CString function. I can't find a call to _cgo_free, but given _cgo_malloc we might as well keep _cgo_free. This patch fixes it so that it should work on amd64. R=rsc CC=golang-dev http://codereview.appspot.com/1399041
Diffstat (limited to 'src/libcgo/util.c')
-rw-r--r--src/libcgo/util.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libcgo/util.c b/src/libcgo/util.c
index a814e018b..c296b493d 100644
--- a/src/libcgo/util.c
+++ b/src/libcgo/util.c
@@ -4,7 +4,7 @@
#include "libcgo.h"
-/* Stub for calling malloc from the other world */
+/* Stub for calling malloc from Go */
void
_cgo_malloc(void *p)
{
@@ -16,6 +16,17 @@ _cgo_malloc(void *p)
a->ret = malloc(a->n);
}
+/* Stub for calling from Go */
+void
+_cgo_free(void *p)
+{
+ struct a {
+ void *arg;
+ } *a = p;
+
+ free(a->arg);
+}
+
/* Stub for creating a new thread */
void
libcgo_thread_start(ThreadStart *arg)