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

ruby-changes:26222

From: shugo <ko1@a...>
Date: Sun, 9 Dec 2012 17:48:46 +0900 (JST)
Subject: [ruby-changes:26222] shugo:r38279 (trunk): * vm_insnhelper.c (vm_call_opt_send): Kernel#send should not use

shugo	2012-12-09 17:48:34 +0900 (Sun, 09 Dec 2012)

  New Revision: 38279

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

  Log:
    * vm_insnhelper.c (vm_call_opt_send): Kernel#send should not use
      refinements.
    
    * proc.c (mnew): Kernel#method, Kernel#public_method,
      Module#instance_method, and Module#public_instance_method should
      not use refinements.
    
    * vm_method.c (rb_method_boundp): Kernel#respond_to? should not use
      refinements.
    
    * test/ruby/test_refinement.rb: related test.

  Modified files:
    trunk/ChangeLog
    trunk/method.h
    trunk/proc.c
    trunk/test/ruby/test_refinement.rb
    trunk/vm_insnhelper.c
    trunk/vm_method.c

Index: method.h
===================================================================
--- method.h	(revision 38278)
+++ method.h	(revision 38279)
@@ -102,6 +102,8 @@
 					     VALUE *defined_class_ptr);
 rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
 						    VALUE *defined_class_ptr);
+rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id,
+						       VALUE *defined_class_ptr);
 
 rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);
 rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38278)
+++ ChangeLog	(revision 38279)
@@ -1,3 +1,17 @@
+Sun Dec  9 17:36:59 2012  Shugo Maeda  <shugo@r...>
+
+	* vm_insnhelper.c (vm_call_opt_send): Kernel#send should not use
+	  refinements.
+
+	* proc.c (mnew): Kernel#method, Kernel#public_method,
+	  Module#instance_method, and Module#public_instance_method should
+	  not use refinements.
+
+	* vm_method.c (rb_method_boundp): Kernel#respond_to? should not use
+	  refinements.
+
+	* test/ruby/test_refinement.rb: related test.
+
 Sun Dec  9 06:19:04 2012  Eric Hodel  <drbrain@s...>
 
 	* lib/rdoc/markdown/entities.rb:  Added documentation.
Index: proc.c
===================================================================
--- proc.c	(revision 38278)
+++ proc.c	(revision 38279)
@@ -917,7 +917,7 @@
     rb_method_flag_t flag = NOEX_UNDEF;
 
   again:
-    me = rb_method_entry_with_refinements(klass, id, &defined_class);
+    me = rb_method_entry_without_refinements(klass, id, &defined_class);
     if (UNDEFINED_METHOD_ENTRY_P(me)) {
 	ID rmiss = rb_intern("respond_to_missing?");
 	VALUE sym = ID2SYM(id);
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 38278)
+++ vm_method.c	(revision 38279)
@@ -629,6 +629,21 @@
     return me;
 }
 
+rb_method_entry_t *
+rb_method_entry_without_refinements(VALUE klass, ID id,
+				    VALUE *defined_class_ptr)
+{
+    VALUE defined_class;
+    rb_method_entry_t *me = rb_method_entry(klass, id, &defined_class);
+
+    if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
+	me = me->def->body.orig_me;
+    }
+    if (defined_class_ptr)
+	*defined_class_ptr = defined_class;
+    return me;
+}
+
 static void
 remove_method(VALUE klass, ID mid)
 {
@@ -753,7 +768,7 @@
 rb_method_boundp(VALUE klass, ID id, int ex)
 {
     rb_method_entry_t *me =
-	rb_method_entry_with_refinements(klass, id, 0);
+	rb_method_entry_without_refinements(klass, id, 0);
 
     if (me != 0) {
 	if ((ex & ~NOEX_RESPONDS) &&
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 38278)
+++ vm_insnhelper.c	(revision 38279)
@@ -1597,7 +1597,9 @@
     if (i > 0) {
 	MEMMOVE(&TOPN(i), &TOPN(i-1), VALUE, i);
     }
-    ci->me = rb_method_entry(CLASS_OF(ci->recv), ci->mid, &ci->defined_class);
+    ci->me =
+	rb_method_entry_without_refinements(CLASS_OF(ci->recv),
+					    ci->mid, &ci->defined_class);
     ci->argc -= 1;
     DEC_SP(1);
 
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 38278)
+++ test/ruby/test_refinement.rb	(revision 38279)
@@ -129,18 +129,18 @@
     assert_raise(NoMethodError) { foo.z }
   end
 
-  def test_new_method_by_send
+  def test_send_should_not_use_refinements
     foo = Foo.new
     assert_raise(NoMethodError) { foo.send(:z) }
-    assert_equal("FooExt#z", FooExtClient.send_z_on(foo))
+    assert_raise(NoMethodError) { FooExtClient.send_z_on(foo) }
     assert_raise(NoMethodError) { foo.send(:z) }
   end
 
-  def test_new_method_by_method_object
+  def test_method_should_not_use_refinements
     foo = Foo.new
-    assert_raise(NoMethodError) { foo.send(:z) }
-    assert_equal("FooExt#z", FooExtClient.method_z(foo).call)
-    assert_raise(NoMethodError) { foo.send(:z) }
+    assert_raise(NameError) { foo.method(:z) }
+    assert_raise(NameError) { FooExtClient.method_z(foo) }
+    assert_raise(NameError) { foo.method(:z) }
   end
 
   def test_no_local_rebinding
@@ -249,10 +249,9 @@
     end
   end
 
-  def test_respond_to?
+  def test_respond_to_should_not_use_refinements
     assert_equal(false, 1.respond_to?(:foo))
-    assert_equal(true, eval_using(FixnumFooExt, "1.respond_to?(:foo)"))
-    assert_equal(false, 1.respond_to?(:foo))
+    assert_equal(false, eval_using(FixnumFooExt, "1.respond_to?(:foo)"))
   end
 
   module StringCmpExt

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

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