Skip to content

Commit

Permalink
reflect: fix methodValueCall code pointer mismatch in Value.Pointer
Browse files Browse the repository at this point in the history
This is the port of CL 356809 for Value.Pointer to fix the mismatch of
methodValueCall code pointer.

Change-Id: I080ac41b94b44d878cd5896207a76a28c57fd48b
Reviewed-on: https://go-review.googlesource.com/c/go/+/356950
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
  • Loading branch information
cuonglm committed Oct 19, 2021
1 parent d7149e5 commit 07e5527
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/reflect/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7724,9 +7724,12 @@ func TestNotInHeapDeref(t *testing.T) {
}

func TestMethodCallValueCodePtr(t *testing.T) {
p := ValueOf(Point{}).Method(1).UnsafePointer()
m := ValueOf(Point{}).Method(1)
want := MethodValueCallCodePtr()
if got := uintptr(p); got != want {
if got := uintptr(m.UnsafePointer()); got != want {
t.Errorf("methodValueCall code pointer mismatched, want: %v, got: %v", want, got)
}
if got := m.Pointer(); got != want {
t.Errorf("methodValueCall code pointer mismatched, want: %v, got: %v", want, got)
}
}
3 changes: 1 addition & 2 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1957,8 +1957,7 @@ func (v Value) Pointer() uintptr {
// 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 **(**uintptr)(unsafe.Pointer(&f))
return methodValueCallCodePtr()
}
p := v.pointer()
// Non-nil func value points at data block.
Expand Down

0 comments on commit 07e5527

Please sign in to comment.