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/fix: incomplete "go tool fix -r cftype" suggestions #23091
Comments
CC @randall77 |
Am not sure if this will be for Go1.10. Perhaps let's punt to Go1.11? |
ping @randall77 |
(I responded to this yesterday! Somehow it didn't stick.) There seem to be 3 different issues here.
It doesn't know to rewrite the
It used to be that
I definitely want to handle 1 and 3. 2 is more questionable, as it involves a more complicated rewrite. |
Actually, number 1 is because cgo isn't run before typechecking, so we don't have the types of the C. functions at all. |
So it looks like there are a lot of types that are upcastable to a |
Change https://golang.org/cl/87615 mentions this issue: |
Change https://golang.org/cl/87616 mentions this issue: |
Cgo currently maps CFTypeRef and its subtypes to unsafe.Pointer or a pointer to a named empty struct. However, Darwin sometimes encodes some of CFTypeRef's subtypes as a few int fields packed in a pointer wrapper. This hackery confuses the Go runtime as the pointers can look like they point to things that shouldn't be pointed at. Switch CFTypeRef and its subtypes to map to uintptr. Detecting the affected set of types is tricky, there are over 200 of them, and the set isn't static across Darwin versions. Fortunately, downcasting from CFTypeRef to a subtype requires calling CFGetTypeID, getting a CFTypeID token, and comparing that with a known id from a *GetTypeID() call. So we can find all the type names by detecting all the *GetTypeID() prototypes and rewriting the corresponding *Ref types to uintptr. This strategy covers all the cases I've checked and is unlikely to have a false positive. Update #23091. Change-Id: I487eb4105c9b4785ba564de9c38d472c8c9a76ac Reviewed-on: https://go-review.googlesource.com/87615 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
If a file uses cgo, incorporate the types generated by running cgo. Update #23091 Change-Id: I10958fa7fd6027c2c96a9fd8a9658de35439719f Reviewed-on: https://go-review.googlesource.com/87616 Reviewed-by: Robert Griesemer <gri@golang.org>
Change https://golang.org/cl/88075 mentions this issue: |
cgo uses the presence of these functions to determine whether a given type is in the CFTypeRef hierarchy and thus should be a uintptr instead of a pointer. But if the *GetTypeID functions aren't used by the user code, then they won't be present in the cgo output, and thus cmd/fix won't see them. Use the simpler rule that anything ending in *Ref should be rewritten. This could over-rewrite, but I don't see a simpler solution. Unlike cgo, it is easy to edit the output to fix any issues. And fix is a much rarer operation than cgo. This is a revert of portions of CL 87616. Update #23091 Change-Id: I74ecd9fb25490a3d279b372e107248452bb62185 Reviewed-on: https://go-review.googlesource.com/88075 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Change https://golang.org/cl/88175 mentions this issue: |
Go 1.10 introduces some changes to cgo, but I ran "go tool fix -r cftype" and still got compilation failures. Is the team still interested in improving the heuristics for "go tool fix"? I'm just an end user of a lot of these libraries, I haven't done that much with cgo and I'm not sure how to fix them.
Running "go tool fix" on this package makes some changes but there are still a number of compilation failures: keybase/go-keychain#19
Also the "remaining change" listed here: golang/text@572a2b1
Feel free to close as "this library needs to do some work, go tool fix is relatively complete."
The text was updated successfully, but these errors were encountered: