]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix list test memory management for mayMoreStack
authorMichael Pratt <mpratt@google.com>
Wed, 12 Nov 2025 20:20:54 +0000 (15:20 -0500)
committerMichael Pratt <mpratt@google.com>
Wed, 12 Nov 2025 21:54:59 +0000 (13:54 -0800)
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 <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/list_manual_test.go

index 281a06ac867a3405a6829b33b2584494b6276c81..f0b64b48ec7efb4dac893afe08390b213bd297be 100644 (file)
@@ -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))