]> Cypherpunks repositories - gostls13.git/commitdiff
hash/maphash: hash channels in purego version of maphash.Comparable
authorVladislav Yarmak <vladislav@vm-0.com>
Sat, 10 May 2025 17:58:48 +0000 (17:58 +0000)
committerSean Liao <sean@liao.dev>
Tue, 20 May 2025 15:41:59 +0000 (08:41 -0700)
This change makes purego implementation of maphash.Comparable consistent
with the one in runtime and fixes hashing of channels.

Fixes #73657

Change-Id: If78a21d996f0c20c0224d4014e4a4177b09c3aa3
GitHub-Last-Rev: 2537216a1e4e62791c7e417441ee770ca149f38a
GitHub-Pull-Request: golang/go#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>
src/hash/maphash/maphash_purego.go
src/hash/maphash/maphash_test.go

index 53636a48ca21c9ddb18d94d1f35f4fb7dc37548c..07b5eaa46056ace2447c5a863772c218164b8aef 100644 (file)
@@ -161,7 +161,7 @@ func appendT(h *Hash, v reflect.Value) {
        case reflect.Bool:
                h.WriteByte(btoi(v.Bool()))
                return
-       case reflect.UnsafePointer, reflect.Pointer:
+       case reflect.UnsafePointer, reflect.Pointer, reflect.Chan:
                var buf [8]byte
                // because pointing to the abi.Escape call in comparableReady,
                // So this is ok to hash pointer,
index 0774c1c3ced7c0bbd4bdff3ec4d4cd020d1b91ea..c9ef1777ec92f3510fdde04ccb12b34b49d9dfb9 100644 (file)
@@ -254,12 +254,17 @@ func TestComparable(t *testing.T) {
        }
        testComparable(t, s1, s2)
        testComparable(t, s1.s, s2.s)
+       c1 := make(chan struct{})
+       c2 := make(chan struct{})
+       testComparable(t, c1, c1)
+       testComparable(t, chan struct{}(nil))
        testComparable(t, float32(0), negativeZero[float32]())
        testComparable(t, float64(0), negativeZero[float64]())
        testComparableNoEqual(t, math.NaN(), math.NaN())
        testComparableNoEqual(t, [2]string{"a", ""}, [2]string{"", "a"})
        testComparableNoEqual(t, struct{ a, b string }{"foo", ""}, struct{ a, b string }{"", "foo"})
        testComparableNoEqual(t, struct{ a, b any }{int(0), struct{}{}}, struct{ a, b any }{struct{}{}, int(0)})
+       testComparableNoEqual(t, c1, c2)
 }
 
 func testComparableNoEqual[T comparable](t *testing.T, v1, v2 T) {