mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: add InterfaceValue.Get to enable setting of an interface
value (through unsafe means) without having a reflect.Type
of type *interface{} (pointer to interface). This is needed to make
gob able to handle interface values by a method analogous to
the way it handles maps.
R=rsc
CC=golang-dev
https://golang.org/cl/2597041
This commit is contained in:
parent
321f0c7fe2
commit
97f3a80d93
1 changed files with 8 additions and 2 deletions
|
|
@ -843,11 +843,17 @@ type InterfaceValue struct {
|
||||||
value "interface"
|
value "interface"
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Get because v.Interface() is available.
|
|
||||||
|
|
||||||
// IsNil returns whether v is a nil interface value.
|
// IsNil returns whether v is a nil interface value.
|
||||||
func (v *InterfaceValue) IsNil() bool { return v.Interface() == nil }
|
func (v *InterfaceValue) IsNil() bool { return v.Interface() == nil }
|
||||||
|
|
||||||
|
// No single uinptr Get because v.Interface() is available.
|
||||||
|
|
||||||
|
// Get returns the two words that represent an interface in the runtime.
|
||||||
|
// Those words are useful only when playing unsafe games.
|
||||||
|
func (v *InterfaceValue) Get() [2]uintptr {
|
||||||
|
return *(*[2]uintptr)(v.addr)
|
||||||
|
}
|
||||||
|
|
||||||
// Elem returns the concrete value stored in the interface value v.
|
// Elem returns the concrete value stored in the interface value v.
|
||||||
func (v *InterfaceValue) Elem() Value { return NewValue(v.Interface()) }
|
func (v *InterfaceValue) Elem() Value { return NewValue(v.Interface()) }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue