2015-04-13 09:31:14 -06: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 main
|
|
|
|
|
2015-04-13 17:31:39 -06:00
|
|
|
import (
|
2015-04-17 14:42:16 -06:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-04-13 17:31:39 -06:00
|
|
|
"syscall"
|
|
|
|
"time"
|
2015-04-17 14:42:16 -06:00
|
|
|
|
2019-02-21 10:34:27 -07:00
|
|
|
_ "testcarchive/p"
|
2015-04-13 17:31:39 -06:00
|
|
|
)
|
2015-04-13 09:31:14 -06:00
|
|
|
|
|
|
|
import "C"
|
|
|
|
|
2015-04-13 17:31:39 -06:00
|
|
|
var initCh = make(chan int, 1)
|
|
|
|
var ranMain bool
|
2015-04-13 09:31:14 -06:00
|
|
|
|
2015-04-13 17:31:39 -06:00
|
|
|
func init() {
|
|
|
|
// emulate an exceedingly slow package initialization function
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
initCh <- 42
|
|
|
|
}
|
2015-04-13 09:31:14 -06:00
|
|
|
|
|
|
|
func main() { ranMain = true }
|
|
|
|
|
|
|
|
//export DidInitRun
|
2015-04-13 17:31:39 -06:00
|
|
|
func DidInitRun() bool {
|
|
|
|
select {
|
|
|
|
case x := <-initCh:
|
|
|
|
if x != 42 {
|
|
|
|
// Just in case initCh was not correctly made.
|
|
|
|
println("want init value of 42, got: ", x)
|
|
|
|
syscall.Exit(2)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 09:31:14 -06:00
|
|
|
|
|
|
|
//export DidMainRun
|
|
|
|
func DidMainRun() bool { return ranMain }
|
2015-04-17 14:42:16 -06:00
|
|
|
|
|
|
|
//export CheckArgs
|
|
|
|
func CheckArgs() {
|
2015-04-20 07:33:25 -06:00
|
|
|
if len(os.Args) != 3 || os.Args[1] != "arg1" || os.Args[2] != "arg2" {
|
|
|
|
fmt.Printf("CheckArgs: want [_, arg1, arg2], got: %v\n", os.Args)
|
2015-04-17 14:42:16 -06:00
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
}
|