]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: test name data is aligned
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 25 Mar 2016 18:28:15 +0000 (14:28 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 25 Mar 2016 20:37:08 +0000 (20:37 +0000)
For #14962.

Change-Id: I3539d882487c99dee99ac953e039b79c6b963cf9
Reviewed-on: https://go-review.googlesource.com/21150
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/reflect/all_test.go
src/reflect/export_test.go

index b0a2608afbc2623d5d6dc5c47ca8d8821b4b350d..ebd352ca46ac1d47bfd3590ae1ac3d16c2e04a86 100644 (file)
@@ -5065,3 +5065,16 @@ func TestNames(t *testing.T) {
                }
        }
 }
+
+type embed struct {
+       EmbedWithUnexpMeth
+}
+
+func TestNameBytesAreAligned(t *testing.T) {
+       typ := TypeOf(embed{})
+       b := FirstMethodNameBytes(typ)
+       v := uintptr(unsafe.Pointer(b))
+       if v%unsafe.Alignof((*byte)(nil)) != 0 {
+               t.Errorf("reflect.name.bytes pointer is not aligned: %x", v)
+       }
+}
index e518a16b536caff287ae7e0707e7018074d87e3e..9db6967ffa6d242fea13d6b262eb0a824bc1a6b4 100644 (file)
@@ -70,3 +70,27 @@ func CachedBucketOf(m Type) Type {
        tt := (*mapType)(unsafe.Pointer(t))
        return tt.bucket
 }
+
+type EmbedWithUnexpMeth struct{}
+
+func (EmbedWithUnexpMeth) f() {}
+
+type pinUnexpMeth interface {
+       f()
+}
+
+var pinUnexpMethI = pinUnexpMeth(EmbedWithUnexpMeth{})
+
+func FirstMethodNameBytes(t Type) *byte {
+       _ = pinUnexpMethI
+
+       ut := t.uncommon()
+       if ut == nil {
+               panic("type has no methods")
+       }
+       m := ut.methods[0]
+       if *m.name.data(0)&(1<<2) == 0 {
+               panic("method name does not have pkgPath *string")
+       }
+       return m.name.bytes
+}