mirror of
https://github.com/golang/go
synced 2024-11-20 03:34:40 -07:00
xml: fix reflect error
Fixes #1749. R=bradfitz CC=golang-dev https://golang.org/cl/4431075
This commit is contained in:
parent
df2c5d5429
commit
6f88288a13
@ -220,13 +220,10 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pv := val; pv.Kind() == reflect.Ptr {
|
if pv := val; pv.Kind() == reflect.Ptr {
|
||||||
if pv.Pointer() == 0 {
|
if pv.IsNil() {
|
||||||
zv := reflect.Zero(pv.Type().Elem())
|
pv.Set(reflect.New(pv.Type().Elem()))
|
||||||
pv.Set(zv.Addr())
|
|
||||||
val = zv
|
|
||||||
} else {
|
|
||||||
val = pv.Elem()
|
|
||||||
}
|
}
|
||||||
|
val = pv.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -329,47 +329,51 @@ func TestSyntax(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type allScalars struct {
|
type allScalars struct {
|
||||||
True1 bool
|
True1 bool
|
||||||
True2 bool
|
True2 bool
|
||||||
False1 bool
|
False1 bool
|
||||||
False2 bool
|
False2 bool
|
||||||
Int int
|
Int int
|
||||||
Int8 int8
|
Int8 int8
|
||||||
Int16 int16
|
Int16 int16
|
||||||
Int32 int32
|
Int32 int32
|
||||||
Int64 int64
|
Int64 int64
|
||||||
Uint int
|
Uint int
|
||||||
Uint8 uint8
|
Uint8 uint8
|
||||||
Uint16 uint16
|
Uint16 uint16
|
||||||
Uint32 uint32
|
Uint32 uint32
|
||||||
Uint64 uint64
|
Uint64 uint64
|
||||||
Uintptr uintptr
|
Uintptr uintptr
|
||||||
Float32 float32
|
Float32 float32
|
||||||
Float64 float64
|
Float64 float64
|
||||||
String string
|
String string
|
||||||
|
PtrString *string
|
||||||
}
|
}
|
||||||
|
|
||||||
var all = allScalars{
|
var all = allScalars{
|
||||||
True1: true,
|
True1: true,
|
||||||
True2: true,
|
True2: true,
|
||||||
False1: false,
|
False1: false,
|
||||||
False2: false,
|
False2: false,
|
||||||
Int: 1,
|
Int: 1,
|
||||||
Int8: -2,
|
Int8: -2,
|
||||||
Int16: 3,
|
Int16: 3,
|
||||||
Int32: -4,
|
Int32: -4,
|
||||||
Int64: 5,
|
Int64: 5,
|
||||||
Uint: 6,
|
Uint: 6,
|
||||||
Uint8: 7,
|
Uint8: 7,
|
||||||
Uint16: 8,
|
Uint16: 8,
|
||||||
Uint32: 9,
|
Uint32: 9,
|
||||||
Uint64: 10,
|
Uint64: 10,
|
||||||
Uintptr: 11,
|
Uintptr: 11,
|
||||||
Float32: 13.0,
|
Float32: 13.0,
|
||||||
Float64: 14.0,
|
Float64: 14.0,
|
||||||
String: "15",
|
String: "15",
|
||||||
|
PtrString: &sixteen,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sixteen = "16"
|
||||||
|
|
||||||
const testScalarsInput = `<allscalars>
|
const testScalarsInput = `<allscalars>
|
||||||
<true1>true</true1>
|
<true1>true</true1>
|
||||||
<true2>1</true2>
|
<true2>1</true2>
|
||||||
@ -390,6 +394,7 @@ const testScalarsInput = `<allscalars>
|
|||||||
<float32>13.0</float32>
|
<float32>13.0</float32>
|
||||||
<float64>14.0</float64>
|
<float64>14.0</float64>
|
||||||
<string>15</string>
|
<string>15</string>
|
||||||
|
<ptrstring>16</ptrstring>
|
||||||
</allscalars>`
|
</allscalars>`
|
||||||
|
|
||||||
func TestAllScalars(t *testing.T) {
|
func TestAllScalars(t *testing.T) {
|
||||||
@ -401,7 +406,7 @@ func TestAllScalars(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(a, all) {
|
if !reflect.DeepEqual(a, all) {
|
||||||
t.Errorf("expected %+v got %+v", all, a)
|
t.Errorf("have %+v want %+v", a, all)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user