Skip to content

Commit acb19e8

Browse files
committed
merge revision(s) ff222ac: [Backport #21370]
compile.c: Handle anonymous variables in `outer_variable_cmp` [Bug #21370]
1 parent cdb039d commit acb19e8

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compile.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13234,6 +13234,13 @@ outer_variable_cmp(const void *a, const void *b, void *arg)
1323413234
{
1323513235
const struct outer_variable_pair *ap = (const struct outer_variable_pair *)a;
1323613236
const struct outer_variable_pair *bp = (const struct outer_variable_pair *)b;
13237+
13238+
if (!ap->name) {
13239+
return -1;
13240+
} else if (!bp->name) {
13241+
return 1;
13242+
}
13243+
1323713244
return rb_str_cmp(ap->name, bp->name);
1323813245
}
1323913246

test/ruby/test_iseq.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,25 @@ def test_unreachable_next_in_block
855855
end
856856
end
857857

858+
def test_serialize_anonymous_outer_variables
859+
iseq = RubyVM::InstructionSequence.compile(<<~'RUBY')
860+
obj = Object.new
861+
def obj.test
862+
[1].each do
863+
raise "Oops"
864+
rescue
865+
return it
866+
end
867+
end
868+
obj
869+
RUBY
870+
871+
binary = iseq.to_binary # [Bug # 21370]
872+
roundtripped_iseq = RubyVM::InstructionSequence.load_from_binary(binary)
873+
object = roundtripped_iseq.eval
874+
assert_equal 1, object.test
875+
end
876+
858877
def test_loading_kwargs_memory_leak
859878
assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true)
860879
a = RubyVM::InstructionSequence.compile("foo(bar: :baz)").to_binary

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 4
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 37
14+
#define RUBY_PATCHLEVEL 38
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)