2009-01-29 00:58:48 +00:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Try to tickle stack splitting bugs by doing
|
2009-02-06 21:46:56 +00:00
|
|
|
// go, defer, and closure calls at different stack depths.
|
2009-01-29 00:58:48 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
2010-03-24 23:46:53 +00:00
|
|
|
type T [20]int
|
2009-01-29 00:58:48 +00:00
|
|
|
|
|
|
|
func g(c chan int, t T) {
|
2010-03-24 23:46:53 +00:00
|
|
|
s := 0
|
2009-01-29 00:58:48 +00:00
|
|
|
for i := 0; i < len(t); i++ {
|
2010-03-24 23:46:53 +00:00
|
|
|
s += t[i]
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
2010-03-24 23:46:53 +00:00
|
|
|
c <- s
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func d(t T) {
|
2010-03-24 23:46:53 +00:00
|
|
|
s := 0
|
2009-01-29 00:58:48 +00:00
|
|
|
for i := 0; i < len(t); i++ {
|
2010-03-24 23:46:53 +00:00
|
|
|
s += t[i]
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
|
|
|
if s != len(t) {
|
2010-03-24 23:46:53 +00:00
|
|
|
println("bad defer", s)
|
|
|
|
panic("fail")
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 23:46:53 +00:00
|
|
|
var c = make(chan int)
|
|
|
|
var t T
|
|
|
|
var b = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
2009-01-29 00:58:48 +00:00
|
|
|
|
|
|
|
func recur(n int) {
|
2010-03-24 23:46:53 +00:00
|
|
|
ss := string(b)
|
2009-04-10 13:22:41 +00:00
|
|
|
if len(ss) != len(b) {
|
2010-03-24 23:46:53 +00:00
|
|
|
panic("bad []byte -> string")
|
2009-04-10 13:22:41 +00:00
|
|
|
}
|
2010-03-24 23:46:53 +00:00
|
|
|
go g(c, t)
|
|
|
|
s := <-c
|
2009-01-29 00:58:48 +00:00
|
|
|
if s != len(t) {
|
2010-03-24 23:46:53 +00:00
|
|
|
println("bad go", s)
|
|
|
|
panic("fail")
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
2009-02-06 21:46:56 +00:00
|
|
|
f := func(t T) int {
|
2010-03-24 23:46:53 +00:00
|
|
|
s := 0
|
2009-02-06 21:46:56 +00:00
|
|
|
for i := 0; i < len(t); i++ {
|
2010-03-24 23:46:53 +00:00
|
|
|
s += t[i]
|
2009-02-06 21:46:56 +00:00
|
|
|
}
|
2010-03-24 23:46:53 +00:00
|
|
|
s += n
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
s = f(t)
|
|
|
|
if s != len(t)+n {
|
|
|
|
println("bad func", s, "at level", n)
|
|
|
|
panic("fail")
|
2009-02-06 21:46:56 +00:00
|
|
|
}
|
2009-01-29 00:58:48 +00:00
|
|
|
if n > 0 {
|
2010-03-24 23:46:53 +00:00
|
|
|
recur(n - 1)
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
2010-03-24 23:46:53 +00:00
|
|
|
defer d(t)
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
for i := 0; i < len(t); i++ {
|
2010-03-24 23:46:53 +00:00
|
|
|
t[i] = 1
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|
2010-04-23 00:52:22 +00:00
|
|
|
recur(8000)
|
2009-01-29 00:58:48 +00:00
|
|
|
}
|