Skip to content

Commit 973b70e

Browse files
SnawootSirherobrine23
authored andcommitted
hash/maphash: hash channels in purego version of maphash.Comparable
This change makes purego implementation of maphash.Comparable consistent with the one in runtime and fixes hashing of channels. Fixes golang#73657 Change-Id: If78a21d996f0c20c0224d4014e4a4177b09c3aa3 GitHub-Last-Rev: 2537216 GitHub-Pull-Request: golang#73660 Reviewed-on: https://go-review.googlesource.com/c/go/+/671655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com>
1 parent 8b7fd64 commit 973b70e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/hash/maphash/maphash_purego.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func appendT(h *Hash, v reflect.Value) {
161161
case reflect.Bool:
162162
h.WriteByte(btoi(v.Bool()))
163163
return
164-
case reflect.UnsafePointer, reflect.Pointer:
164+
case reflect.UnsafePointer, reflect.Pointer, reflect.Chan:
165165
var buf [8]byte
166166
// because pointing to the abi.Escape call in comparableReady,
167167
// So this is ok to hash pointer,

src/hash/maphash/maphash_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,17 @@ func TestComparable(t *testing.T) {
254254
}
255255
testComparable(t, s1, s2)
256256
testComparable(t, s1.s, s2.s)
257+
c1 := make(chan struct{})
258+
c2 := make(chan struct{})
259+
testComparable(t, c1, c1)
260+
testComparable(t, chan struct{}(nil))
257261
testComparable(t, float32(0), negativeZero[float32]())
258262
testComparable(t, float64(0), negativeZero[float64]())
259263
testComparableNoEqual(t, math.NaN(), math.NaN())
260264
testComparableNoEqual(t, [2]string{"a", ""}, [2]string{"", "a"})
261265
testComparableNoEqual(t, struct{ a, b string }{"foo", ""}, struct{ a, b string }{"", "foo"})
262266
testComparableNoEqual(t, struct{ a, b any }{int(0), struct{}{}}, struct{ a, b any }{struct{}{}, int(0)})
267+
testComparableNoEqual(t, c1, c2)
263268
}
264269

265270
func testComparableNoEqual[T comparable](t *testing.T, v1, v2 T) {

0 commit comments

Comments
 (0)