File: issue21897.go

package info (click to toggle)
golang-1.11 1.11.6-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, experimental
  • size: 107,332 kB
  • sloc: asm: 88,993; ansic: 8,174; perl: 2,007; sh: 1,804; xml: 623; python: 346; makefile: 123; cpp: 22; f90: 8; awk: 7
file content (65 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// We skip this test in race mode because, for unknown reasons,
// linking against CoreFoundation on macOS 10.10 causes mmap to ignore
// the hint address, which makes the Go allocator incompatible with
// TSAN. See golang.org/issue/26475.
//
// TODO(austin): Once support for macOS 10.10 is dropped, remove the
// race constraint (and the one in issue21897b.go). See
// golang.org/issue/26513.

// +build darwin,cgo,!internal,!race

package cgotest

/*
#cgo LDFLAGS: -framework CoreFoundation
#include <CoreFoundation/CoreFoundation.h>
*/
import "C"
import (
	"runtime/debug"
	"testing"
	"unsafe"
)

func test21897(t *testing.T) {
	// Please write barrier, kick in soon.
	defer debug.SetGCPercent(debug.SetGCPercent(1))

	for i := 0; i < 10000; i++ {
		testCFNumberRef()
		testCFDateRef()
		testCFBooleanRef()
		// Allocate some memory, so eventually the write barrier is enabled
		// and it will see writes of bad pointers in the test* functions below.
		byteSliceSink = make([]byte, 1024)
	}
}

var byteSliceSink []byte

func testCFNumberRef() {
	var v int64 = 0
	xCFNumberRef = C.CFNumberCreate(C.kCFAllocatorSystemDefault, C.kCFNumberSInt64Type, unsafe.Pointer(&v))
	//fmt.Printf("CFNumberRef: %x\n", uintptr(unsafe.Pointer(xCFNumberRef)))
}

var xCFNumberRef C.CFNumberRef

func testCFDateRef() {
	xCFDateRef = C.CFDateCreate(C.kCFAllocatorSystemDefault, 0) // 0 value is 1 Jan 2001 00:00:00 GMT
	//fmt.Printf("CFDateRef: %x\n", uintptr(unsafe.Pointer(xCFDateRef)))
}

var xCFDateRef C.CFDateRef

func testCFBooleanRef() {
	xCFBooleanRef = C.kCFBooleanFalse
	//fmt.Printf("CFBooleanRef: %x\n", uintptr(unsafe.Pointer(xCFBooleanRef)))
}

var xCFBooleanRef C.CFBooleanRef