This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
libgo patch committed: Fix calling Interface on MakeFunc value
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Fri, 04 Oct 2013 11:52:45 -0700
- Subject: libgo patch committed: Fix calling Interface on MakeFunc value
- Authentication-results: sourceware.org; auth=none
This patch to libgo fixes calling the Interface method on a Value
created by calling MakeFunc. Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch.
Ian
diff -r 52c01e7b81fe libgo/go/reflect/all_test.go
--- a/libgo/go/reflect/all_test.go Fri Oct 04 11:00:40 2013 -0700
+++ b/libgo/go/reflect/all_test.go Fri Oct 04 11:49:27 2013 -0700
@@ -1454,6 +1454,30 @@
}
}
+func TestMakeFuncInterface(t *testing.T) {
+ switch runtime.GOARCH {
+ case "amd64", "386":
+ default:
+ t.Skip("MakeFunc not implemented for " + runtime.GOARCH)
+ }
+
+ fn := func(i int) int { return i }
+ incr := func(in []Value) []Value {
+ return []Value{ValueOf(int(in[0].Int() + 1))}
+ }
+ fv := MakeFunc(TypeOf(fn), incr)
+ ValueOf(&fn).Elem().Set(fv)
+ if r := fn(2); r != 3 {
+ t.Errorf("Call returned %d, want 3", r)
+ }
+ if r := fv.Call([]Value{ValueOf(14)})[0].Int(); r != 15 {
+ t.Errorf("Call returned %d, want 15", r)
+ }
+ if r := fv.Interface().(func(int) int)(26); r != 27 {
+ t.Errorf("Call returned %d, want 27", r)
+ }
+}
+
type Point struct {
x, y int
}
diff -r 52c01e7b81fe libgo/go/reflect/makefunc.go
--- a/libgo/go/reflect/makefunc.go Fri Oct 04 11:00:40 2013 -0700
+++ b/libgo/go/reflect/makefunc.go Fri Oct 04 11:49:27 2013 -0700
@@ -63,7 +63,7 @@
impl := &makeFuncImpl{code: code, typ: ftyp, fn: fn}
- return Value{t, unsafe.Pointer(impl), flag(Func) << flagKindShift}
+ return Value{t, unsafe.Pointer(&impl), flag(Func<<flagKindShift) | flagIndir}
}
// makeFuncStub is an assembly function that is the code half of