Skip to content

Commit 8b0acd9

Browse files
dgryskideadprogram
authored andcommitted
runtime: properly turn pointer into empty interface when hashing
1 parent aba3a23 commit 8b0acd9

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/runtime/hashmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ func hashmapInterfaceHash(itf interface{}, seed uintptr) uint32 {
563563
}
564564

565565
func hashmapInterfacePtrHash(iptr unsafe.Pointer, size uintptr, seed uintptr) uint32 {
566-
_i := *(*_interface)(iptr)
566+
_i := *(*interface{})(iptr)
567567
return hashmapInterfaceHash(_i, seed)
568568
}
569569

testdata/map.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ func main() {
129129
floatcmplx()
130130

131131
mapgrow()
132+
133+
interfacerehash()
132134
}
133135

134136
func floatcmplx() {
@@ -274,3 +276,35 @@ func mapgrow() {
274276
}
275277
println("done")
276278
}
279+
280+
type Counter interface {
281+
count() int
282+
}
283+
284+
type counter struct {
285+
i int
286+
}
287+
288+
func (c *counter) count() int {
289+
return c.i
290+
}
291+
292+
func interfacerehash() {
293+
m := make(map[Counter]int)
294+
295+
for i := 0; i < 20; i++ {
296+
c := &counter{i}
297+
m[c] = i
298+
}
299+
300+
var failures int
301+
for k, v := range m {
302+
if got := m[k]; got != v {
303+
println("lookup failure got", got, "want", v)
304+
failures++
305+
}
306+
}
307+
if failures == 0 {
308+
println("no interface lookup failures")
309+
}
310+
}

testdata/map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ tested growing of a map
8080
2
8181
2
8282
done
83+
no interface lookup failures

0 commit comments

Comments
 (0)