Promote Ripper DSL array elements to VALUE

Ensure arguments passed through `rb_ary_new_from_args` have type
`VALUE`, including when the statement-expression optimization is
unavailable.  This avoids undefined behavior in variadic calls.
This commit is contained in:
Nobuyoshi Nakada 2026-07-21 13:35:05 +09:00
parent 40f105bd55
commit fda83cd2d6
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2026-07-21 07:29:29 +00:00
2 changed files with 11 additions and 1 deletions

View File

@ -37,7 +37,8 @@ class DSL
if empty?
"rb_ary_new()"
else
"rb_ary_new_from_args(#{size}, #{map(&:to_s).join(', ')})"
values = map {|value| "(VALUE)0|(#{value})"}
"rb_ary_new_from_args(#{size}, #{values.join(', ')})"
end
end
end

View File

@ -225,3 +225,12 @@ end
Ripper::Lexer::State.new(Ripper.const_get(name))
end
end if ripper_test
class TestRipper::DSL < Test::Unit::TestCase
def test_array_elements_are_values
require_relative "../../ext/ripper/tools/dsl"
code = DSL.line?("/*% ripper: [$:$, 0] %*/").generate
assert_include(code, "rb_ary_new_from_args(2, (VALUE)0|(p->s_lvalue), (VALUE)0|(0))")
end
end if ripper_test