Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(314)

Unified Diff: libgo/go/reflect/makefunc.go

Issue 152840043: code review 152840043: refect: fix direct call of variadic method value
Patch Set: diff -r ae56e39c190fa444898e76f6268eb29c9a395357 https://code.google.com/p/gofrontend/ Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libgo/go/reflect/all_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libgo/go/reflect/makefunc.go
===================================================================
--- a/libgo/go/reflect/makefunc.go
+++ b/libgo/go/reflect/makefunc.go
@@ -117,29 +117,21 @@
ftyp := (*funcType)(unsafe.Pointer(t))
method := int(v.flag) >> flagMethodShift
- var code uintptr
- var ffi *ffiData
+ fv := &makeFuncImpl{
+ typ: ftyp,
+ method: method,
+ rcvr: rcvr,
+ }
+
switch runtime.GOARCH {
case "amd64", "386":
// Indirect Go func value (dummy) to obtain actual
// code address. (A Go func value is a pointer to a C
// function pointer. http://golang.org/s/go11func.)
dummy := makeFuncStub
- code = **(**uintptr)(unsafe.Pointer(&dummy))
+ fv.code = **(**uintptr)(unsafe.Pointer(&dummy))
default:
- code, ffi = makeFuncFFI(ftyp,
- func(in []Value) []Value {
- m := rcvr.Method(method)
- return m.Call(in)
- })
- }
-
- fv := &makeFuncImpl{
- code: code,
- typ: ftyp,
- method: method,
- rcvr: rcvr,
- ffi: ffi,
+ fv.code, fv.ffi = makeFuncFFI(ftyp, fv.call)
}
return Value{ft, unsafe.Pointer(&fv), v.flag&flagRO | flag(Func)<<flagKindShift | flagIndir}
@@ -160,28 +152,21 @@
t := typ.common()
ftyp := (*funcType)(unsafe.Pointer(t))
- var code uintptr
- var ffi *ffiData
+ impl := &makeFuncImpl{
+ typ: ftyp,
+ method: -2,
+ rcvr: v,
+ }
+
switch runtime.GOARCH {
case "amd64", "386":
// Indirect Go func value (dummy) to obtain actual
// code address. (A Go func value is a pointer to a C
// function pointer. http://golang.org/s/go11func.)
dummy := makeFuncStub
- code = **(**uintptr)(unsafe.Pointer(&dummy))
+ impl.code = **(**uintptr)(unsafe.Pointer(&dummy))
default:
- code, ffi = makeFuncFFI(ftyp,
- func(in []Value) []Value {
- return v.Call(in)
- })
- }
-
- impl := &makeFuncImpl{
- code: code,
- typ: ftyp,
- method: -2,
- rcvr: v,
- ffi: ffi,
+ impl.code, impl.ffi = makeFuncFFI(ftyp, impl.call)
}
return Value{t, unsafe.Pointer(&impl), flag(Func<<flagKindShift) | flagIndir}
@@ -192,9 +177,17 @@
if c.method == -1 {
return c.fn(in)
} else if c.method == -2 {
- return c.rcvr.Call(in)
+ if c.typ.IsVariadic() {
+ return c.rcvr.CallSlice(in)
+ } else {
+ return c.rcvr.Call(in)
+ }
} else {
m := c.rcvr.Method(c.method)
- return m.Call(in)
+ if c.typ.IsVariadic() {
+ return m.CallSlice(in)
+ } else {
+ return m.Call(in)
+ }
}
}
« no previous file with comments | « libgo/go/reflect/all_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b