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 (patch) | |
tree | c0e89d90d7ad34e7aa833a800227724f62c0930a /compile.c | |
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
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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 */ + if (!iseq->compile_data->option->frozen_string_literal) { + ADD_INSN1(ret, line, putstring, node->nd_lit); } else { - ADD_INSN1(ret, line, putstring, node->nd_lit); + if (!iseq->compile_data->option->frozen_string_literal_debug) { + ADD_INSN1(ret, line, putobject, node->nd_lit); /* already frozen */ + } + else { + VALUE str = rb_str_dup(node->nd_lit); + rb_iv_set(str, "__object_created_path__", iseq->body->location.path); + rb_iv_set(str, "__object_created_line__", INT2FIX(line)); + ADD_INSN1(ret, line, putobject, rb_obj_freeze(str)); + } } } break; |