diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-23 19:02:55 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-23 19:02:55 +0000 |
commit | 54716fe7ebbf20b5e91fdbe9b65e0bedb0c4836a () | |
tree | c0e89d90d7ad34e7aa833a800227724f62c0930a | |
parent | 31f21aed2cee297a1fc316d60744697580446608 (diff) |
* ruby.c: introduce --enable-frozen-string-literal-debug option.
If this option is enabled, the modify error will be: can't modify frozen String (RuntimeError) => can't modify frozen String, created at test.rb:3 (RuntimeError) * iseq.h: add compile option frozen_string_literal_debug. * compile.c: catch up this fix. * error.c (rb_error_frozen): ditto. * iseq.c (set_compile_option_from_hash): ditto. * test/ruby/test_rubyoptions.rb: add a test for this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52257 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | compile.c | 14 | ||||
-rw-r--r-- | error.c | 12 | ||||
-rw-r--r-- | iseq.c | 1 | ||||
-rw-r--r-- | iseq.h | 1 | ||||
-rw-r--r-- | ruby.c | 9 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 11 |
7 files changed, 60 insertions, 5 deletions
@@ -1,3 +1,20 @@ Sat Oct 24 02:02:24 2015 Koichi Sasada <[email protected]> * vm_insnhelper.c: introduce new call handler for simple ISeqs. @@ -5107,11 +5107,19 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) debugp_param("nd_lit", node->nd_lit); if (!poped) { node->nd_lit = rb_fstring(node->nd_lit); - if (iseq->compile_data->option->frozen_string_literal) { - ADD_INSN1(ret, line, putobject, node->nd_lit); /* already frozen */ } else { - ADD_INSN1(ret, line, putstring, node->nd_lit); } } break; @@ -2226,8 +2226,16 @@ rb_error_frozen(const char *what) void rb_error_frozen_object(VALUE frozen_obj) { - rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE, - CLASS_OF(frozen_obj)); } #undef rb_check_frozen @@ -366,6 +366,7 @@ set_compile_option_from_hash(rb_compile_option_t *option, VALUE opt) SET_COMPILE_OPTION(option, opt, stack_caching); SET_COMPILE_OPTION(option, opt, trace_instruction); SET_COMPILE_OPTION(option, opt, frozen_string_literal); SET_COMPILE_OPTION_NUM(option, opt, debug_level); #undef SET_COMPILE_OPTION #undef SET_COMPILE_OPTION_NUM @@ -67,6 +67,7 @@ struct rb_compile_option_struct { int stack_caching; int trace_instruction; int frozen_string_literal; int debug_level; }; @@ -69,6 +69,7 @@ enum feature_flag_bits { feature_did_you_mean, feature_rubyopt, feature_frozen_string_literal, feature_flag_count }; @@ -126,6 +127,7 @@ cmdline_options_init(struct cmdline_options *opt) opt->features &= ~FEATURE_BIT(gems); #endif opt->features &= ~FEATURE_BIT(frozen_string_literal); return opt; } @@ -739,6 +741,7 @@ enable_option(const char *str, int len, void *arg) SET_WHEN_ENABLE(did_you_mean); SET_WHEN_ENABLE(rubyopt); SET_WHEN_ENABLE(frozen_string_literal); if (NAME_MATCH_P("all", str, len)) { *(unsigned int *)arg = ~0U; return; @@ -754,6 +757,7 @@ disable_option(const char *str, int len, void *arg) UNSET_WHEN_DISABLE(did_you_mean); UNSET_WHEN_DISABLE(rubyopt); UNSET_WHEN_DISABLE(frozen_string_literal); if (NAME_MATCH_P("all", str, len)) { *(unsigned int *)arg = 0U; return; @@ -1474,6 +1478,11 @@ process_options(int argc, char **argv, struct cmdline_options *opt) rb_hash_aset(option, ID2SYM(rb_intern_const("frozen_string_literal")), Qtrue); rb_funcallv(rb_cISeq, rb_intern_const("compile_option="), 1, &option); } #if UTF8_PATH opt->script_name = str_conv_enc(opt->script_name, rb_utf8_encoding(), lenc); opt->script = RSTRING_PTR(opt->script_name); @@ -804,4 +804,15 @@ class TestRubyOptions < Test::Unit::TestCase end end end end |