github.com/bir3/gocompiler@v0.9.2202/src/cmd/cgo/internal/test/issue21897.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build darwin && cgo && !internal 6 7 package cgotest 8 9 /* 10 #cgo LDFLAGS: -framework CoreFoundation 11 #include <CoreFoundation/CoreFoundation.h> 12 */ 13 import "C" 14 import ( 15 "runtime/debug" 16 "testing" 17 "unsafe" 18 ) 19 20 func test21897(t *testing.T) { 21 // Please write barrier, kick in soon. 22 defer debug.SetGCPercent(debug.SetGCPercent(1)) 23 24 for i := 0; i < 10000; i++ { 25 testCFNumberRef() 26 testCFDateRef() 27 testCFBooleanRef() 28 // Allocate some memory, so eventually the write barrier is enabled 29 // and it will see writes of bad pointers in the test* functions below. 30 byteSliceSink = make([]byte, 1024) 31 } 32 } 33 34 var byteSliceSink []byte 35 36 func testCFNumberRef() { 37 var v int64 = 0 38 xCFNumberRef = C.CFNumberCreate(C.kCFAllocatorSystemDefault, C.kCFNumberSInt64Type, unsafe.Pointer(&v)) 39 //fmt.Printf("CFNumberRef: %x\n", uintptr(unsafe.Pointer(xCFNumberRef))) 40 } 41 42 var xCFNumberRef C.CFNumberRef 43 44 func testCFDateRef() { 45 xCFDateRef = C.CFDateCreate(C.kCFAllocatorSystemDefault, 0) // 0 value is 1 Jan 2001 00:00:00 GMT 46 //fmt.Printf("CFDateRef: %x\n", uintptr(unsafe.Pointer(xCFDateRef))) 47 } 48 49 var xCFDateRef C.CFDateRef 50 51 func testCFBooleanRef() { 52 xCFBooleanRef = C.kCFBooleanFalse 53 //fmt.Printf("CFBooleanRef: %x\n", uintptr(unsafe.Pointer(xCFBooleanRef))) 54 } 55 56 var xCFBooleanRef C.CFBooleanRef