aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/reflect
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2016-11-18 00:15:38 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-11-18 00:15:38 +0000
commit5302cd025063e00bde7d102284f638977dde5f27 (patch)
tree67be8f93c3e7e9a2a592f5932622a54083146948 /libgo/go/reflect
parentf97db488a6ad72106426990653fa397d690d1654 (diff)
downloadgcc-5302cd025063e00bde7d102284f638977dde5f27.zip
gcc-5302cd025063e00bde7d102284f638977dde5f27.tar.gz
gcc-5302cd025063e00bde7d102284f638977dde5f27.tar.bz2
runtime, reflect: rewrite Go to FFI type conversion in Go
As we move toward the Go 1.7 garbage collector, it's essential that all allocation of values that can contain Go pointers be done using the correct type descriptor. That is simplest if we do all such allocation in Go code. This rewrites the code that converts from a Go type to a libffi CIF into Go. Reviewed-on: https://go-review.googlesource.com/33353 From-SVN: r242578
Diffstat (limited to 'libgo/go/reflect')
-rw-r--r--libgo/go/reflect/makefunc.go6
-rw-r--r--libgo/go/reflect/makefunc_ffi.go5
-rw-r--r--libgo/go/reflect/makefunc_ffi_c.c15
3 files changed, 12 insertions, 14 deletions
diff --git a/libgo/go/reflect/makefunc.go b/libgo/go/reflect/makefunc.go
index 543a335..3a9fd28 100644
--- a/libgo/go/reflect/makefunc.go
+++ b/libgo/go/reflect/makefunc.go
@@ -63,7 +63,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
method: -1,
}
- makeFuncFFI(ftyp, unsafe.Pointer(impl))
+ makeFuncFFI(makeCIF(ftyp), unsafe.Pointer(impl))
return Value{t, unsafe.Pointer(&impl), flag(Func) | flagIndir}
}
@@ -102,7 +102,7 @@ func makeMethodValue(op string, v Value) Value {
rcvr: rcvr,
}
- makeFuncFFI(ftyp, unsafe.Pointer(fv))
+ makeFuncFFI(makeCIF(ftyp), unsafe.Pointer(fv))
return Value{ft, unsafe.Pointer(&fv), v.flag&flagRO | flag(Func) | flagIndir}
}
@@ -128,7 +128,7 @@ func makeValueMethod(v Value) Value {
rcvr: v,
}
- makeFuncFFI(ftyp, unsafe.Pointer(impl))
+ makeFuncFFI(makeCIF(ftyp), unsafe.Pointer(impl))
return Value{t, unsafe.Pointer(&impl), v.flag&flagRO | flag(Func) | flagIndir}
}
diff --git a/libgo/go/reflect/makefunc_ffi.go b/libgo/go/reflect/makefunc_ffi.go
index c821131..2acf7bb 100644
--- a/libgo/go/reflect/makefunc_ffi.go
+++ b/libgo/go/reflect/makefunc_ffi.go
@@ -10,7 +10,10 @@ import (
// The makeFuncFFI function, written in C, fills in an FFI closure.
// It arranges for ffiCall to be invoked directly from FFI.
-func makeFuncFFI(ftyp *funcType, impl unsafe.Pointer)
+func makeFuncFFI(cif unsafe.Pointer, impl unsafe.Pointer)
+
+// The makeCIF function, implemented in the runtime package, allocates a CIF.
+func makeCIF(ft *funcType) unsafe.Pointer
// FFICallbackGo implements the Go side of the libffi callback.
// It is exported so that C code can call it.
diff --git a/libgo/go/reflect/makefunc_ffi_c.c b/libgo/go/reflect/makefunc_ffi_c.c
index 06a41ef..d3935eb 100644
--- a/libgo/go/reflect/makefunc_ffi_c.c
+++ b/libgo/go/reflect/makefunc_ffi_c.c
@@ -8,7 +8,7 @@
#ifdef USE_LIBFFI
-#include "go-ffi.h"
+#include "ffi.h"
#if FFI_GO_CLOSURES
#define USE_LIBFFI_CLOSURES
@@ -18,7 +18,7 @@
/* Declare C functions with the names used to call from Go. */
-void makeFuncFFI(const struct __go_func_type *ftyp, void *impl)
+void makeFuncFFI(void *cif, void *impl)
__asm__ (GOSYM_PREFIX "reflect.makeFuncFFI");
#ifdef USE_LIBFFI_CLOSURES
@@ -70,20 +70,15 @@ ffi_callback (ffi_cif* cif __attribute__ ((unused)), void *results,
/* Allocate an FFI closure and arrange to call ffi_callback. */
void
-makeFuncFFI(const struct __go_func_type *ftyp, void *impl)
+makeFuncFFI(void *cif, void *impl)
{
- ffi_cif *cif;
-
- cif = (ffi_cif *) __go_alloc (sizeof (ffi_cif));
- __go_func_to_cif (ftyp, 0, 0, cif);
-
- ffi_prep_go_closure(impl, cif, ffi_callback);
+ ffi_prep_go_closure(impl, (ffi_cif*)cif, ffi_callback);
}
#else /* !defined(USE_LIBFFI_CLOSURES) */
void
-makeFuncFFI(const struct __go_func_type *ftyp __attribute__ ((unused)),
+makeFuncFFI(void *cif __attribute__ ((unused)),
void *impl __attribute__ ((unused)))
{
runtime_panicstring ("libgo built without FFI does not support "