3 // Copyright 2019 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 // Test that //go:uintptrescapes works for methods.
21 func F(ptr uintptr) { callback() }
25 func Fv(ptrs ...uintptr) { callback() }
31 func (T) M(ptr uintptr) { callback() }
35 func (T) Mv(ptrs ...uintptr) { callback() }
37 // Each test should pass uintptr(ptr) as an argument to a function call,
38 // which in turn should call callback. The callback checks that ptr is kept alive.
39 var tests = []func(ptr unsafe.Pointer){
40 func(ptr unsafe.Pointer) { F(uintptr(ptr)) },
41 func(ptr unsafe.Pointer) { Fv(uintptr(ptr)) },
42 func(ptr unsafe.Pointer) { T{}.M(uintptr(ptr)) },
43 func(ptr unsafe.Pointer) { T{}.Mv(uintptr(ptr)) },
47 for i, test := range tests {
51 runtime.SetFinalizer(ptr, func(*[64]byte) {
58 fmt.Printf("test #%d failed\n", i)
61 test(unsafe.Pointer(ptr))