summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--compile.c2
-rw-r--r--error.c3
-rw-r--r--io.c5
-rw-r--r--variable.c3
-rw-r--r--vm.c2
-rw-r--r--vm_eval.c3
-rw-r--r--vm_insnhelper.c2
8 files changed, 18 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index b6a082a31f..0ca3bd3609 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Feb 20 16:23:52 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * prevent temporary objects from GC, and should not use
+ RSTRING_PTR() for function calls since it evaluates the argument
+ a couple of times.
+
Sun Feb 20 16:22:53 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_flock): use rb_thread_io_blocking_region for the
diff --git a/compile.c b/compile.c
index c5364ca0b2..10d63bcd1f 100644
--- a/compile.c
+++ b/compile.c
@@ -5211,7 +5211,7 @@ get_exception_sym2type(VALUE sym)
if (sym == symNext) return CATCH_TYPE_NEXT;
sym_inspect = rb_inspect(sym);
rb_raise(rb_eSyntaxError, "invalid exception symbol: %s",
- RSTRING_PTR(RB_GC_GUARD(sym_inspect)));
+ StringValuePtr(sym_inspect));
return 0;
}
diff --git a/error.c b/error.c
index ca563722ba..b89818337e 100644
--- a/error.c
+++ b/error.c
@@ -356,7 +356,8 @@ rb_check_type(VALUE x, int t)
etype = "Symbol";
}
else if (rb_special_const_p(x)) {
- etype = RSTRING_PTR(rb_obj_as_string(x));
+ x = rb_obj_as_string(x);
+ etype = StringValuePtr(x);
}
else {
etype = rb_obj_classname(x);
diff --git a/io.c b/io.c
index 33c97a68d3..82b8469d40 100644
--- a/io.c
+++ b/io.c
@@ -7498,8 +7498,9 @@ advice_arg_check(VALUE advice)
advice != sym_willneed &&
advice != sym_dontneed &&
advice != sym_noreuse) {
- rb_raise(rb_eNotImpError, "Unsupported advice: :%s",
- RSTRING_PTR(rb_id2str(SYM2ID(advice))));
+ VALUE symname = rb_inspect(advice);
+ rb_raise(rb_eNotImpError, "Unsupported advice: %s",
+ StringValuePtr(symname));
}
}
diff --git a/variable.c b/variable.c
index cd3318616e..505758c0c0 100644
--- a/variable.c
+++ b/variable.c
@@ -312,7 +312,8 @@ rb_class_name(VALUE klass)
const char *
rb_class2name(VALUE klass)
{
- return RSTRING_PTR(rb_class_name(klass));
+ VALUE name = rb_class_name(klass);
+ return RSTRING_PTR(name);
}
const char *
diff --git a/vm.c b/vm.c
index 571942565f..5db91dd6ae 100644
--- a/vm.c
+++ b/vm.c
@@ -1446,7 +1446,7 @@ rb_thread_current_status(const rb_thread_t *th)
}
else if (cfp->me->def->original_id) {
str = rb_sprintf("`%s#%s' (cfunc)",
- RSTRING_PTR(rb_class_name(cfp->me->klass)),
+ rb_class2name(cfp->me->klass),
rb_id2name(cfp->me->def->original_id));
}
diff --git a/vm_eval.c b/vm_eval.c
index 0dcbafad21..ce7057476c 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1015,7 +1015,8 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
th->base_block = 0;
if (0) { /* for debug */
- printf("%s\n", RSTRING_PTR(rb_iseq_disasm(iseqval)));
+ VALUE disasm = rb_iseq_disasm(iseqval);
+ printf("%s\n", StringValuePtr(disasm));
}
/* save new env */
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 139a2a24ab..3666aed53e 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1143,7 +1143,7 @@ vm_check_if_namespace(VALUE klass)
default:
str = rb_inspect(klass);
rb_raise(rb_eTypeError, "%s is not a class/module",
- RSTRING_PTR(RB_GC_GUARD(str)));
+ StringValuePtr(str));
}
}