2015-05-05 15:57:36 -04:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
package testpkg
|
|
|
|
|
|
|
|
//go:generate gobind -lang=go -outdir=go_testpkg .
|
2015-06-07 14:15:51 -04:00
|
|
|
//go:generate gobind -lang=objc -outdir=objc_testpkg .
|
2015-05-05 15:57:36 -04:00
|
|
|
|
2015-06-04 14:56:48 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"time"
|
|
|
|
)
|
2015-05-05 15:57:36 -04:00
|
|
|
|
|
|
|
func Hi() {
|
|
|
|
fmt.Println("Hi")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Int(x int32) {
|
|
|
|
fmt.Println("Received int32", x)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Sum(x, y int64) int64 {
|
|
|
|
return x + y
|
|
|
|
}
|
|
|
|
|
|
|
|
func Hello(s string) string {
|
|
|
|
return fmt.Sprintf("Hello, %s!", s)
|
|
|
|
}
|
2015-05-11 16:25:42 -04:00
|
|
|
|
|
|
|
func BytesAppend(a []byte, b []byte) []byte {
|
|
|
|
return append(a, b...)
|
|
|
|
}
|
2015-06-02 09:36:44 -04:00
|
|
|
|
2015-06-04 14:56:48 -04:00
|
|
|
var collectS = make(chan struct{}, 100)
|
|
|
|
|
|
|
|
func finalizeS(a *S) {
|
|
|
|
collectS <- struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CollectS(want, timeoutSec int) int {
|
|
|
|
runtime.GC()
|
|
|
|
|
|
|
|
tick := time.NewTicker(time.Duration(timeoutSec) * time.Second)
|
|
|
|
defer tick.Stop()
|
|
|
|
|
|
|
|
for i := 0; i < want; i++ {
|
|
|
|
select {
|
|
|
|
case <-collectS:
|
|
|
|
case <-tick.C:
|
|
|
|
fmt.Println("CollectS: timed out")
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return want
|
|
|
|
}
|
|
|
|
|
2015-06-02 09:36:44 -04:00
|
|
|
type S struct {
|
|
|
|
X, Y float64
|
|
|
|
unexported bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewS(x, y float64) *S {
|
2015-06-04 14:56:48 -04:00
|
|
|
s := &S{X: x, Y: y}
|
|
|
|
runtime.SetFinalizer(s, finalizeS)
|
|
|
|
return s
|
2015-06-02 09:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *S) Sum() float64 {
|
|
|
|
return s.X + s.Y
|
|
|
|
}
|
2015-06-04 14:56:48 -04:00
|
|
|
|
|
|
|
func CallSSum(s *S) float64 {
|
|
|
|
return s.Sum()
|
|
|
|
}
|