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// +build darwin,cgo,!internal 7 8package cgotest 9 10/* 11#cgo LDFLAGS: -framework CoreFoundation 12#include <CoreFoundation/CoreFoundation.h> 13*/ 14import "C" 15import ( 16 "runtime/debug" 17 "testing" 18 "unsafe" 19) 20 21func test21897(t *testing.T) { 22 // Please write barrier, kick in soon. 23 defer debug.SetGCPercent(debug.SetGCPercent(1)) 24 25 for i := 0; i < 10000; i++ { 26 testCFNumberRef() 27 testCFDateRef() 28 testCFBooleanRef() 29 // Allocate some memory, so eventually the write barrier is enabled 30 // and it will see writes of bad pointers in the test* functions below. 31 byteSliceSink = make([]byte, 1024) 32 } 33} 34 35var byteSliceSink []byte 36 37func testCFNumberRef() { 38 var v int64 = 0 39 xCFNumberRef = C.CFNumberCreate(C.kCFAllocatorSystemDefault, C.kCFNumberSInt64Type, unsafe.Pointer(&v)) 40 //fmt.Printf("CFNumberRef: %x\n", uintptr(unsafe.Pointer(xCFNumberRef))) 41} 42 43var xCFNumberRef C.CFNumberRef 44 45func testCFDateRef() { 46 xCFDateRef = C.CFDateCreate(C.kCFAllocatorSystemDefault, 0) // 0 value is 1 Jan 2001 00:00:00 GMT 47 //fmt.Printf("CFDateRef: %x\n", uintptr(unsafe.Pointer(xCFDateRef))) 48} 49 50var xCFDateRef C.CFDateRef 51 52func testCFBooleanRef() { 53 xCFBooleanRef = C.kCFBooleanFalse 54 //fmt.Printf("CFBooleanRef: %x\n", uintptr(unsafe.Pointer(xCFBooleanRef))) 55} 56 57var xCFBooleanRef C.CFBooleanRef 58