[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:200

From: ko1 atdot.net
Date: 31 Jan 2006 18:54:31 -0000
Subject: [yarv-diff:200] r358 - in trunk: . test test/ruby yarvtest

Author: ko1
Date: 2006-02-01 03:54:31 +0900 (Wed, 01 Feb 2006)
New Revision: 358

Modified:
   trunk/ChangeLog
   trunk/eval.c
   trunk/gc.c
   trunk/insns.def
   trunk/test.rb
   trunk/test/ruby/test_gc.rb
   trunk/test/runner.rb
   trunk/yarvtest/test_method.rb
Log:
	* gc.c : add GC.debug_flag= method

	* insns.def : support method definition in method

	* yarvtest/test_method.rb : add tests for above



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/ChangeLog	2006-01-31 18:54:31 UTC (rev 358)
@@ -4,6 +4,15 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-02-01(Wed) 03:51:39 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* gc.c : add GC.debug_flag= method
+
+	* insns.def : support method definition in method
+
+	* yarvtest/test_method.rb : add tests for above
+
+
 2006-01-29(Sun) 11:40:26 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* eval_proc.c (proc_alloc) : fix [yarv-dev:777]

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/eval.c	2006-01-31 18:54:31 UTC (rev 358)
@@ -111,7 +111,6 @@
 
 NORETURN(void rb_thread_start_1(void));
 void Init_yarv(void);
-extern int gc_debug_flag;
 
 void
 ruby_init()
@@ -159,7 +158,6 @@
     exit(EXIT_FAILURE);
   }
   ruby_running = 1;
-  gc_debug_flag = 1;
 }
 
 int ruby_in_eval;
@@ -1957,7 +1955,7 @@
     /* push tag */
     if(stored_klass){
       stored_special_cref_stack =
-        th_restore_stored_klass(th, env->block.lfp, stored_klass);
+        th_restore_stored_klass(th, env->block.lfp, (void *)stored_klass);
     }
     
     /* kick */

Modified: trunk/gc.c
===================================================================
--- trunk/gc.c	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/gc.c	2006-01-31 18:54:31 UTC (rev 358)
@@ -106,8 +106,14 @@
     rb_exc_raise(nomem_error);
 }
 
-int gc_debug_flag = 0;
+static int gc_debug_flag = 0;
 
+static VALUE
+set_gc_debug_flag(VALUE self, VALUE v){
+  gc_debug_flag = (v == Qtrue);
+  return v;
+}
+
 void *
 ruby_xmalloc(long size)
 {
@@ -119,7 +125,7 @@
   if (size == 0) size = 1;
   malloc_increase += size;
 
-  if (malloc_increase > malloc_limit || (0 && gc_debug_flag)) {
+  if (malloc_increase > malloc_limit || gc_debug_flag) {
     garbage_collect();
   }
   RUBY_CRITICAL(mem = malloc(size));
@@ -1879,6 +1885,7 @@
     rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
     rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
     rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0);
+    rb_define_singleton_method(rb_mGC, "debug_flag=", set_gc_debug_flag, 1);
     rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0);
 
     rb_mObSpace = rb_define_module("ObjectSpace");

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/insns.def	2006-01-31 18:54:31 UTC (rev 358)
@@ -848,9 +848,14 @@
   //debugp_(-1, "self", GET_SELF());
   //printf("%s\n", body_name(nd_type(newbody)));
   //fflush(stdout);
-
-  klass = GET_KLASS();
-
+  
+  if(GET_ISEQ()->local_iseq->type == ISEQ_TYPE_METHOD){
+    klass = CLASS_OF(GET_SELF());
+  }
+  else{
+    klass = GET_KLASS();
+  }
+  
   rb_add_method(klass, id, newbody, noex);
 
   if(noex == NOEX_MODFUNC){
@@ -858,12 +863,6 @@
                   id, newbody, NOEX_PUBLIC);
   }
   
-  if(0){
-    NODE *mn = rb_method_node(klass, id);
-    dp(klass);
-    printf("defined: %s: %s\n", rb_id2name(id), node_name(nd_type(mn)));
-  }
-
   INC_VM_STATE_VERSION();
 }
 

Modified: trunk/test/ruby/test_gc.rb
===================================================================
--- trunk/test/ruby/test_gc.rb	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/test/ruby/test_gc.rb	2006-01-31 18:54:31 UTC (rev 358)
@@ -8,6 +8,8 @@
   end
 
   def test_gc
+    GC.debug_flag = false
+    
     assert_nothing_raised do
       1.upto(10000) {
         tmp = [0,1,2,3,4,5,6,7,8,9]
@@ -26,5 +28,7 @@
     }
     GC.start
     assert true   # reach here or dumps core
+
+    GC.debug_flag = true
   end
 end

Modified: trunk/test/runner.rb
===================================================================
--- trunk/test/runner.rb	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/test/runner.rb	2006-01-31 18:54:31 UTC (rev 358)
@@ -6,4 +6,6 @@
 Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
 Release = rcsid[3].freeze
 
+# GC.debug_flag = true
+
 exit Test::Unit::AutoRunner.run(true, File.dirname($0))

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/test.rb	2006-01-31 18:54:31 UTC (rev 358)
@@ -1,6 +1,79 @@
-require 'test/unit'
+class A
+  class B
+    def a_method
+      def nested_method
+        p "nested_method"
+      end
+      nested_method
+    end
+  end
+
+  def test_method
+    instance_eval("B.new.a_method")
+#    eval("B.new.a_method")
+#    B.new.a_method
+  end
+end
+
+A.new.test_method
+
 __END__
+
+class A
+  class B
+    def a_method
+      def nested_method
+        p "nested_method"
+      end
+      nested_method
+    end
+  end
+
+  def test_method
+    instance_eval("B.new.a_method")
+  end
+end
+
+A.new.test_method
+
 __END__
+
+module M
+  class A
+    def hoge
+      p "hoge"
+    end
+  end
+end
+
+class A
+  include M
+  def initialize
+    p A
+    p self.class.ancestors
+  end
+end
+
+A.new
+
+__END__
+
+class Hoge
+  def fuge
+    eval "EvaluatedConst = 10"
+    self
+  end
+end
+ 
+Hoge.new.fuge
+p Hoge::EvaluatedConst
+
+__END__
+1000.times{
+  Thread.new{}.join
+}
+
+__END__
 require 'test/unit'
 
 __END__

Modified: trunk/yarvtest/test_method.rb
===================================================================
--- trunk/yarvtest/test_method.rb	2006-01-29 02:44:35 UTC (rev 357)
+++ trunk/yarvtest/test_method.rb	2006-01-31 18:54:31 UTC (rev 358)
@@ -450,6 +450,30 @@
       $1
     }
   end
+
+  def test_nested_method
+    ae %q{
+      class A
+        def m
+          def m2
+            p :m2
+          end
+          m2()
+        end
+      end
+      A.new.m
+    }
+    ae %q{
+      class A
+        def m
+          def m2
+            p :m2
+          end
+          m2()
+        end
+      end
+      instance_eval('A.new.m')
+    }
+  end
 end
 
-


-- 
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]