Issue #19315 has been updated by Dan0042 (Daniel DeLorme). I agree that completely deprecating RSTRING_PTR might not be strictly necessary, but for the sake of a smooth migration, I highly recommend introducing RSTRING_CSTR as an alias for the new, NUL-terminated RSTRING_PTR behavior. Introducing this alias provides a clear upgrade path. Maintainers can simply grep through their codebases for RSTRING_PTR and systematically replace it with either RSTRING_START or RSTRING_CSTR. Without RSTRING_CSTR, it becomes much harder to audit existing code, as maintainers will look at an instance of RSTRING_PTR and have to wonder: "Was this intended to rely on the new NUL-terminated behavior, or should I change it to RSTRING_START?" The compatibility issue involving the RSTRING_PTR + RSTRING_END pattern perfectly highlights this advantage. If a developer sees RSTRING_PTR paired with RSTRING_END, they can confidently convert RSTRING_PTR to RSTRING_START to ensure seamless compatibility without any guesswork. ---------------------------------------- Feature #19315: Lazy substrings in CRuby https://bugs.ruby-lang.org/issues/19315#change-117467 * Author: Eregon (Benoit Daloze) * Status: Open ---------------------------------------- CRuby should implement lazy substrings, i.e., "abcdef"[1..3] must not copy bytes. Currently CRuby only reuse the char* if the substring is until the end of the buffer. But it should also work wherever the substring starts and ends. Yes, it means RSTRING_PTR() might need to allocate to \0-terminate, so be it, it's worth it. There is already code for this (`SHARABLE_MIDDLE_SUBSTRING`), but it's disabled by default and `RSTRING_PTR()` needs to be changed to deal with this. It seems a good idea to introduce a variant of `RSTRING_PTR` which doesn't guarantee \0-termination, so such callers can then use the existing bytes always without copy. There are countless workarounds for this missing optimization, all not worth it with lazy substring and all less readable: * https://bugs.ruby-lang.org/issues/19314 * https://bugs.ruby-lang.org/issues/18598#note-3 * https://github.com/ruby/net-protocol/pull/14 * Manual lazy substrings which track string + index + length * More but I don't remember all now, feel free to comment or link more urls/tickets. -- https://bugs.ruby-lang.org/