1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00

go/ssa/interp: handle nil *hashmap cleanly

Change-Id: I2cb8eef79bc011b209b3df0b859bcddefd4c8337
Reviewed-on: https://go-review.googlesource.com/32818
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-11-04 17:43:38 -04:00
parent 2e348630fd
commit 58ec10c513
4 changed files with 12 additions and 4 deletions

View File

@ -113,3 +113,11 @@ func (m *hashmap) len() int {
}
return 0
}
// entries returns a rangeable map of entries.
func (m *hashmap) entries() map[int]*entry {
if m != nil {
return m.table
}
return nil
}

View File

@ -1098,7 +1098,7 @@ func rangeIter(x value, t types.Type) iter {
// reflect.(Value).MapKeys machinery.
it := make(mapIter)
go func() {
for _, e := range x.table {
for _, e := range x.entries() {
for e != nil {
it <- [2]value{e.key, e.value}
e = e.next

View File

@ -333,7 +333,7 @@ func ext۰reflect۰Value۰MapKeys(fr *frame, args []value) value {
}
case *hashmap:
for _, e := range v.table {
for _, e := range v.entries() {
for ; e != nil; e = e.next {
keys = append(keys, makeReflectValue(tKey, e.key))
}
@ -365,7 +365,7 @@ func ext۰reflect۰Value۰Pointer(fr *frame, args []value) value {
case []value:
return reflect.ValueOf(v).Pointer()
case *hashmap:
return reflect.ValueOf(v.table).Pointer()
return reflect.ValueOf(v.entries()).Pointer()
case map[value]value:
return reflect.ValueOf(v).Pointer()
case *ssa.Function:

View File

@ -384,7 +384,7 @@ func writeValue(buf *bytes.Buffer, v value) {
case *hashmap:
buf.WriteString("map[")
sep := " "
for _, e := range v.table {
for _, e := range v.entries() {
for e != nil {
buf.WriteString(sep)
sep = " "