diff options
author | Damian Gryski <[email protected]> | 2023-02-24 23:48:31 -0800 |
---|---|---|
committer | Ayke <[email protected]> | 2023-02-25 06:42:30 -0800 |
commit | 7b44fcd865370d5ecf7471b04ad1b4e013e63708 (patch) | |
tree | c979a2b3e51fcdd565f9a3bdb0ba92372c561696 | |
parent | cfe971d723a4e91e7f7df65c8f9479e4eb2c7477 (diff) | |
download | tinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.tar.gz tinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.zip |
runtime: properly turn pointer into empty interface when hashing
-rw-r--r-- | src/runtime/hashmap.go | 2 | ||||
-rw-r--r-- | testdata/map.go | 34 | ||||
-rw-r--r-- | testdata/map.txt | 1 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 2db09f590..e00b223d4 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -563,7 +563,7 @@ func hashmapInterfaceHash(itf interface{}, seed uintptr) uint32 { } func hashmapInterfacePtrHash(iptr unsafe.Pointer, size uintptr, seed uintptr) uint32 { - _i := *(*_interface)(iptr) + _i := *(*interface{})(iptr) return hashmapInterfaceHash(_i, seed) } diff --git a/testdata/map.go b/testdata/map.go index d30889910..d746cf9fc 100644 --- a/testdata/map.go +++ b/testdata/map.go @@ -129,6 +129,8 @@ func main() { floatcmplx() mapgrow() + + interfacerehash() } func floatcmplx() { @@ -274,3 +276,35 @@ func mapgrow() { } println("done") } + +type Counter interface { + count() int +} + +type counter struct { + i int +} + +func (c *counter) count() int { + return c.i +} + +func interfacerehash() { + m := make(map[Counter]int) + + for i := 0; i < 20; i++ { + c := &counter{i} + m[c] = i + } + + var failures int + for k, v := range m { + if got := m[k]; got != v { + println("lookup failure got", got, "want", v) + failures++ + } + } + if failures == 0 { + println("no interface lookup failures") + } +} diff --git a/testdata/map.txt b/testdata/map.txt index 6bf04c80d..d5e553b1a 100644 --- a/testdata/map.txt +++ b/testdata/map.txt @@ -80,3 +80,4 @@ tested growing of a map 2 2 done +no interface lookup failures |