summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-08 03:06:13 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-08 03:06:13 +0000
commitd928280cb6644d2d899aadf7bfc8cf4e1b5e2997 (patch)
treec366adbd42bc4330b4009a5da44936e981c10c3d
parentdb051011d68950cd1261f91e724513282d419d9e (diff)
* 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
-rw-r--r--ChangeLog9
-rw-r--r--eval.c8
-rw-r--r--test/ruby/test_refinement.rb8
-rw-r--r--vm_insnhelper.c2
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 <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):
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);