Skip to content
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

Util: add StringData, String, SliceData(go 1.20) #2472

Open
monkey92t opened this issue Mar 3, 2023 · 1 comment
Open

Util: add StringData, String, SliceData(go 1.20) #2472

monkey92t opened this issue Mar 3, 2023 · 1 comment

Comments

@monkey92t
Copy link
Collaborator

monkey92t commented Mar 3, 2023

See golang/go#53003

As stated in Proposal:

  • converting []byte to string
  • converting string to []byte
  • grabbing the Data pointer field for ffi or some other niche use
  • converting a slice of one type to a slice of another type

The first use case can also commonly be seen as *(*string)(unsafe.Pointer(&mySlice)), which is never actually officially documented anywhere as something that can be relied upon. Under the hood, the shape of a string is less than a slice, so this seems valid per unsafe rule (1), but this is all relying on undocumented behavior. The second use case is commonly seen as ([]byte)(unsafe.Pointer(&string)), which is by-default broken because the Cap field can be past the end of a page boundary (example here, in widely used code) -- this violates unsafe rule (1).

:)

@monkey92t monkey92t changed the title add StringData, String, SliceData(go 1.20) Util: add StringData, String, SliceData(go 1.20) Mar 3, 2023
@SoulPancake
Copy link
Contributor

Will this be done part by part or all at once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants