mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-12 07:29:30 +00:00
runtime: require explicit GC layouts
This commit is contained in:
@@ -994,6 +994,20 @@ func TestTypeAssertPanic(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
type tinyMakeChanElement struct {
|
||||
ptr *int
|
||||
text string
|
||||
}
|
||||
|
||||
var tinyMakeChanChurn []*int
|
||||
|
||||
//go:noinline
|
||||
func fillTinyMakeChan(ch chan tinyMakeChanElement) {
|
||||
value := new(int)
|
||||
*value = 42
|
||||
ch <- tinyMakeChanElement{ptr: value, text: "hello"}
|
||||
}
|
||||
|
||||
func TestTinyMakeChan(t *testing.T) {
|
||||
// Value.Send and Value.Recv are not implemented yet, so the channel is
|
||||
// exercised through Interface(): that proves MakeChan returns a working
|
||||
@@ -1027,6 +1041,22 @@ func TestTinyMakeChan(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("buffered pointers survive GC", func(t *testing.T) {
|
||||
v := MakeChan(TypeOf(make(chan tinyMakeChanElement)), 1)
|
||||
ch := v.Interface().(chan tinyMakeChanElement)
|
||||
fillTinyMakeChan(ch)
|
||||
runtime.GC()
|
||||
tinyMakeChanChurn = make([]*int, 128)
|
||||
for i := range tinyMakeChanChurn {
|
||||
tinyMakeChanChurn[i] = new(int)
|
||||
}
|
||||
|
||||
got := <-ch
|
||||
if *got.ptr != 42 || got.text != "hello" {
|
||||
t.Errorf("<-ch=%v, want {42 hello}", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unbuffered", func(t *testing.T) {
|
||||
v := MakeChan(TypeOf(make(chan string)), 0)
|
||||
if got, want := v.Cap(), 0; got != want {
|
||||
|
||||
Reference in New Issue
Block a user