-
Notifications
You must be signed in to change notification settings - Fork 18k
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
reflect: UnsafePointer() map Values cannot be converted back to a map #70595
Comments
Related Issues
Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
reflect.ValueOf(&m).UnsafePointer() Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
I'm aware there's other ways to do this, I'm opening an issue because doing things this way exposes an edge case that produces unusable pointers. |
You can do:
I agree that the interaction of |
Glad you bring that up - the pointer returned by |
I think we would need a very good reason to add anything map-specific to the unsafe package, more than just symmetry or cleanliness. That said, if you want to pursue this, file a proposal issue. See https://go.dev/s/proposal. Thanks. |
Go version
go version go1.22.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Obtained an unsafe.Pointer to a map like this:
What did you see happen?
The above snippet crashes the app, because uPtr is the actual map, not a pointer to it, and there's no other working API that can initialize/associate the Value with the uPtr. (or just cast the unsafe.Pointer into a map)
What did you expect to see?
There should be an operation analogous to Value.UnsafePointer() that can take the pointer and re-create a map out of it. Perhaps unsafe pkg itself should have Map methods similar to unsafe.Slice() + unsafe.SliceData()?
The text was updated successfully, but these errors were encountered: