From: Marcel van Lohuizen Date: Fri, 28 Aug 2015 07:33:51 +0000 (+0200) Subject: reflect: adjust access to unexported embedded structs X-Git-Tag: go1.6beta1~723 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=adf9b30e55943feb44669ebf773964fd32d4ee94;p=gostls13.git reflect: adjust access to unexported embedded structs This CL changes reflect to allow access to exported fields and methods in unexported embedded structs for gccgo and after gc has been adjusted to disallow access to embedded unexported structs. Adresses #12367, #7363, #11007, and #7247. Change-Id: If80536eab35abcd25300d8ddc2d27d5c42d7e78e Reviewed-on: https://go-review.googlesource.com/14010 Reviewed-by: Russ Cox --- diff --git a/src/reflect/export_test.go b/src/reflect/export_test.go index 0b9d0fde9e..26a648e193 100644 --- a/src/reflect/export_test.go +++ b/src/reflect/export_test.go @@ -8,13 +8,13 @@ import "unsafe" // MakeRO returns a copy of v with the read-only flag set. func MakeRO(v Value) Value { - v.flag |= flagRO + v.flag |= flagStickyRO return v } // IsRO reports whether v's read-only flag is set. func IsRO(v Value) bool { - return v.flag&flagRO != 0 + return v.flag&flagStickyRO != 0 } var CallGC = &callGC diff --git a/src/reflect/type.go b/src/reflect/type.go index e98c960a03..aa56fcbe95 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -496,7 +496,7 @@ func (t *uncommonType) Method(i int) (m Method) { fl := flag(Func) if p.pkgPath != nil { m.PkgPath = *p.pkgPath - fl |= flagRO + fl |= flagStickyRO } mt := p.typ m.Type = mt diff --git a/src/reflect/value.go b/src/reflect/value.go index 001d0274ec..2317a7bec3 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -44,7 +44,8 @@ type Value struct { // flag holds metadata about the value. // The lowest bits are flag bits: - // - flagRO: obtained via unexported field, so read-only + // - flagStickyRO: obtained via unexported not embedded field, so read-only + // - flagEmbedRO: obtained via unexported embedded field, so read-only // - flagIndir: val holds a pointer to the data // - flagAddr: v.CanAddr is true (implies flagIndir) // - flagMethod: v is a method value. @@ -67,11 +68,13 @@ type flag uintptr const ( flagKindWidth = 5 // there are 27 kinds flagKindMask flag = 1<