reflect: disallow Interface method on Value obtained via unexported name
Had been allowing it for use by fmt, but it is too hard to lock down.
Fix other packages not to depend on it.
On Oct 17, 2011 at 14:59, r@golang.org wrote: > http://codereview.appspot.com/5266054/diff/1001/src/pkg/fmt/print.go#newcode654 > src/pkg/fmt/print.go:654: p.fmtBool(f, verb, field, ...
13 years, 5 months ago
(2011-10-17 19:01:59 UTC)
#3
On Oct 17, 2011 at 14:59, r@golang.org wrote:
>
http://codereview.appspot.com/5266054/diff/1001/src/pkg/fmt/print.go#newcode654
> src/pkg/fmt/print.go:654: p.fmtBool(f, verb, field, reflect.Value{})
> there's a lot of creation and passing of reflection values being added
> here. can we store the thing in p and avoid that? i think we can, and it
> would simplify (and speed up) this process.
The only creation is of zero values (reflect.Value{}).
I don't think that is slowing us down.
I'm not thrilled with it but it seems cleaner than
hiding state in p that code might or might not
remember to keep up to date.
Russ
On Mon, Oct 17, 2011 at 15:59, <r@golang.org> wrote: > is it still possible to ...
13 years, 5 months ago
(2011-10-17 20:00:44 UTC)
#9
On Mon, Oct 17, 2011 at 15:59, <r@golang.org> wrote:
> is it still possible to avoid this check working by hand, without using
> unsafe?
yes, you can call value.CanInterface before calling value.Interface.
On Oct 17, 2011, at 1:00 PM, Russ Cox wrote: > On Mon, Oct 17, ...
13 years, 5 months ago
(2011-10-17 20:01:22 UTC)
#10
On Oct 17, 2011, at 1:00 PM, Russ Cox wrote:
> On Mon, Oct 17, 2011 at 15:59, <r@golang.org> wrote:
>> is it still possible to avoid this check working by hand, without using
>> unsafe?
>
> yes, you can call value.CanInterface before calling value.Interface.
no, i meant the other way around. can i still break the rules?
-rob
On Mon, Oct 17, 2011 at 16:01, Rob 'Commander' Pike <r@google.com> wrote: > no, i ...
13 years, 5 months ago
(2011-10-17 20:01:56 UTC)
#11
On Mon, Oct 17, 2011 at 16:01, Rob 'Commander' Pike <r@google.com> wrote:
> no, i meant the other way around. can i still break the rules?
i don't believe so.
the intent is definitely not to let people break the rules anymore.
On Oct 17, 2011, at 1:01 PM, Russ Cox wrote: > On Mon, Oct 17, ...
13 years, 5 months ago
(2011-10-17 20:07:33 UTC)
#12
On Oct 17, 2011, at 1:01 PM, Russ Cox wrote:
> On Mon, Oct 17, 2011 at 16:01, Rob 'Commander' Pike <r@google.com> wrote:
>> no, i meant the other way around. can i still break the rules?
>
> i don't believe so.
> the intent is definitely not to let people break the rules anymore.
i understand the intent, it's the implementation i'm trying to figure out.
-rob
> i understand the intent, it's the implementation i'm trying to figure out. the only ...
13 years, 5 months ago
(2011-10-17 22:29:08 UTC)
#13
> i understand the intent, it's the implementation i'm trying to figure out.
the only place i am aware of where reflect was letting
clients cheat was in Interface - the appropriate check
was there, just commented out because it broke fmt.
this CL puts the check back - if the flagRO bit is set,
it means that the value was obtained by using an
unexported field, so it and any values obtained by using
it must be treated as read-only. returning an int from
Interface would be fine, since ints are inherently
read-only, but returning a *int would not be, since
you could then write through it.
russ
Benchmarked: it is about 5% slower. It might be interesting to move more of the ...
13 years, 5 months ago
(2011-10-17 22:38:36 UTC)
#14
Benchmarked: it is about 5% slower.
It might be interesting to move more of the parameters
into p or p.fmt, but let's do that refactoring in another CL.
This CL is about fixing the reflect bugs, and I'd like to
keep it as straightforward as possible so that we can be
confident about backporting it into r60.
Russ
*** Submitted as http://code.google.com/p/go/source/detail?r=f798c2579fbd *** reflect: disallow Interface method on Value obtained via unexported name ...
13 years, 5 months ago
(2011-10-17 22:48:48 UTC)
#16
On Mon, Oct 17, 2011 at 18:53, <r@golang.org> wrote: > src/pkg/fmt/print.go:667: p.fmtBool(f, verb, field, reflect.Value{}) ...
13 years, 5 months ago
(2011-10-18 12:41:14 UTC)
#18
On Mon, Oct 17, 2011 at 18:53, <r@golang.org> wrote:
> src/pkg/fmt/print.go:667: p.fmtBool(f, verb, field, reflect.Value{})
> i asked you to tidy this up.
>
> ok, i'll do a pass to restore it to my comfort zone.
sorry, i planned to do that in the refactoring i promised
in a later CL. i was going to take a crack at that today
but i will assume it's in your court unless i hear otherwise.
as for reflect.Value{} vs declaring and using a zero,
the compiler should have an easier job in the former case,
because it can synthesize zeros more easily than copy them.
if it doesn't do that well, i should fix that. i started on making
some of the init stuff a bit cleaner a while back but only got
as far as fixing globals.
russ
Issue 5266054: code review 5266054: reflect: disallow Interface method on Value obtained vi...
(Closed)
Created 13 years, 5 months ago by rsc
Modified 13 years, 5 months ago
Reviewers: r
Base URL:
Comments: 6