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

ruby-changes:21015

From: ko1 <ko1@a...>
Date: Thu, 25 Aug 2011 08:38:06 +0900 (JST)
Subject: [ruby-changes:21015] ko1:r33064 (trunk): * vm.c (vm_make_env_each): work around to solve Bug #2729.

ko1	2011-08-25 08:37:56 +0900 (Thu, 25 Aug 2011)

  New Revision: 33064

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

  Log:
    * vm.c (vm_make_env_each): work around to solve Bug #2729.
      fixes: Bug #2729
      a patch from Kazuki Tsujimoto <kazuki@c...>
      This problem is caused by changing dfp (dynamic env pointer)
      from saved dfp.  Saved dfp is pointed env in VM stack.  However,
      the dfp can be moved because VM copies env from VM stack to
      the heap.  At this copying, dfp was also changed.  To solve this
      problem, I'll try to change throw mechanism (not save target dfp,
      but save target cfp).
    * bootstraptest/test_flow.rb: add a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_flow.rb
    trunk/vm.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33063)
+++ ChangeLog	(revision 33064)
@@ -1,3 +1,17 @@
+Thu Aug 25 08:19:43 2011  Koichi Sasada  <ko1@a...>
+
+	* vm.c (vm_make_env_each): work around to solve Bug #2729.
+	  fixes: Bug #2729
+	  a patch from Kazuki Tsujimoto <kazuki@c...>
+	  This problem is caused by changing dfp (dynamic env pointer)
+	  from saved dfp.  Saved dfp is pointed env in VM stack.  However,
+	  the dfp can be moved because VM copies env from VM stack to
+	  the heap.  At this copying, dfp was also changed.  To solve this
+	  problem, I'll try to change throw mechanism (not save target dfp,
+	  but save target cfp).
+
+	* bootstraptest/test_flow.rb: add a test for above.
+
 Thu Aug 25 07:57:33 2011  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* numeric.c (int_round): Fix Integer#round [ruby-core:39096]
Index: bootstraptest/test_flow.rb
===================================================================
--- bootstraptest/test_flow.rb	(revision 33063)
+++ bootstraptest/test_flow.rb	(revision 33064)
@@ -517,6 +517,19 @@
     end
   end
   e = Bug2728.new
+}],
+ ['[ruby-core:28132]', %q{
+  class Bug2729
+    include Enumerable
+    def each
+      begin
+        yield :foo
+      ensure
+        proc {}.call
+      end
+    end
+  end
+  e = Bug2729.new
 }]].each do |bug, src|
   assert_equal "foo", src + %q{e.detect {true}}, bug
   assert_equal "true", src + %q{e.any? {true}}, bug
Index: vm.c
===================================================================
--- vm.c	(revision 33063)
+++ vm.c	(revision 33064)
@@ -409,6 +409,23 @@
     if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
 	/* TODO */
 	env->block.iseq = 0;
+    } else {
+	/* rewrite dfp in errinfo to point to heap */
+	if (cfp->iseq->type == ISEQ_TYPE_RESCUE ||
+	    cfp->iseq->type == ISEQ_TYPE_ENSURE) {
+	    VALUE errinfo = env->env[0]; /* #$! */
+	    if (RB_TYPE_P(errinfo, T_NODE)) {
+		VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(errinfo);
+		if (! ENV_IN_HEAP_P(th, escape_dfp)) {
+		    VALUE dfpval = *escape_dfp;
+		    if (CLASS_OF(dfpval) == rb_cEnv) {
+			rb_env_t *dfpenv;
+			GetEnvPtr(dfpval, dfpenv);
+			SET_THROWOBJ_CATCH_POINT(errinfo, (VALUE)(dfpenv->env + dfpenv->local_size));
+		    }
+		}
+	    }
+	}
     }
     return envval;
 }

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

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