Skip to content

Commit db8f1dc

Browse files
Snawootgopherbot
authored andcommitted
[release-branch.go1.24] 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. For golang#73657 Fixes golang#73669 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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: qiu laidongfeng2 <[email protected]> (cherry picked from commit 1635aed) Reviewed-on: https://go-review.googlesource.com/c/go/+/676817 Auto-Submit: Michael Knyszek <[email protected]>
1 parent 664cf83 commit db8f1dc

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
@@ -253,12 +253,17 @@ func TestComparable(t *testing.T) {
253253
}
254254
testComparable(t, s1, s2)
255255
testComparable(t, s1.s, s2.s)
256+
c1 := make(chan struct{})
257+
c2 := make(chan struct{})
258+
testComparable(t, c1, c1)
259+
testComparable(t, chan struct{}(nil))
256260
testComparable(t, float32(0), negativeZero[float32]())
257261
testComparable(t, float64(0), negativeZero[float64]())
258262
testComparableNoEqual(t, math.NaN(), math.NaN())
259263
testComparableNoEqual(t, [2]string{"a", ""}, [2]string{"", "a"})
260264
testComparableNoEqual(t, struct{ a, b string }{"foo", ""}, struct{ a, b string }{"", "foo"})
261265
testComparableNoEqual(t, struct{ a, b any }{int(0), struct{}{}}, struct{ a, b any }{struct{}{}, int(0)})
266+
testComparableNoEqual(t, c1, c2)
262267
}
263268

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

0 commit comments

Comments
 (0)