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

refactor: replace reflect.StringHeader with unsafe.StringData #1162

Merged
merged 1 commit into from
Oct 4, 2024

Commits on Oct 2, 2024

  1. refactor: replace reflect.StringHeader with unsafe.StringData

    Closes #1147.
    
    The Godoc of `reflect.StringHeader` says [1]:
    
      "the Data field is not sufficient to guarantee the data it references
    will not be garbage collected, so programs must keep a separate,
    correctly typed pointer to the underlying data."
    
    And the Godoc of `unsafe.Pointer` says [2]:
    
      "A uintptr is an integer, not a reference. ... Even if a uintptr holds
    the address of some object, the garbage collector will not update that
    uintptr's value if the object moves, nor will that uintptr keep the
    object from being reclaimed."
    
    The replacement `unsafe.StringData` is a more correct way to get the
    pointer to the string data. The original proposal can be seen in
    golang/go#53003 (comment).
    
    [1]: https://pkg.go.dev/reflect#StringHeader
    [2]: https://pkg.go.dev/unsafe#Pointer
    
    Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
    Juneezee committed Oct 2, 2024
    Configuration menu
    Copy the full SHA
    142970e View commit details
    Browse the repository at this point in the history