mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
fix up %p
- use an interface {Get()}
- implement Get for maps, slices
- for slices, retrieves the address of the end of the array, which will give the
same value for every slice of the same array.
R=rsc
CC=golang-dev
https://golang.org/cl/179129
This commit is contained in:
parent
d488c4b4ac
commit
148ee9c009
2 changed files with 19 additions and 4 deletions
|
|
@ -567,6 +567,14 @@ func (v *SliceValue) Set(x *SliceValue) {
|
|||
// Set sets v to the value x.
|
||||
func (v *SliceValue) SetValue(x Value) { v.Set(x.(*SliceValue)) }
|
||||
|
||||
// Get returns the uintptr address of the v.Cap()'th element. This gives
|
||||
// the same result for all slices of the same array.
|
||||
// It is mainly useful for printing.
|
||||
func (v *SliceValue) Get() uintptr {
|
||||
typ := v.typ.(*SliceType)
|
||||
return uintptr(v.addr()) + uintptr(v.Cap())*typ.Elem().Size()
|
||||
}
|
||||
|
||||
// Slice returns a sub-slice of the slice v.
|
||||
func (v *SliceValue) Slice(beg, end int) *SliceValue {
|
||||
cap := v.Cap()
|
||||
|
|
@ -970,6 +978,10 @@ func (v *MapValue) Set(x *MapValue) {
|
|||
// Set sets v to the value x.
|
||||
func (v *MapValue) SetValue(x Value) { v.Set(x.(*MapValue)) }
|
||||
|
||||
// Get returns the uintptr value of v.
|
||||
// It is mainly useful for printing.
|
||||
func (v *MapValue) Get() uintptr { return *(*uintptr)(v.addr) }
|
||||
|
||||
// implemented in ../pkg/runtime/reflect.cgo
|
||||
func mapaccess(m, key, val *byte) bool
|
||||
func mapassign(m, key, val *byte)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue