Skip to content

[Backport #21370] compile.c: Handle anonymous variables in outer_variable_cmp #13945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: ruby_3_4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -13234,6 +13234,13 @@ outer_variable_cmp(const void *a, const void *b, void *arg)
{
const struct outer_variable_pair *ap = (const struct outer_variable_pair *)a;
const struct outer_variable_pair *bp = (const struct outer_variable_pair *)b;

if (!ap->name) {
return -1;
} else if (!bp->name) {
return 1;
}

return rb_str_cmp(ap->name, bp->name);
}

Expand Down
19 changes: 19 additions & 0 deletions test/ruby/test_iseq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,25 @@ def test_unreachable_next_in_block
end
end

def test_serialize_anonymous_outer_variables
iseq = RubyVM::InstructionSequence.compile(<<~'RUBY')
obj = Object.new
def obj.test
[1].each do
raise "Oops"
rescue
return it
end
end
obj
RUBY

binary = iseq.to_binary # [Bug # 21370]
roundtripped_iseq = RubyVM::InstructionSequence.load_from_binary(binary)
object = roundtripped_iseq.eval
assert_equal 1, object.test
end

def test_loading_kwargs_memory_leak
assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true)
a = RubyVM::InstructionSequence.compile("foo(bar: :baz)").to_binary
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy