v = ValueOf((*nih)(unsafe.Pointer(new(int))))
shouldPanic("reflect: reflect.Value.Elem on an invalid notinheap pointer", func() { v.Elem() })
}
+
+func TestMethodCallValueCodePtr(t *testing.T) {
+ p := ValueOf(Point{}).Method(1).UnsafePointer()
+ want := MethodValueCallCodePtr()
+ if got := uintptr(p); got != want {
+ t.Errorf("methodValueCall code pointer mismatched, want: %v, got: %v", want, got)
+ }
+}
clearLayoutCache()
return
}
+
+var MethodValueCallCodePtr = methodValueCallCodePtr
// v.Type returns the actual type of the method value.
ftyp := (*funcType)(unsafe.Pointer(v.Type().(*rtype)))
- code := abi.FuncPCABI0(methodValueCall)
+ code := methodValueCallCodePtr()
// methodValue contains a stack map for use by the runtime
_, _, abi := funcLayout(ftyp, nil)
return Value{&ftyp.rtype, unsafe.Pointer(fv), v.flag&flagRO | flag(Func)}
}
+func methodValueCallCodePtr() uintptr {
+ return abi.FuncPCABI0(methodValueCall)
+}
+
// methodValueCall is an assembly function that is the code half of
// the function returned from makeMethodValue. It expects a *methodValue
// as its context register, and its job is to invoke callMethod(ctxt, frame)
// created via reflect have the same underlying code pointer,
// so their Pointers are equal. The function used here must
// match the one used in makeMethodValue.
- f := methodValueCall
- return **(**unsafe.Pointer)(unsafe.Pointer(&f))
+ code := methodValueCallCodePtr()
+ return *(*unsafe.Pointer)(unsafe.Pointer(&code))
}
p := v.pointer()
// Non-nil func value points at data block.