Skip to content

Commit 0b61e41

Browse files
etiennebarriebyroot
andcommitted
Compile putchilledstring when frozen_string_literal is undefined
Co-authored-by: Jean Boussier <[email protected]>
1 parent 214acee commit 0b61e41

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

bootstraptest/test_ractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ class C8; def self.foo = 17; end
16621662
Warning[:experimental] = $VERBOSE = true
16631663
STDERR.reopen(STDOUT)
16641664
eval("Ractor.new{}.take", nil, "test_ractor.rb", 1)
1665-
}
1665+
}, frozen_string_literal: false
16661666

16671667
# check moved object
16681668
assert_equal 'ok', %q{

compile.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10355,12 +10355,18 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
1035510355
debugp_param("nd_lit", get_string_value(node));
1035610356
if (!popped) {
1035710357
VALUE lit = get_string_value(node);
10358-
if (!frozen_string_literal_p(iseq)) {
10358+
switch (ISEQ_COMPILE_DATA(iseq)->option->frozen_string_literal) {
10359+
case -1: // unspecified
10360+
lit = rb_fstring(lit);
10361+
ADD_INSN1(ret, node, putchilledstring, lit);
10362+
RB_OBJ_WRITTEN(iseq, Qundef, lit);
10363+
break;
10364+
case 0: // disabled
1035910365
lit = rb_fstring(lit);
1036010366
ADD_INSN1(ret, node, putstring, lit);
1036110367
RB_OBJ_WRITTEN(iseq, Qundef, lit);
10362-
}
10363-
else {
10368+
break;
10369+
case 1: // enabled
1036410370
if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal || RTEST(ruby_debug)) {
1036510371
VALUE debug_info = rb_ary_new_from_args(2, rb_iseq_path(iseq), INT2FIX(line));
1036610372
lit = rb_str_dup(lit);
@@ -10372,6 +10378,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
1037210378
}
1037310379
ADD_INSN1(ret, node, putobject, lit);
1037410380
RB_OBJ_WRITTEN(iseq, Qundef, lit);
10381+
break;
10382+
default:
10383+
rb_bug("invalid frozen_string_literal");
1037510384
}
1037610385
}
1037710386
break;

0 commit comments

Comments
 (0)