bytecodealliance / bytecodealliance/wasmtime-rb
`UnsafeSlice.to_str` frozen string pitfalls
Open
- Dominant language
- Rust
- Stars
- 146
- Forks
- 28
- Avg merge
- 7h 52m
- Merged PRs (30d)
- 9
Description
Now, it's quite obvious that `UnsafeSlice` is... unsafe, but to help the next surprised poor soul I suggest you add something like the following to the documentation of `UnsafeSlice.to_str`:
> The returned string is frozen, which means that any slices, slices of slices, and even the result of `.dup`, `.clone`, `String.new(str)` (of the whole string or any slices) will still reference the underlying memory. To make a true copy that won't keep a reference:
> ```ruby
> String.new(capacity: str.bytesize).concat(str)
> ```
> To copy a slice:
>
> ```ruby
> IO::Buffer.for(str).get_string(ofs, len)
> ```
Contributor guide
Assessment
This issue has not been assessed yet.