From e7c0a6e1d745935460a226cd5f29e2f0faff5417 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 20 Feb 2011 07:23:55 +0000 Subject: * prevent temporary objects from GC, and should not use RSTRING_PTR() for function calls since it evaluates the argument a couple of times. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ compile.c | 2 +- error.c | 3 ++- io.c | 5 +++-- variable.c | 3 ++- vm.c | 2 +- vm_eval.c | 3 ++- vm_insnhelper.c | 2 +- 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 + + * 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 * 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)); } } -- cgit v1.2.3