[前][次][番号順一覧][スレッド一覧]

ruby-changes:26213

From: shugo <ko1@a...>
Date: Sat, 8 Dec 2012 12:06:28 +0900 (JST)
Subject: [ruby-changes:26213] shugo:r38270 (trunk): * eval.c (rb_mod_refine): raise an ArgumentError if a given

shugo	2012-12-08 12:06:13 +0900 (Sat, 08 Dec 2012)

  New Revision: 38270

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38270

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/test/ruby/test_refinement.rb
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38269)
+++ ChangeLog	(revision 38270)
@@ -1,3 +1,12 @@
+Sat Dec  8 11:59:59 2012  Shugo Maeda  <shugo@r...>
+
+	* 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@r...>
 
 	* eval.c (rb_mod_refine), vm_eval.c (rb_yield_refine_block): 
Index: eval.c
===================================================================
--- eval.c	(revision 38269)
+++ eval.c	(revision 38270)
@@ -1196,10 +1196,16 @@
     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);
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 38269)
+++ vm_insnhelper.c	(revision 38270)
@@ -1763,8 +1763,6 @@
 		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);
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 38269)
+++ test/ruby/test_refinement.rb	(revision 38270)
@@ -616,6 +616,14 @@
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]