From: Michael Pratt Date: Wed, 12 Nov 2025 20:20:54 +0000 (-0500) Subject: runtime: fix list test memory management for mayMoreStack X-Git-Tag: go1.26rc1~309 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f03d06ec1a;p=gostls13.git runtime: fix list test memory management for mayMoreStack The NIH tests simply failed to allocate the nodes outside the heap at all. The Manual tests failed to keep the nodes alive, allowing the GC to collect them. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Change-Id: I6a6a636c434bb703d6888383d32dbf95fb0a15ea Reviewed-on: https://go-review.googlesource.com/c/go/+/719962 TryBot-Bypass: Michael Pratt Auto-Submit: Michael Pratt Reviewed-by: Michael Knyszek --- diff --git a/src/runtime/list_manual_test.go b/src/runtime/list_manual_test.go index 281a06ac86..f0b64b48ec 100644 --- a/src/runtime/list_manual_test.go +++ b/src/runtime/list_manual_test.go @@ -21,10 +21,19 @@ type listedValManual struct { bNode runtime.ListNodeManual } +// ListHeadManual is intended to be used with objects where the lifetime of the +// object is managed explicitly, so it is OK to store as uintptr. +// +// This means that our test values must outlive the test, and must not live on +// the stack (which may move). +var allListedValManual []*listedValManual + func newListedValManual(v int) *listedValManual { - return &listedValManual{ + lv := &listedValManual{ val: v, } + allListedValManual = append(allListedValManual, lv) + return lv } func TestListManualPush(t *testing.T) { @@ -239,13 +248,13 @@ func TestListNIHPush(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) p := headA.Pop() @@ -296,13 +305,13 @@ func TestListNIHRemoveHead(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(three)) @@ -326,13 +335,13 @@ func TestListNIHRemoveMiddle(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(two)) @@ -356,13 +365,13 @@ func TestListNIHRemoveTail(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(one)) @@ -386,13 +395,13 @@ func TestListNIHRemoveAll(t *testing.T) { headA := newListHeadNIH() headA.Init(unsafe.Offsetof(listedValNIH{}.aNode)) - one := newListedVal(1) + one := newListedValNIH(1) headA.Push(unsafe.Pointer(one)) - two := newListedVal(2) + two := newListedValNIH(2) headA.Push(unsafe.Pointer(two)) - three := newListedVal(3) + three := newListedValNIH(3) headA.Push(unsafe.Pointer(three)) headA.Remove(unsafe.Pointer(one))