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

ruby-changes:9573

From: yugui <ko1@a...>
Date: Sun, 28 Dec 2008 18:40:04 +0900 (JST)
Subject: [ruby-changes:9573] Ruby:r21113 (ruby_1_9_1): merges r21084 from trunk into ruby_1_9_1.

yugui	2008-12-28 18:39:43 +0900 (Sun, 28 Dec 2008)

  New Revision: 21113

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

  Log:
    merges r21084 from trunk into ruby_1_9_1.
    * 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:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/test/stringio/test_stringio.rb
    branches/ruby_1_9_1/vm_eval.c
    branches/ruby_1_9_1/vm_insnhelper.c
    branches/ruby_1_9_1/vm_method.c

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 21112)
+++ ruby_1_9_1/ChangeLog	(revision 21113)
@@ -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 13:09:36 2008  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* man/irb.1: adds -v, -h, -E, and -U.
Index: ruby_1_9_1/vm_eval.c
===================================================================
--- ruby_1_9_1/vm_eval.c	(revision 21112)
+++ ruby_1_9_1/vm_eval.c	(revision 21113)
@@ -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: ruby_1_9_1/vm_method.c
===================================================================
--- ruby_1_9_1/vm_method.c	(revision 21112)
+++ ruby_1_9_1/vm_method.c	(revision 21113)
@@ -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: ruby_1_9_1/vm_insnhelper.c
===================================================================
--- ruby_1_9_1/vm_insnhelper.c	(revision 21112)
+++ ruby_1_9_1/vm_insnhelper.c	(revision 21113)
@@ -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: ruby_1_9_1/test/stringio/test_stringio.rb
===================================================================
--- ruby_1_9_1/test/stringio/test_stringio.rb	(revision 21112)
+++ ruby_1_9_1/test/stringio/test_stringio.rb	(revision 21113)
@@ -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/

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