issue21897.go 1.4 KB

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