ruby-changes:30342
From: shugo <ko1@a...>
Date: Tue, 6 Aug 2013 16:15:31 +0900 (JST)
Subject: [ruby-changes:30342] shugo:r42396 (trunk): * vm_eval.c (eval_string_with_cref): copy cref to limit the scope of
shugo 2013-08-06 16:15:18 +0900 (Tue, 06 Aug 2013) New Revision: 42396 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42396 Log: * vm_eval.c (eval_string_with_cref): copy cref to limit the scope of refienements in the eval string. [ruby-core:56329] [Bug #8722] * test/ruby/test_refinement.rb: related test. Modified files: trunk/ChangeLog trunk/test/ruby/test_refinement.rb trunk/vm_eval.c _______________________________________________ ruby-cvs mailing list ruby-cvs@r... http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-cvs Index: ChangeLog =================================================================== --- ChangeLog (revision 42395) +++ ChangeLog (revision 42396) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Aug 6 16:14:32 2013 Shugo Maeda <shugo@r...> + + * vm_eval.c (eval_string_with_cref): copy cref to limit the scope of + refienements in the eval string. [ruby-core:56329] [Bug #8722] + + * test/ruby/test_refinement.rb: related test. + Tue Aug 6 12:23:12 2013 Tanaka Akira <akr@f...> * bignum.c (rb_big_realloc): Use VALGRIND_MAKE_MEM_UNDEFINED to Index: vm_eval.c =================================================================== --- vm_eval.c (revision 42395) +++ vm_eval.c (revision 42396) @@ -1186,6 +1186,8 @@ eval_string_with_cref(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1186 rb_block_t block, *base_block; volatile int parse_in_eval; volatile int mild_compile_error; + NODE *orig_cref; + VALUE crefval; if (file == 0) { file = rb_sourcefilename(); @@ -1243,7 +1245,14 @@ eval_string_with_cref(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1245 th->mild_compile_error--; th->parse_in_eval--; + if (!cref && base_block->iseq) { + orig_cref = rb_vm_get_cref(base_block->iseq, base_block->ep); + cref = NEW_CREF(Qnil); + crefval = (VALUE) cref; + COPY_CREF(cref, orig_cref); + } vm_set_eval_stack(th, iseqval, cref, base_block); + RB_GC_GUARD(crefval); if (0) { /* for debug */ VALUE disasm = rb_iseq_disasm(iseqval); Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 42395) +++ test/ruby/test_refinement.rb (revision 42396) @@ -929,6 +929,38 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L929 assert_equal("FooExt2#y Foo#y", FooFoo2ExtClient.invoke_y_on(foo)) end + def test_eval_scoping + assert_in_out_err([], <<-INPUT, ["HELLO WORLD", "dlrow olleh", "HELLO WORLD"], []) + module M + refine String do + def upcase + reverse + end + end + end + + puts "hello world".upcase + puts eval(%{using M; "hello world".upcase}) + puts "hello world".upcase + INPUT + end + + def test_eval_with_binding_scoping + assert_in_out_err([], <<-INPUT, ["HELLO WORLD", "dlrow olleh", "HELLO WORLD"], []) + module M + refine String do + def upcase + reverse + end + end + end + + puts "hello world".upcase + puts eval(%{using M; "hello world".upcase}, TOPLEVEL_BINDING) + puts eval(%{"hello world".upcase}, TOPLEVEL_BINDING) + INPUT + end + private def eval_using(mod, s) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/