aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/reflect/makefunc_ffi.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/reflect/makefunc_ffi.go')
-rw-r--r--libgo/go/reflect/makefunc_ffi.go39
1 files changed, 32 insertions, 7 deletions
diff --git a/libgo/go/reflect/makefunc_ffi.go b/libgo/go/reflect/makefunc_ffi.go
index 88ffca5..05c5bc0 100644
--- a/libgo/go/reflect/makefunc_ffi.go
+++ b/libgo/go/reflect/makefunc_ffi.go
@@ -28,7 +28,7 @@ func makeCIF(ft *funcType) unsafe.Pointer
//
// The ffi_callback handles __go_makefunc_can_recover, and
// then passes off the data as received from ffi here.
-func ffiCallbackGo(results unsafe.Pointer, params unsafe.Pointer, impl *makeFuncImpl) {
+func ffiCallbackGo(results unsafe.Pointer, params unsafe.Pointer, impl *makeFuncImpl, wordsize int32, bigEndian bool) {
ftyp := impl.typ
in := make([]Value, 0, len(ftyp.in))
ap := params
@@ -42,21 +42,46 @@ func ffiCallbackGo(results unsafe.Pointer, params unsafe.Pointer, impl *makeFunc
out := impl.call(in)
- off := uintptr(0)
- for i, typ := range ftyp.out {
- v := out[i]
+ checkValue := func(v Value, typ *rtype, addr unsafe.Pointer) {
if v.flag&flagRO != 0 {
panic("reflect: function created by MakeFunc using " + funcName(impl.fn) +
" returned value obtained from unexported field")
}
- off = align(off, uintptr(typ.fieldAlign))
- addr := unsafe.Pointer(uintptr(results) + off)
-
// Convert v to type typ if v is assignable to a variable
// of type t in the language spec.
// See issue 28761.
v = v.assignTo("reflect.MakeFunc", typ, addr)
+ }
+
+ // In libffi a single integer return value is always promoted
+ // to a full word. This only matters for integers whose size
+ // is less than the size of a full word. There is similar code
+ // in libgo/runtime/go-reflect-call.c.
+ if len(ftyp.out) == 1 {
+ typ := ftyp.out[0]
+ switch typ.Kind() {
+ case Bool, Int8, Int16, Int32, Uint8, Uint16, Uint32:
+ v := out[0]
+ checkValue(v, typ, nil)
+
+ if bigEndian {
+ results = unsafe.Pointer(uintptr(results) + uintptr(wordsize) - typ.size)
+ }
+
+ memmove(results, v.ptr, typ.size)
+ return
+ }
+ }
+
+ off := uintptr(0)
+ for i, typ := range ftyp.out {
+ v := out[i]
+
+ off = align(off, uintptr(typ.fieldAlign))
+ addr := unsafe.Pointer(uintptr(results) + off)
+
+ checkValue(v, typ, addr)
if v.flag&flagIndir == 0 && (v.kind() == Ptr || v.kind() == UnsafePointer) {
*(*unsafe.Pointer)(addr) = v.ptr