Thanks for taking this. Matz asked for out-of-range `offset` and `length` to return `nil` rather than raise. Assuming you have no objection to that direction, there are a few points I would like to think through. The first is wheth...himura467 (Akito Shitara)
* [Feature #22056] Zero-Copy String Constructor Backed by Arbitrary Ruby Object (himura467) * A C API creating a String that references memory owned by another Ruby object instead of copying it. * It was blocked on the `RSTRING_PTR()...himura467 (Akito Shitara)
I think one thing here still needs fixing. `IO::Buffer.new(0)` and `IO::Buffer.new(0).slice(0, 0)` are both `{NULL, 0}`, but they do not behave the same. On master (4.1.0dev, 37325e9f7a): ```ruby IO::Buffer.new(0).get_string ...himura467 (Akito Shitara)
Thanks for the review. I filed this because the rdoc for `#free` says that access after free raises, while it does not, so either the implementation or the documentation had to be wrong: * "After the buffer is freed, no further ope...himura467 (Akito Shitara)
For the `IO::Buffer#get_string` use case in the description, I would propose a new method rather than changing `get_string`: ```ruby IO::Buffer#slice_string([offset, [length, [encoding]]]) -> string ``` built on `rb_enc_str_new_e...himura467 (Akito Shitara)
In #note-19 the blocker here was the `RSTRING_PTR()` NUL-termination invariant, to be settled in #19315 first. I have just reported there that `SHARABLE_MIDDLE_SUBSTRING` is neutral on ruby-bench now that [Feature #22186] has landed, so ...himura467 (Akito Shitara)
[Feature #22186] landed as commit:https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/a9017ccc1346f620ff1f1b4340fffdd6b4069f96, so per Matz's request in #22186#note-16 I am revisiting this. ruby-bench with `SHARAB...himura467 (Akito Shitara)
## Reproduction ```ruby buffer = IO::Buffer.new(64) slice = buffer.slice(0, 8) slice.resize(0) slice.size # => an arbitrary size or a SEGV ``` The outcome depends on what the stack happens to hold. Reading `slice.inspect` inst...himura467 (Akito Shitara)
Applied in changeset commit:git|a9017ccc1346f620ff1f1b4340fffdd6b4069f96. ---------- str_subseq: copy sharable substrings up to a 256 byte slot Previously the embedded path allocated a full-size embedded string via str_alloc_heap plus ...himura467 (Akito Shitara)
Previously the embedded path allocated a full-size embedded string via str_alloc_heap plus STR_SET_EMBED, which capped the copy at the default struct RString slot whatever the substring length. Size the allocation to the substring with s...himura467 (Akito Shitara)