-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: type confusion between CGO and CoreFoundation types on Go1.10 #24161
Comments
Did you read https://golang.org/doc/go1.10#cgo ? Starting at " |
Yes, that's not the problem here. The problem is that a variable ostensibly of type In fact, merely mentioning the |
Question: is there an |
@randall77 yes, both |
This one is tricky.
But more generally, introducing
Whereas when cgo processes file1.go, we get
It happens to build successfully like that, but it sounds dangerous in general. We could somehow re-run the part that asks |
Sorry to pile on here, but I noticed some additional weird behavior. The typedef CFStringRef SecKeyAlgorithm CF_STRING_ENUM Variables of this type can be passed to C functions without an issue. When you start using Here is a contrived example that doesn't really do anything.
|
@gopherbot please file this for backport against 1.10. This is a regression. |
Backport issue(s) opened: #25036 (for 1.10). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/122575 mentions this issue: |
Change https://golang.org/cl/123177 mentions this issue: |
@gopherbot open some more backport issues please. |
Change https://golang.org/cl/123715 mentions this issue: |
The test uses functions from C that were introduced in OSX 1.12. Include stubs for those functions when compiling for 1.11 and earlier. This test really a compile-time test, it doesn't matter much what the executed code actually does. Use a nasty #define hack to work around the fact that cgo doesn't support static global variables. Update #24161 Fixes #26355 Change-Id: Icf6f7bc9b6b36cacc81d5d0e033a2ebaff7e0298 Reviewed-on: https://go-review.googlesource.com/123715 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Change https://golang.org/cl/123959 mentions this issue: |
The test in CL 123715 doesn't work on iOS, it needs to use a different version scheme to determine whether SecKeyAlgorithm and friends exist. Restrict the old version test to OSX only. The same problem occurs on iOS: the functions tested don't exist before iOS 10. But we don't have builders below iOS 10, so it isn't a big issue. If we ever get older builders, or someone wants to run all.bash on an old iOS, they'll need to figure out the right incantation. Update #24161 Update #26355 Change-Id: Ia3ace86b00486dc172ed00c0c6d668a95565bff7 Reviewed-on: https://go-review.googlesource.com/123959 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
Change https://golang.org/cl/124075 mentions this issue: |
TARGET_OS_OSX is the right macro, but it also was only introduced in 1.12. For 1.11 and earlier a reasonable substitution is TARGET_OS_IPHONE == 0. Update #24161 Update #26355 Change-Id: I5f43c463d14fada9ed1d83cc684c7ea05d94c5f3 Reviewed-on: https://go-review.googlesource.com/124075 Run-TryBot: Keith Randall <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
@randall77 it seems like the fix for this issue introduced a regression, so beware when backporting this for 1.10.4: #26517 |
Go 1.11 breaks the workaround for the behavior I described above. Here is the output from compiling the example workaround:
I don't think it will be possible to fix this in a way that works with 1.9, 1.10, and 1.11 without writing version-specific code and using build tags. |
I guess its not quite so dire. The only versions that would require special casing would be 1.10.0→1.10.3. I hadn't realized that there had been a patch release changing the behavior (1.10.4). |
fixes #40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks #34 which resolves int overflow #31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
fixes #40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks #34 which resolves int overflow #31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
fixes fsnotify#40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks fsnotify#34 which resolves int overflow fsnotify#31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
fixes fsnotify#40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks fsnotify#34 which resolves int overflow fsnotify#31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
fixes fsnotify#40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks fsnotify#34 which resolves int overflow fsnotify#31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
github.com/pchain/vendor/github.com/rjeczalik/notifyvendor/github.com/rjeczalik/notify/watcher_fsevents_cgo.go:51:216: cannot use nil as type _Ctype_CFAllocatorRef in argument to func literal |
@lzhaoGitHub This issue is closed. If you are having a problem, please open a new issue with full details, including filling out the issue template. Thanks. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.10
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
The following file should compile:
returnsCFArrayRef
is a function in another file in the same package that looks likeA full example is on https://gist.github.com/akalin-keybase/6d075a61e683a4b2e2424638308e95c5 .
What did you see instead?
Compilation succeeds with go 1.9.2.
This is likely related to the go 1.10 changes that made some C types map to
uintptr
.The text was updated successfully, but these errors were encountered: