[#116016] [Ruby master Bug#20150] Memory leak in grapheme clusters — "peterzhu2118 (Peter Zhu) via ruby-core" <ruby-core@...>
Issue #20150 has been reported by peterzhu2118 (Peter Zhu).
7 messages
2024/01/04
[#116382] [Ruby master Feature#20205] Enable `frozen_string_literal` by default — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #20205 has been reported by byroot (Jean Boussier).
77 messages
2024/01/23
[ruby-core:116185] [Ruby master Bug#19975] ISeq#to_binary loses hidden local variable indices
From:
"jeremyevans0 (Jeremy Evans) via ruby-core" <ruby-core@...>
Date:
2024-01-12 19:27:24 UTC
List:
ruby-core #116185
Issue #19975 has been updated by jeremyevans0 (Jeremy Evans).
I submitted a pull request to fix this: https://github.com/ruby/ruby/pull/9512
----------------------------------------
Bug #19975: ISeq#to_binary loses hidden local variable indices
https://bugs.ruby-lang.org/issues/19975#change-106199
* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
When you call `RubyVM::InstructionSequence#to_a`, you get hidden local variables as the index in the stack from the top:
``` c
if (rb_id2str(lid)) {
rb_ary_push(locals, ID2SYM(lid));
}
else { /* hidden variable from id_internal() */
rb_ary_push(locals, ULONG2NUM(iseq_body->local_table_size-i+1));
}
```
``` rb
RubyVM::InstructionSequence.compile("for foo in bar; end").to_a[13][4][2][10]
# => [2]
```
When you call `RubyVM::InstructionSequence#to_binary`, it dumps hidden local variables as 0:
``` c
if (id == 0 || rb_id2name(id) == NULL) {
return 0;
}
return ibf_dump_object(dump, rb_id2sym(id));
```
When it reads that back in and then you call `to_a`, you get `:#arg_rest`:
``` ruby
RubyVM::InstructionSequence.load_from_binary(RubyVM::InstructionSequence.compile("for foo in bar; end").to_binary).to_a[13][4][2][10]
# => [:"#arg_rest"]
```
This means you end up not being able to consistently look at the locals. Instead, when reading back in from binary it could replace it with the index so that it matches up with the value before it is dumped to binary. Could we do that so that `#to_a` is consistent no matter where the iseq came from?
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/