mirror of
https://github.com/ruby/ruby.git
synced 2026-08-08 15:08:11 +08:00
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:
parent
40f105bd55
commit
fda83cd2d6
Notes:
git
2026-07-21 07:29:29 +00:00
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user