Commit 419e1e05 authored by Rob Pike's avatar Rob Pike

add some support for modifying what pointers point to

R=rsc
DELTA=27  (16 added, 11 deleted, 0 changed)
OCL=19130
CL=19132
parent 6e70c2c7
......@@ -91,17 +91,6 @@ func main() {
var s string;
var t reflect.Type;
{
var ip *int32;
var i int32 = 1234;
vip := reflect.NewValue(&ip);
vi := reflect.NewValue(i);
vip.(reflect.PtrValue).Sub().(reflect.PtrValue).SetSub(vi);
if *ip != 1234 {
panicln("SetSub failure", *ip);
}
}
// Types
typedump("missing", "$missing$");
typedump("int", "int");
......@@ -205,6 +194,17 @@ func main() {
assert(reflect.ValueToString(value.(reflect.PtrValue).Sub()), "main.AA·test{1, 2, 3, 4, 123, 6, 7, 8, 9, 10}");
}
{
var ip *int32;
var i int32 = 1234;
vip := reflect.NewValue(&ip);
vi := reflect.NewValue(i);
vip.(reflect.PtrValue).Sub().(reflect.PtrValue).SetSub(vi);
if *ip != 1234 {
panicln("SetSub failure", *ip);
}
}
var pt reflect.PtrType;
var st reflect.StructType;
var mt reflect.MapType;
......
......@@ -514,6 +514,11 @@ func (v *PtrValueStruct) Sub() Value {
}
func (v *PtrValueStruct) SetSub(subv Value) {
a := v.typ.(PtrType).Sub().String();
b := subv.Type().String();
if a != b {
panicln("reflect: incompatible types in PtrValue.SetSub:", a, b);
}
*AddrToPtrAddr(v.addr) = subv.Addr();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment