-
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
proposal: spec: disallow T<->uintptr conversion for type T unsafe.Pointer #20171
Comments
Per #18130 (comment), I believe that it would be difficult to eliminate the possibility that packages that do not explicitly import It may be more viable to disallow all conversions from package unsafe
type Pointer
func Convert(Pointer) *T Then |
@bcmills I don't think we make this bullet-proof - but at least I want it to be water-proof. But I agree that if we reconsider the unsafe package interface entirely, we may find better solutions. Even with your suggestion, it's possible to encapsulate the desired conversions in functions exported by a package that's not the unsafe package. A client would only need to import that package. |
Note that now that we have type aliases, we'd also have to disallow conversions involving T where
as well. And that's a bit harder to defend. |
@rsc An alternative (for Go 2) is to rethink how unsafe operations work. For instance, we could remove the Pointer type altogether and make all unsafe operations function-based. |
Indeed. That would fit with #19367. |
Currently, implementations permit conversions to/from
unsafe.Pointer
and to/from types with underlying typeunsafe.Pointer
.Consequently, unsafe conversions can be hidden because package unsafe doesn't even have to be imported.
This was arguably an "implementation mistake" which we should fix. See also #19306.
The text was updated successfully, but these errors were encountered: