summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--array.c6
-rw-r--r--insns.def4
-rw-r--r--iseq.c29
-rw-r--r--string.c5
-rw-r--r--vm_core.h3
6 files changed, 43 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d39a9d756..9fffb9e1fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Feb 18 14:33:35 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * array.c (rb_ary_resurrect), string.c (rb_str_resurrect): new
+ functions based on [ruby-dev:37983]
+
+ * insns.def (putstring, duparray): use rb_{ary,str}_resurrect().
+
+ * iseq.c (iseq_data_to_ary): needs to result TS_VALUE.
+
Wed Feb 18 12:35:31 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_s_extname): fix for spaces before extention.
diff --git a/array.c b/array.c
index ca23dd4922..8ec325c0c9 100644
--- a/array.c
+++ b/array.c
@@ -1469,6 +1469,12 @@ rb_ary_dup(VALUE ary)
return dup;
}
+VALUE
+rb_ary_resurrect(VALUE ary)
+{
+ return rb_ary_new4(RARRAY_LEN(ary), RARRAY_PTR(ary));
+}
+
extern VALUE rb_output_fs;
static VALUE
diff --git a/insns.def b/insns.def
index 9a709a5b3e..5534fb2479 100644
--- a/insns.def
+++ b/insns.def
@@ -373,7 +373,7 @@ putstring
()
(VALUE val)
{
- val = rb_str_replace(rb_str_new(0, 0), str);
+ val = rb_str_resurrect(str);
}
/**
@@ -460,7 +460,7 @@ duparray
()
(VALUE val)
{
- val = rb_ary_replace(rb_ary_new2(0), ary);
+ val = rb_ary_resurrect(ary);
}
/**
diff --git a/iseq.c b/iseq.c
index 18494550be..3c2fb7d546 100644
--- a/iseq.c
+++ b/iseq.c
@@ -23,6 +23,22 @@ VALUE rb_cISeq;
#define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass)
+static inline VALUE
+obj_resurrect(VALUE obj)
+{
+ if (hidden_obj_p(obj)) {
+ switch (BUILTIN_TYPE(obj)) {
+ case T_STRING:
+ obj = rb_str_resurrect(obj);
+ break;
+ case T_ARRAY:
+ obj = rb_ary_resurrect(obj);
+ break;
+ }
+ }
+ return obj;
+}
+
static void
compile_data_free(struct iseq_compile_data *compile_data)
{
@@ -701,16 +717,7 @@ insn_operand_intern(rb_iseq_t *iseq,
op = ID2SYM(op);
case TS_VALUE: /* VALUE */
- if (hidden_obj_p(op)) {
- switch (BUILTIN_TYPE(op)) {
- case T_STRING:
- op = rb_str_replace(rb_str_new(0, 0), op);
- break;
- case T_ARRAY:
- op = rb_ary_replace(rb_ary_new2(0), op);
- break;
- }
- }
+ op = obj_resurrect(op);
ret = rb_inspect(op);
if (CLASS_OF(op) == rb_cISeq) {
rb_ary_push(child, op);
@@ -1141,7 +1148,7 @@ iseq_data_to_ary(rb_iseq_t *iseq)
rb_ary_push(ary, INT2FIX(*seq));
break;
case TS_VALUE:
- rb_ary_push(ary, *seq);
+ rb_ary_push(ary, obj_resurrect(*seq));
break;
case TS_ISEQ:
{
diff --git a/string.c b/string.c
index 5004727b3d..da36213f7c 100644
--- a/string.c
+++ b/string.c
@@ -828,6 +828,11 @@ rb_str_dup(VALUE str)
return str_duplicate(rb_obj_class(str), str);
}
+VALUE
+rb_str_resurrect(VALUE str)
+{
+ return rb_str_replace(str_alloc(rb_cString), str);
+}
/*
* call-seq:
diff --git a/vm_core.h b/vm_core.h
index dd5f3400db..511c1e3198 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -599,6 +599,9 @@ NOINLINE(void rb_gc_save_machine_context(rb_thread_t *));
#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
+VALUE rb_str_resurrect(VALUE str);
+VALUE rb_ary_resurrect(VALUE ary);
+
/* for thread */
#if RUBY_VM_THREAD_MODEL == 2