diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2026-02-02 22:06:44 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-02-03 07:24:29 +0000 |
| commit | 066332465b927cf2d2b05d0d77014d7e3f48d933 (patch) | |
| tree | 4c3cc671b497ab5e5d55898a3102c7a4073320ed /test/ruby/box/string_ext.rb | |
| parent | e1655dad3a00a7b4026c653ff7c611811e7e34da (diff) | |
[ruby/json] Ensure `Generator::State` is kept on the stack
Fix: https://github.com/ruby/json/issues/929
When calling `cState_partial_generate` from `mHash_to_json` or other
`to_json` funcs, `VState` becomes unreachable very quickly, hence the
compiler may optimize it out of the stack, and make it invisible to
the GC stack scanning. This is particularly liekly given how aggressively
we inline.
Repro:
```ruby
require 'json'
test_data = {
"flag" => true,
"data" => 10000.times.map { [1.0] },
:flag => false,
}
10.times do
test_data.to_json
end
```
But in practice the cause was just that the issued warning calls
Hash#inspect on a big hash, which triggers GC.
So it can be triggered even more reliably with:
```ruby
require 'json'
module JSON
module Common
def self.on_mixed_keys_hash(...)
GC.start
end
end
end
test_data = {
"flag" => true,
"data" => 10000.times.map { [1.0] },
:flag => false,
}
test_data.to_json
```
https://github.com/ruby/json/commit/79b6e168ba
Diffstat (limited to 'test/ruby/box/string_ext.rb')
0 files changed, 0 insertions, 0 deletions
