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

ruby-changes:6972

From: matz <ko1@a...>
Date: Mon, 11 Aug 2008 17:14:01 +0900 (JST)
Subject: [ruby-changes:6972] Ruby:r18490 (trunk): * class.c (clone_method): should copy cbase in cref as well.

matz	2008-08-11 17:13:42 +0900 (Mon, 11 Aug 2008)

  New Revision: 18490

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

  Log:
    * class.c (clone_method): should copy cbase in cref as well.
      [ruby-dev:35116]
    
    * iseq.c (iseq_mark): mark original iseq object.
    
    * iseq.c (iseq_free): do not free internal data if they have
      original iseq to belong.
    
    * iseq.c (rb_iseq_clone): a new function to clone iseq value.

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/iseq.c
    trunk/vm_core.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18489)
+++ ChangeLog	(revision 18490)
@@ -3,6 +3,18 @@
 	* test/readline/test_readline.rb: added test for Readline's class
 	  methods.
 
+Mon Aug 11 16:39:23 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* class.c (clone_method): should copy cbase in cref as well.
+	  [ruby-dev:35116]
+
+	* iseq.c (iseq_mark): mark original iseq object.
+
+	* iseq.c (iseq_free): do not free internal data if they have
+	  original iseq to belong.
+
+	* iseq.c (rb_iseq_clone): a new function to clone iseq value.
+
 Mon Aug 11 16:34:48 2008  Tanaka Akira  <akr@f...>
 
 	* enc/trans/iso2022.trans: renamed from iso2022.erb.c.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 18489)
+++ vm_core.h	(revision 18490)
@@ -261,6 +261,7 @@
     /****************/
 
     VALUE self;
+    VALUE orig;			/* non-NULL if its data have origin */
 
     /* block inlining */
     /* 
Index: iseq.c
===================================================================
--- iseq.c	(revision 18489)
+++ iseq.c	(revision 18490)
@@ -48,20 +48,22 @@
 
     if (ptr) {
 	iseq = ptr;
-	/* It's possible that strings are freed
-         * GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name),
-         *                      RSTRING_PTR(iseq->filename));
-	 */
-	if (iseq->iseq != iseq->iseq_encoded) {
-	    RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
+	if (!iseq->orig) {
+	    /* It's possible that strings are freed
+	     * GC_INFO("%s @ %s\n", RSTRING_PTR(iseq->name),
+	     *                      RSTRING_PTR(iseq->filename));
+	     */
+	    if (iseq->iseq != iseq->iseq_encoded) {
+		RUBY_FREE_UNLESS_NULL(iseq->iseq_encoded);
+	    }
+
+	    RUBY_FREE_UNLESS_NULL(iseq->iseq);
+	    RUBY_FREE_UNLESS_NULL(iseq->insn_info_table);
+	    RUBY_FREE_UNLESS_NULL(iseq->local_table);
+	    RUBY_FREE_UNLESS_NULL(iseq->catch_table);
+	    RUBY_FREE_UNLESS_NULL(iseq->arg_opt_table);
+	    compile_data_free(iseq->compile_data);
 	}
-
-	RUBY_FREE_UNLESS_NULL(iseq->iseq);
-	RUBY_FREE_UNLESS_NULL(iseq->insn_info_table);
-	RUBY_FREE_UNLESS_NULL(iseq->local_table);
-	RUBY_FREE_UNLESS_NULL(iseq->catch_table);
-	RUBY_FREE_UNLESS_NULL(iseq->arg_opt_table);
-	compile_data_free(iseq->compile_data);
 	ruby_xfree(ptr);
     }
     RUBY_FREE_LEAVE("iseq");
@@ -84,6 +86,7 @@
 	RUBY_MARK_UNLESS_NULL(iseq->coverage);
 /* 	RUBY_MARK_UNLESS_NULL((VALUE)iseq->node); */
 /*	RUBY_MARK_UNLESS_NULL(iseq->cached_special_block); */
+	RUBY_MARK_UNLESS_NULL(iseq->orig);
 
 	if (iseq->compile_data != 0) {
 	    RUBY_MARK_UNLESS_NULL(iseq->compile_data->mark_ary);
@@ -910,7 +913,7 @@
 
     if ((node = rb_method_body(body)) != 0) {
 	if (nd_type(node) == RUBY_VM_METHOD_NODE) {
-	    VALUE iseqval = (VALUE)node->nd_body;
+ 	    VALUE iseqval = (VALUE)node->nd_body;
 	    ret = ruby_iseq_disasm(iseqval);
 	}
     }
@@ -1227,6 +1230,27 @@
     return table;
 }
 
+VALUE
+rb_iseq_clone(VALUE iseqval, VALUE newcbase)
+{
+    VALUE newiseq = iseq_alloc(rb_cISeq);
+    rb_iseq_t *iseq0, *iseq1;
+
+    GetISeqPtr(iseqval, iseq0);
+    GetISeqPtr(newiseq, iseq1);
+
+    *iseq1 = *iseq0;
+    iseq1->self = newiseq;
+    if (!iseq1->orig) {
+	iseq1->orig = iseqval;
+    }
+    if (newcbase) {
+	iseq1->cref_stack = NEW_BLOCK(newcbase);
+    }
+
+    return newiseq;
+}
+
 /* ruby2cext */
 
 VALUE
Index: class.c
===================================================================
--- class.c	(revision 18489)
+++ class.c	(revision 18490)
@@ -13,6 +13,7 @@
 #include "ruby/signal.h"
 #include "ruby/node.h"
 #include "ruby/st.h"
+#include "vm_core.h"
 #include <ctype.h>
 
 extern st_table *rb_class_tbl;
@@ -78,10 +79,17 @@
 	st_insert(data->tbl, mid, 0);
     }
     else {
+	NODE *fbody = body->nd_body->nd_body;
+
+	if (nd_type(fbody) == RUBY_VM_METHOD_NODE) {
+	    fbody = NEW_NODE(RUBY_VM_METHOD_NODE, 0, 
+			     rb_iseq_clone((VALUE)fbody->nd_body, data->klass),
+			     0);
+	}
 	st_insert(data->tbl, mid,
 		  (st_data_t)
 		  NEW_FBODY(
-		      NEW_METHOD(body->nd_body->nd_body,
+		      NEW_METHOD(fbody,
 				 data->klass, /* TODO */
 				 body->nd_body->nd_noex),
 		      0));

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

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