diff options
| author | Carlos Amedee <carlos@golang.org> | 2025-04-23 12:30:52 -0400 |
|---|---|---|
| committer | Carlos Amedee <carlos@golang.org> | 2025-05-13 14:02:58 -0700 |
| commit | b4e992b6e1a3eb6985814ac074ad3057ab21c40a (patch) | |
| tree | 0504fd7a882ee571481029bbe96ce65e28809c05 /src | |
| parent | afd6b0bc663cf49e74200729da91785219d28b53 (diff) | |
| download | go-b4e992b6e1a3eb6985814ac074ad3057ab21c40a.tar.xz | |
reflect: use runtime.AddCleanup instead of runtime.SetFinalizer
Replace a usage of runtime.SetFinalizer with runtime.AddCleanup in
the TestCallReturnsEmpty test. There is an additional use of
SetFinalizer in the reflect package which depends on object
resurrection and needs further refactoring to replace.
Updates #70907
Change-Id: I4c0e56c35745a225776bd611d026945efdaf96f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/667595
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/reflect/all_test.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 3d1e410dac..16c361e53f 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -2240,18 +2240,18 @@ func TestCallReturnsEmpty(t *testing.T) { // Issue 21717: past-the-end pointer write in Call with // nonzero-sized frame and zero-sized return value. runtime.GC() - var finalized uint32 + var cleanedUp atomic.Uint32 f := func() (emptyStruct, *[2]int64) { - i := new([2]int64) // big enough to not be tinyalloc'd, so finalizer always runs when i dies - runtime.SetFinalizer(i, func(*[2]int64) { atomic.StoreUint32(&finalized, 1) }) + i := new([2]int64) // big enough to not be tinyalloc'd, so cleanup always runs when i dies + runtime.AddCleanup(i, func(cu *atomic.Uint32) { cu.Store(uint32(1)) }, &cleanedUp) return emptyStruct{}, i } - v := ValueOf(f).Call(nil)[0] // out[0] should not alias out[1]'s memory, so the finalizer should run. + v := ValueOf(f).Call(nil)[0] // out[0] should not alias out[1]'s memory, so the cleanup should run. timeout := time.After(5 * time.Second) - for atomic.LoadUint32(&finalized) == 0 { + for cleanedUp.Load() == 0 { select { case <-timeout: - t.Fatal("finalizer did not run") + t.Fatal("cleanup did not run") default: } runtime.Gosched() |
