summaryrefslogtreecommitdiff
path: root/include/ruby.h
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2025-07-16 17:20:21 +0900
committerYusuke Endoh <mame@ruby-lang.org>2025-07-16 18:31:10 +0900
commit6d17a3e6472b4c6ce81f5308fc07050855114410 (patch)
tree89a656af7eda6b64c301092ef20059197752c10c /include/ruby.h
parent3956308aa420eac3e358be1d35ca7fbc3bf22148 (diff)
Prevent ObjectSpace.count_objects from allocating extra arrays
`ObjectSpace.count_objects` could cause an unintended array allocation. It returns a hash like `{ :T_ARRAY => 100, :T_STRING => 100, ... }`, so it creates the key symbol (e.g., `:T_STRING`) for the first time. On rare occations, this symbol creation internally allocates a new array for symbol management. This led to a problematic side effect where calling `count_objects` twice in a row could produce inconsistent results: the first call would trigger the hidden array allocation, and the second call would then report an increased count for `:T_ARRAY`. This behavior caused test failures in `test/ruby/test_allocation.rb`, which performs a baseline measurement before an operation and then asserts the exact number of new allocations. https://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20250716T053005Z.fail.html.gz > 1) Failure: > TestAllocation::ProcCall::WithBlock#test_ruby2_keywords [...]: > Expected 1 array allocations for "r2k.(1, a: 2, &block)", but 2 arrays allocated. This change resolves the issue by pre-interning all key symbols used by `ObjectSpace.count_objects` before its counting. This eliminates the side effect and ensures the stability of allocation-sensitive tests. Co-authored-by: Koichi Sasada <ko1@atdot.net>
Diffstat (limited to 'include/ruby.h')
0 files changed, 0 insertions, 0 deletions