Source file
test/stack.go
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 type T [20]int
14
15 func g(c chan int, t T) {
16 s := 0
17 for i := 0; i < len(t); i++ {
18 s += t[i]
19 }
20 c <- s
21 }
22
23 func d(t T) {
24 s := 0
25 for i := 0; i < len(t); i++ {
26 s += t[i]
27 }
28 if s != len(t) {
29 println("bad defer", s)
30 panic("fail")
31 }
32 }
33
34 func f0() {
35
36
37
38 f1()
39 }
40
41 func f1() [3000]byte {
42
43
44
45
46
47
48
49
50
51 f2()
52 return [3000]byte{}
53 }
54
55 func f2() [3000]byte {
56
57 return [3000]byte{}
58 }
59
60 var c = make(chan int)
61 var t T
62 var b = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
63
64 func recur(n int) {
65 ss := string(b)
66 if len(ss) != len(b) {
67 panic("bad []byte -> string")
68 }
69 go g(c, t)
70 f0()
71 s := <-c
72 if s != len(t) {
73 println("bad go", s)
74 panic("fail")
75 }
76 f := func(t T) int {
77 s := 0
78 for i := 0; i < len(t); i++ {
79 s += t[i]
80 }
81 s += n
82 return s
83 }
84 s = f(t)
85 if s != len(t)+n {
86 println("bad func", s, "at level", n)
87 panic("fail")
88 }
89 if n > 0 {
90 recur(n - 1)
91 }
92 defer d(t)
93 }
94
95 func main() {
96 for i := 0; i < len(t); i++ {
97 t[i] = 1
98 }
99 recur(8000)
100 }
101
View as plain text