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

ruby-changes:9544

From: ko1 <ko1@a...>
Date: Sat, 27 Dec 2008 12:57:42 +0900 (JST)
Subject: [ruby-changes:9544] Ruby:r21084 (trunk): * vm_insnhelper.c (vm_call_method, vm_call_cfunc): use original id instead of

ko1	2008-12-27 12:57:21 +0900 (Sat, 27 Dec 2008)

  New Revision: 21084

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

  Log:
    * vm_insnhelper.c (vm_call_method, vm_call_cfunc): use original id instead of
      calling id when NODE_CFUNC or NODE_BMETHOD.
      fixes Bug #632 [ruby-core:19282].
    * vm_eval.c (vm_call0, vm_call_super): ditto.
    * vm_method.c (rb_add_method, rb_alias): store original id
      in nd_file field of NODE_METHOD.
    * test/stringio/test_stringio.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/test/stringio/test_stringio.rb
    trunk/vm_eval.c
    trunk/vm_insnhelper.c
    trunk/vm_method.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 21083)
+++ ChangeLog	(revision 21084)
@@ -1,3 +1,16 @@
+Sat Dec 27 11:41:45 2008  Koichi Sasada  <ko1@a...>
+
+	* vm_insnhelper.c (vm_call_method, vm_call_cfunc): use original id instead of
+	  calling id when NODE_CFUNC or NODE_BMETHOD.
+	  fixes Bug #632 [ruby-core:19282].
+
+	* vm_eval.c (vm_call0, vm_call_super): ditto.
+
+	* vm_method.c (rb_add_method, rb_alias): store original id
+	  in nd_file field of NODE_METHOD.
+
+	* test/stringio/test_stringio.rb: add a test.
+
 Sat Dec 27 09:48:54 2008  Koichi Sasada  <ko1@a...>
 
 	* vm.c (Init_VM): create and define TOPLEVEL_BINDING at first.
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 21083)
+++ vm_eval.c	(revision 21084)
@@ -64,7 +64,7 @@
 		vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC,
 			      recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
 
-	    cfp->method_id = id;
+	    cfp->method_id = oid;
 	    cfp->method_class = klass;
 
 	    val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
@@ -96,7 +96,7 @@
 	break;
       }
       case NODE_BMETHOD:{
-	val = vm_call_bmethod(th, id, body->nd_cval,
+	val = vm_call_bmethod(th, oid, body->nd_cval,
 			      recv, klass, argc, (VALUE *)argv, blockptr);
 	break;
       }
@@ -152,8 +152,8 @@
 	return method_missing(recv, id, argc, argv, 0);
     }
 
-    body = body->nd_body;
-    return vm_call0(th, klass, recv, id, id, argc, argv, body, CALL_SUPER);
+    return vm_call0(th, klass, recv, id, (ID)body->nd_file,
+		    argc, argv, body->nd_body, CALL_SUPER);
 }
 
 VALUE
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 21083)
+++ vm_method.c	(revision 21084)
@@ -129,6 +129,7 @@
 
     /*
      * NODE_METHOD (NEW_METHOD(body, klass, vis)):
+     *   nd_file : original id   // RBASIC()->klass (TODO: dirty hack)
      *   nd_body : method body   // (2) // mark
      *   nd_clss : klass         // (1) // mark
      *   nd_noex : visibility    // (3)
@@ -139,7 +140,9 @@
      *   nd_cnt  : alias count           // (3)
      */
     if (node) {
-	body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex)), 0);
+	NODE *method = NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex));
+	method->nd_file = (void *)mid;
+	body = NEW_FBODY(method, mid);
     }
     else {
 	body = 0;
@@ -725,7 +728,7 @@
 void
 rb_alias(VALUE klass, ID name, ID def)
 {
-    NODE *orig_fbody, *node;
+    NODE *orig_fbody, *node, *method;
     VALUE singleton = 0;
     st_data_t data;
 
@@ -762,9 +765,10 @@
 
     st_insert(RCLASS_M_TBL(klass), name,
 	      (st_data_t) NEW_FBODY(
-		  NEW_METHOD(orig_fbody->nd_body->nd_body,
+		  method = NEW_METHOD(orig_fbody->nd_body->nd_body,
 			     orig_fbody->nd_body->nd_clss,
 			     NOEX_WITH_SAFE(orig_fbody->nd_body->nd_noex)), def));
+    method->nd_file = (void *)def;
 
     rb_clear_cache_by_id(name);
 
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 21083)
+++ vm_insnhelper.c	(revision 21084)
@@ -355,7 +355,7 @@
 
 static inline VALUE
 vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp,
-	      int num, ID id, VALUE recv, VALUE klass,
+	      int num, ID id, ID oid, VALUE recv, VALUE klass,
 	      VALUE flag, const NODE *mn, const rb_block_t *blockptr)
 {
     VALUE val;
@@ -366,7 +366,7 @@
 	    vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC,
 			  recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1);
 
-	cfp->method_id = id;
+	cfp->method_id = oid;
 	cfp->method_class = klass;
 
 	reg_cfp->sp -= num + 1;
@@ -497,7 +497,7 @@
 		return Qundef;
 	      }
 	      case NODE_CFUNC:{
-		val = vm_call_cfunc(th, cfp, num, id, recv, mn->nd_clss, flag, node, blockptr);
+		val = vm_call_cfunc(th, cfp, num, id, (ID)mn->nd_file, recv, mn->nd_clss, flag, node, blockptr);
 		break;
 	      }
 	      case NODE_ATTRSET:{
@@ -518,7 +518,7 @@
 		VALUE *argv = ALLOCA_N(VALUE, num);
 		MEMCPY(argv, cfp->sp - num, VALUE, num);
 		cfp->sp += - num - 1;
-		val = vm_call_bmethod(th, id, node->nd_cval, recv, mn->nd_clss, num, argv, blockptr);
+		val = vm_call_bmethod(th, (ID)mn->nd_file, node->nd_cval, recv, mn->nd_clss, num, argv, blockptr);
 		break;
 	      }
 	      case NODE_ZSUPER:{
Index: test/stringio/test_stringio.rb
===================================================================
--- test/stringio/test_stringio.rb	(revision 21083)
+++ test/stringio/test_stringio.rb	(revision 21084)
@@ -379,4 +379,19 @@
     assert_equal(4, f.size)
   end
 
+  # This test is should in ruby/test_method.rb
+  # However this test depends on stringio library,
+  # we write it here.
+  class C < StringIO
+    alias old_init initialize
+    attr_reader :foo
+    def initialize
+      @foo = :ok
+      old_init
+    end
+  end
+
+  def test_method
+    assert_equal(:ok, C.new.foo, 'Bug #632 [ruby-core:19282]')
+  end
 end

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

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