diff options
| author | thepudds <thepudds1460@gmail.com> | 2025-02-06 08:07:38 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-02-06 13:16:59 -0800 |
| commit | 8163ea1458763aa38fa9197e479bd30cb0145429 (patch) | |
| tree | e4191d199aef072217af0bdeb64d76cf52ca899e /src/weak/pointer_test.go | |
| parent | 478ad013f90fe1dbb199d22f41b93c920ae0d5e9 (diff) | |
| download | go-8163ea1458763aa38fa9197e479bd30cb0145429.tar.xz | |
weak: prevent unsafe conversions using weak pointers
Prevent conversions between Pointer types,
like we do for sync/atomic.Pointer.
Fixes #71583
Change-Id: I20e83106d8a27996f221e6cd9d52637b0442cea4
Reviewed-on: https://go-review.googlesource.com/c/go/+/647195
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/weak/pointer_test.go')
| -rw-r--r-- | src/weak/pointer_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/weak/pointer_test.go b/src/weak/pointer_test.go index e0ef30377e..70c743381c 100644 --- a/src/weak/pointer_test.go +++ b/src/weak/pointer_test.go @@ -6,10 +6,12 @@ package weak_test import ( "context" + "internal/goarch" "runtime" "sync" "testing" "time" + "unsafe" "weak" ) @@ -155,6 +157,14 @@ func TestPointerFinalizer(t *testing.T) { } } +func TestPointerSize(t *testing.T) { + var p weak.Pointer[T] + size := unsafe.Sizeof(p) + if size != goarch.PtrSize { + t.Errorf("weak.Pointer[T] size = %d, want %d", size, goarch.PtrSize) + } +} + // Regression test for issue 69210. // // Weak-to-strong conversions must shade the new strong pointer, otherwise |
