aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/list_manual_test.go41
1 files changed, 25 insertions, 16 deletions
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))