From d928280cb6644d2d899aadf7bfc8cf4e1b5e2997 Mon Sep 17 00:00:00 2001 From: shugo Date: Sat, 8 Dec 2012 03:06:13 +0000 Subject: * eval.c (rb_mod_refine): raise an ArgumentError if a given block is of a Proc object. * vm_insnhelper.c (vm_call_method): store refined methods in inline cache to improve performance. It's safe now because blocks cannot be yielded with different refinements in the new specification. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ eval.c | 8 +++++++- test/ruby/test_refinement.rb | 8 ++++++++ vm_insnhelper.c | 2 -- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79d90b640d..198d9a131a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Dec 8 11:59:59 2012 Shugo Maeda + + * eval.c (rb_mod_refine): raise an ArgumentError if a given + block is of a Proc object. + + * vm_insnhelper.c (vm_call_method): store refined methods in inline + cache to improve performance. It's safe now because blocks cannot + be yielded with different refinements in the new specification. + Sat Dec 8 11:17:53 2012 Shugo Maeda * eval.c (rb_mod_refine), vm_eval.c (rb_yield_refine_block): diff --git a/eval.c b/eval.c index e7da8a63e2..934037da91 100644 --- a/eval.c +++ b/eval.c @@ -1196,10 +1196,16 @@ rb_mod_refine(VALUE module, VALUE klass) ID id_refinements, id_activated_refinements, id_refined_class, id_defined_at; VALUE refinements, activated_refinements; + rb_thread_t *th = GET_THREAD(); + rb_block_t *block = rb_vm_control_frame_block_ptr(th->cfp); - if (!rb_block_given_p()) { + if (!block) { rb_raise(rb_eArgError, "no block given"); } + if (block->proc) { + rb_raise(rb_eArgError, + "can't pass a Proc as a block to Module#refine"); + } Check_Type(klass, T_CLASS); CONST_ID(id_refinements, "__refinements__"); refinements = rb_attr_get(module, id_refinements); diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 872ca1754a..05ac1030c5 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -616,6 +616,14 @@ class TestRefinement < Test::Unit::TestCase assert_equal('[{"1":2},{"3":4}]', x) end + def test_refine_with_proc + assert_raise(ArgumentError) do + Module.new { + refine(String, &Proc.new {}) + } + end + end + private def eval_using(mod, s) diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 8c687bfbb7..4d0d6b6185 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1763,8 +1763,6 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci) VALUE refinements = cref ? cref->nd_refinements : Qnil; VALUE refinement, defined_class; rb_method_entry_t *me; - ci_temp = *ci; - ci = &ci_temp; refinement = find_refinement(refinements, ci->defined_class); -- cgit v1.2.3