]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.8] reflect: clear ptrToThis in Ptr when allocating result on...
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Fri, 10 Feb 2017 00:08:13 +0000 (13:08 +1300)
committerRuss Cox <rsc@golang.org>
Fri, 10 Feb 2017 17:53:40 +0000 (17:53 +0000)
Otherwise, calling PtrTo on the result will fail.

Fixes #19003

Change-Id: I8d7d1981a5d0417d5aee52740469d71e90734963
Reviewed-on: https://go-review.googlesource.com/36731
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-on: https://go-review.googlesource.com/36718
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/reflect/all_test.go
src/reflect/type.go

index 022350b322f9910f30514b5df973203c8ebaaf59..3eca29367589757c6a23dd639aa1e01e59fb39d6 100644 (file)
@@ -2478,17 +2478,24 @@ func TestNumMethodOnDDD(t *testing.T) {
 }
 
 func TestPtrTo(t *testing.T) {
+       // This block of code means that the ptrToThis field of the
+       // reflect data for *unsafe.Pointer is non zero, see
+       // https://golang.org/issue/19003
+       var x unsafe.Pointer
+       var y = &x
+       var z = &y
+
        var i int
 
-       typ := TypeOf(i)
+       typ := TypeOf(z)
        for i = 0; i < 100; i++ {
                typ = PtrTo(typ)
        }
        for i = 0; i < 100; i++ {
                typ = typ.Elem()
        }
-       if typ != TypeOf(i) {
-               t.Errorf("after 100 PtrTo and Elem, have %s, want %s", typ, TypeOf(i))
+       if typ != TypeOf(z) {
+               t.Errorf("after 100 PtrTo and Elem, have %s, want %s", typ, TypeOf(z))
        }
 }
 
index 9d6e7a6846781f7513760da833e01b9a56bf99a4..5d3c5c612a15c0d9416d6af524f22a26522eaefd 100644 (file)
@@ -1469,6 +1469,7 @@ func (t *rtype) ptrTo() *rtype {
        pp := *prototype
 
        pp.str = resolveReflectName(newName(s, "", "", false))
+       pp.ptrToThis = 0
 
        // For the type structures linked into the binary, the
        // compiler provides a good hash of the string.