mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
reflect: add PtrTo, add Value.Addr (old Addr is now UnsafeAddr)
This change makes it possible to take the address of a struct field or slice element in order to call a method that requires a pointer receiver. Existing code that uses the Value.Addr method will have to change (as gob does in this CL) to call UnsafeAddr instead. R=r, rog CC=golang-dev https://golang.org/cl/4239052
This commit is contained in:
parent
44fd7573aa
commit
e46acb091f
6 changed files with 285 additions and 52 deletions
|
|
@ -518,7 +518,7 @@ func (dec *Decoder) decodeArray(atyp *reflect.ArrayType, state *decodeState, p u
|
|||
|
||||
func decodeIntoValue(state *decodeState, op decOp, indir int, v reflect.Value, ovfl os.ErrorString) reflect.Value {
|
||||
instr := &decInstr{op, 0, indir, 0, ovfl}
|
||||
up := unsafe.Pointer(v.Addr())
|
||||
up := unsafe.Pointer(v.UnsafeAddr())
|
||||
if indir > 1 {
|
||||
up = decIndirect(up, indir)
|
||||
}
|
||||
|
|
@ -1052,9 +1052,9 @@ func (dec *Decoder) decodeValue(wireId typeId, val reflect.Value) (err os.Error)
|
|||
name := base.Name()
|
||||
return os.ErrorString("gob: type mismatch: no fields matched compiling decoder for " + name)
|
||||
}
|
||||
return dec.decodeStruct(engine, ut, uintptr(val.Addr()), indir)
|
||||
return dec.decodeStruct(engine, ut, uintptr(val.UnsafeAddr()), indir)
|
||||
}
|
||||
return dec.decodeSingle(engine, ut, uintptr(val.Addr()))
|
||||
return dec.decodeSingle(engine, ut, uintptr(val.UnsafeAddr()))
|
||||
}
|
||||
|
||||
func (dec *Decoder) decodeIgnoredValue(wireId typeId) os.Error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue