func F() { if b { for { } } C.f() }
func Tcsetpgrp(fd int, pid int) error { i := C.f(C.int(fd), C.pid_t(pid)) if i != 0 { return syscall.Errno(C.e()) } return nil }
func main() { var wg sync.WaitGroup var mu sync.Mutex c := make(chan []C.char, 100) for i := 0; i < 10; i++ { wg.Add(2) go func() { defer wg.Done() for i := 0; i < 100; i++ { c <- make([]C.char, 4096) runtime.Gosched() } }() go func() { defer wg.Done() for i := 0; i < 100; i++ { p := &(<-c)[0] mu.Lock() C.f(p) mu.Unlock() } }() } wg.Wait() }
func main() { a := make([]int32, 10) C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a))) for i, v := range a { if i != int(v) { fmt.Println("bad %d: %v\n", i, a) os.Exit(1) } } }
func CgoTests() { var c chan bool C.f(*(*unsafe.Pointer)(unsafe.Pointer(&c))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&c)) // ERROR "embedded pointer" var m map[string]string C.f(*(*unsafe.Pointer)(unsafe.Pointer(&m))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&m)) // ERROR "embedded pointer" var f func() C.f(*(*unsafe.Pointer)(unsafe.Pointer(&f))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&f)) // ERROR "embedded pointer" var s []int C.f(*(*unsafe.Pointer)(unsafe.Pointer(&s))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&s)) // ERROR "embedded pointer" var a [1][]int C.f(*(*unsafe.Pointer)(unsafe.Pointer(&a))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&a)) // ERROR "embedded pointer" var st struct{ f []int } C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st))) // ERROR "embedded pointer" C.f(unsafe.Pointer(&st)) // ERROR "embedded pointer" // The following cases are OK. var i int C.f(*(*unsafe.Pointer)(unsafe.Pointer(&i))) C.f(unsafe.Pointer(&i)) C.f(*(*unsafe.Pointer)(unsafe.Pointer(&s[0]))) C.f(unsafe.Pointer(&s[0])) var a2 [1]int C.f(*(*unsafe.Pointer)(unsafe.Pointer(&a2))) C.f(unsafe.Pointer(&a2)) var st2 struct{ i int } C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2))) C.f(unsafe.Pointer(&st2)) C.CBytes([]byte("hello")) }
func main() { a := make([]int32, 10) C.f((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a))) a[4] = 1 C.g((*C.int32_t)(unsafe.Pointer(&a[0])), C.int(len(a))) }
func main() { _ = C.f(1) // ERROR HERE }
func main() { fmt.Println(Random()) fmt.Println(C.f(2)) }
func F(p *x) { C.f(p) // ERROR HERE }
func main() { if r := C.f(); r != 1 { panic(r) } }