]> Cypherpunks repositories - gostls13.git/commitdiff
Correct _cgo_free when C ABI does not pass first arg on stack.
authorIan Lance Taylor <iant@golang.org>
Mon, 31 May 2010 05:22:47 +0000 (22:22 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 31 May 2010 05:22:47 +0000 (22:22 -0700)
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
https://golang.org/cl/1399041

src/cmd/cgo/out.go
src/libcgo/util.c

index 2fae48fe47b52dac0bb7e80101b7efa78c32eeba..e58923ab2a1968f716647b9f2cc991f711f0de2f 100644 (file)
@@ -568,7 +568,7 @@ const cProlog = `
 #pragma dynimport libcgo_thread_start libcgo_thread_start "%s/libcgo.so"
 #pragma dynimport libcgo_set_scheduler libcgo_set_scheduler "%s/libcgo.so"
 #pragma dynimport _cgo_malloc _cgo_malloc "%s/libcgo.so"
-#pragma dynimport _cgo_free free "%s/libcgo.so"
+#pragma dynimport _cgo_free _cgo_free "%s/libcgo.so"
 
 void
 ·_C_GoString(int8 *p, String s)
index a814e018b3b9386fbe8af664f7427d5cad3041a7..c296b493da66283571d73a74a460b67459c080c8 100644 (file)
@@ -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)