Skip to content

Instantly share code, notes, and snippets.

@akalin-keybase
Last active November 15, 2018 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akalin-keybase/6d075a61e683a4b2e2424638308e95c5 to your computer and use it in GitHub Desktop.
Save akalin-keybase/6d075a61e683a4b2e2424638308e95c5 to your computer and use it in GitHub Desktop.
Repro for go 1.10 bug with CoreFoundation types and cgo
// +build darwin
// +build go1.10
package bugrepro
/*
#cgo LDFLAGS: -framework CoreFoundation
#include <CoreFoundation/CoreFoundation.h>
*/
import "C"
// If this function is moved to file2, compilation succeeds.
func returnsCFArrayRef() C.CFArrayRef {
return C.CFArrayRef(0)
}
// +build darwin
// +build !go1.10
package bugrepro
/*
#cgo LDFLAGS: -framework CoreFoundation
#include <CoreFoundation/CoreFoundation.h>
*/
import "C"
// If this function is moved to file2, compilation succeeds.
func returnsCFArrayRef() C.CFArrayRef {
return C.CFArrayRef(nil)
}
// +build darwin
package bugrepro
/*
#cgo LDFLAGS: -framework CoreFoundation -framework IOKit
#include <CoreFoundation/CoreFoundation.h>
*/
import "C"
// If this function is uncommented, compilation succeeds.
/*
func fn1() {
var _ C.CFArrayRef
}
*/
func bugRepro() {
arr := returnsCFArrayRef()
// If arr is replaced with C.CFArrayRef(arr), compilation succeeds.
C.CFArrayCreateCopy(nil, arr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment