3 // Copyright 2020 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // This test makes sure unsafe-uintptr arguments are handled correctly.
16 var done = make(chan bool, 1)
18 func setup() unsafe.Pointer {
20 runtime.SetFinalizer(&s, func(p *string) { *p = "FAIL" })
21 return unsafe.Pointer(&s)
26 func test(s string, p, q uintptr, rest ...uintptr) int {
30 if *(*string)(unsafe.Pointer(p)) != "ok" {
31 panic(s + ": p failed")
33 if *(*string)(unsafe.Pointer(q)) != "ok" {
34 panic(s + ": q failed")
36 for _, r := range rest {
37 if *(*string)(unsafe.Pointer(r)) != "ok" {
38 panic(s + ": r[i] failed")
48 return test("return", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
55 func (S) test(s string, p, q uintptr, rest ...uintptr) int {
56 return test(s, p, q, rest...)
60 test("normal", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
63 go test("go", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
67 defer test("defer", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
73 defer test("defer in for loop", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
81 defer s.test("method call", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))
88 defer s.test("defer method loop", uintptr(setup()), uintptr(setup()), uintptr(setup()), uintptr(setup()))