]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix methodValueCall code pointer mismatch in Value.Pointer
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 19 Oct 2021 17:16:23 +0000 (00:16 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 19 Oct 2021 18:56:08 +0000 (18:56 +0000)
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>
src/reflect/all_test.go
src/reflect/value.go

index 91aac9cccb287b996793634e54df005a9d00a11f..fcd0e15f0a1c4170dcdd63dd40510d18830b5cb1 100644 (file)
@@ -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)
        }
 }
index 63faa0496443c8322ce552c9ac690f6c4bce1da6..7bb8ae5b974026458ebf86cb1b1731b924048bb8 100644 (file)
@@ -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.