summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 10:42:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-12 10:42:36 +0000
commite52da919872f8cf71c90a27b470cef724204eece (patch)
tree2d425228fcba503e2f0a82726548f477cefc5da0 /compile.c
parent48149dff328079a25b9f17d47999a513b14389c6 (diff)
* compile.c (compile_array_, defined_expr, iseq_compile_each): hide
and freeze internal literal objects, to prevent from modifying. [ruby-dev:37959] * iseq.c (insn_operand_intern): copy internal literal objects. * insns.def (putstring, duparray): ditto. * string.c (rb_str_replace): exported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 3e1d7fb92d..05572233ad 100644
--- a/compile.c
+++ b/compile.c
@@ -295,6 +295,7 @@ PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
#define INIT_ANCHOR(name) \
(name##_body__.last = &name##_body__.anchor, name = &name##_body__)
+#define hide_obj(obj) (void)(OBJ_FREEZE(obj), RBASIC(obj)->klass = 0)
#include "optinsn.inc"
#if OPT_INSTRUCTIONS_UNIFICATION
@@ -2230,7 +2231,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
if (opt_p == Qtrue) {
if (!poped) {
- VALUE ary = rb_ary_new();
+ VALUE ary = rb_ary_tmp_new(len);
node = node_root;
while (node) {
rb_ary_push(ary, node->nd_head->nd_lit);
@@ -2709,6 +2710,7 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
if (estr != 0) {
if (needstr != Qfalse) {
VALUE str = rb_str_new2(estr);
+ hide_obj(str);
ADD_INSN1(ret, nd_line(node), putstring, str);
iseq_add_mark_object_compile_time(iseq, str);
}
@@ -4353,6 +4355,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
case NODE_STR:{
debugp_param("nd_lit", node->nd_lit);
if (!poped) {
+ hide_obj(node->nd_lit);
ADD_INSN1(ret, nd_line(node), putstring, node->nd_lit);
}
break;