ruby-changes:18897
From: nobu <ko1@a...>
Date: Sun, 20 Feb 2011 16:24:03 +0900 (JST)
Subject: [ruby-changes:18897] Ruby:r30922 (trunk): * prevent temporary objects from GC, and should not use
nobu 2011-02-20 16:23:55 +0900 (Sun, 20 Feb 2011) New Revision: 30922 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30922 Log: * prevent temporary objects from GC, and should not use RSTRING_PTR() for function calls since it evaluates the argument a couple of times. Modified files: trunk/ChangeLog trunk/compile.c trunk/error.c trunk/io.c trunk/variable.c trunk/vm.c trunk/vm_eval.c trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 30921) +++ ChangeLog (revision 30922) @@ -1,3 +1,9 @@ +Sun Feb 20 16:23:52 2011 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * file.c (rb_file_flock): use rb_thread_io_blocking_region for the Index: variable.c =================================================================== --- variable.c (revision 30921) +++ variable.c (revision 30922) @@ -312,7 +312,8 @@ 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 * Index: io.c =================================================================== --- io.c (revision 30921) +++ io.c (revision 30922) @@ -7498,8 +7498,9 @@ 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)); } } Index: compile.c =================================================================== --- compile.c (revision 30921) +++ compile.c (revision 30922) @@ -5211,7 +5211,7 @@ 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; } Index: vm_eval.c =================================================================== --- vm_eval.c (revision 30921) +++ vm_eval.c (revision 30922) @@ -1015,7 +1015,8 @@ 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 */ Index: error.c =================================================================== --- error.c (revision 30921) +++ error.c (revision 30922) @@ -356,7 +356,8 @@ 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); Index: vm.c =================================================================== --- vm.c (revision 30921) +++ vm.c (revision 30922) @@ -1446,7 +1446,7 @@ } 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)); } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 30921) +++ vm_insnhelper.c (revision 30922) @@ -1143,7 +1143,7 @@ default: str = rb_inspect(klass); rb_raise(rb_eTypeError, "%s is not a class/module", - RSTRING_PTR(RB_GC_GUARD(str))); + StringValuePtr(str)); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/