[ruby-core:126211] [Ruby Feature#22222] Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary`
Issue #22222 has been reported by byroot (Jean Boussier). ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by nobu (Nobuyoshi Nakada). `rb_str_new_static` does not `memcpy` (of course you have the responsibility to keep the `String`). ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118293 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by byroot (Jean Boussier). @nobu yes I know, but as you mention, it's meant to point at static C strings, not mmaped files or stack buffers, so it doesn't work for Bootsnap. ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118294 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by nobu (Nobuyoshi Nakada). The only requirements for `rb_str_new_static` are that the caller is responsible for freeing the allocated memory, and that the memory is not freed while the object is still in existence. You can think of it as requiring the same level of care as when passing a buffer to a system call. The term “static” essentially means that the memory is stable from the perspective of this function. ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118297 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` Pull request: https://github.com/ruby/ruby/pull/18136 -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by byroot (Jean Boussier). Yes, I get that, but my point is that these constraints are very hard to ensure in my case. ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118298 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` Pull request: https://github.com/ruby/ruby/pull/18136 -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by Eregon (Benoit Daloze). I guess one concrete issue here with using `rb_str_new_static()` is the mmaped file/stack buffer will be freed soon after the `RubyVM::InstructionSequence.load_from_binary(String)` call, but that String object might live longer, there is no "GC this object now" (AFAIK). And potentially something could get that String via `ObjectSpace.each_object`, and then it'd segfault if the underlying buffer has been freed. ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118299 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` Pull request: https://github.com/ruby/ruby/pull/18136 -- https://bugs.ruby-lang.org/
Issue #22222 has been updated by matz (Yukihiro Matsumoto). Accepted. This exposes no new capability, only a way to avoid a copy for something already possible from Ruby. Matz. ---------------------------------------- Feature #22222: Expose a C API equivalent of `RubyVM::InstructionSequence.load_from_binary` https://bugs.ruby-lang.org/issues/22222#change-118393 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- Currently the only API to deserialize instruction sequence is `RubyVM::InstructionSequence.load_from_binary(String)`. It works fine, but isn't ideal for gems like bootsnap, as it needs to allocate a fairly large string and `memcpy` into it. I would like to be able to directly pass a `char *ptr` and `size_t len` pair, so that I can directly pass a internal buffer or even mmapped file. Proposed API: ``` VALUE rb_iseq_load_from_binary(const char *ptr, size_t len) ``` Pull request: https://github.com/ruby/ruby/pull/18136 -- https://bugs.ruby-lang.org/
participants (4)
-
byroot (Jean Boussier) -
Eregon (Benoit Daloze) -
matz (Yukihiro Matsumoto) -
nobu (Nobuyoshi Nakada)