1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
shugo 2012-12-08 03:06:13 +00:00
parent db051011d6
commit d928280cb6
4 changed files with 24 additions and 3 deletions

View file

@ -1,3 +1,12 @@
Sat Dec 8 11:59:59 2012 Shugo Maeda <shugo@ruby-lang.org>
* 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 <shugo@ruby-lang.org>
* eval.c (rb_mod_refine), vm_eval.c (rb_yield_refine_block):

8
eval.c
View file

@ -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);

View file

@ -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)

View file

@ -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);