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

ruby-changes:35967

From: usa <ko1@a...>
Date: Mon, 20 Oct 2014 14:46:08 +0900 (JST)
Subject: [ruby-changes:35967] usa:r48048 (ruby_2_0_0): merge revision(s) 48000: [Backport #10368]

usa	2014-10-20 14:45:53 +0900 (Mon, 20 Oct 2014)

  New Revision: 48048

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

  Log:
    merge revision(s) 48000: [Backport #10368]
    
    * vm_core.h, vm.c, proc.c: fix GC mark miss on bindings.
      [ruby-dev:48616] [Bug #10368]
    
    * test/ruby/test_eval.rb: add a test code.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/proc.c
    branches/ruby_2_0_0/test/ruby/test_eval.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm.c
    branches/ruby_2_0_0/vm_core.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 48047)
+++ ruby_2_0_0/ChangeLog	(revision 48048)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Oct 20 14:41:45 2014  Kazuki Tsujimoto  <kazuki@c...>
+
+	* vm_core.h, vm.c, proc.c: fix GC mark miss on bindings.
+	  [ruby-dev:48616] [Bug #10368]
+
+	* test/ruby/test_eval.rb: add a test code.
+
 Fri Oct 17 13:22:17 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (parser_here_document): do not append already appended
Index: ruby_2_0_0/vm_core.h
===================================================================
--- ruby_2_0_0/vm_core.h	(revision 48047)
+++ ruby_2_0_0/vm_core.h	(revision 48048)
@@ -692,6 +692,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_core.h#L692
 typedef struct {
     VALUE env;
     VALUE path;
+    VALUE blockprocval;	/* for GC mark */
     unsigned short first_lineno;
 } rb_binding_t;
 
@@ -806,6 +807,7 @@ rb_block_t *rb_vm_control_frame_block_pt https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_core.h#L807
 /* VM related object allocate functions */
 VALUE rb_thread_alloc(VALUE klass);
 VALUE rb_proc_alloc(VALUE klass);
+VALUE rb_binding_alloc(VALUE klass);
 
 /* for debug */
 extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
@@ -830,6 +832,7 @@ int rb_thread_method_id_and_class(rb_thr https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_core.h#L832
 VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
 			int argc, const VALUE *argv, const rb_block_t *blockptr);
 VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
+VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp);
 VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
 VALUE rb_binding_new_with_cfp(rb_thread_t *th, const rb_control_frame_t *src_cfp);
 void rb_vm_inc_const_missing_count(void);
Index: ruby_2_0_0/proc.c
===================================================================
--- ruby_2_0_0/proc.c	(revision 48047)
+++ ruby_2_0_0/proc.c	(revision 48048)
@@ -259,6 +259,7 @@ binding_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L259
 	bind = ptr;
 	RUBY_MARK_UNLESS_NULL(bind->env);
 	RUBY_MARK_UNLESS_NULL(bind->path);
+	RUBY_MARK_UNLESS_NULL(bind->blockprocval);
     }
     RUBY_MARK_LEAVE("binding");
 }
@@ -278,8 +279,8 @@ static const rb_data_type_t binding_data https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L279
     },
 };
 
-static VALUE
-binding_alloc(VALUE klass)
+VALUE
+rb_binding_alloc(VALUE klass)
 {
     VALUE obj;
     rb_binding_t *bind;
@@ -291,12 +292,13 @@ binding_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L292
 static VALUE
 binding_dup(VALUE self)
 {
-    VALUE bindval = binding_alloc(rb_cBinding);
+    VALUE bindval = rb_binding_alloc(rb_cBinding);
     rb_binding_t *src, *dst;
     GetBindingPtr(self, src);
     GetBindingPtr(bindval, dst);
     dst->env = src->env;
     dst->path = src->path;
+    dst->blockprocval = src->blockprocval;
     dst->first_lineno = src->first_lineno;
     return bindval;
 }
@@ -313,30 +315,7 @@ binding_clone(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L315
 VALUE
 rb_binding_new_with_cfp(rb_thread_t *th, const rb_control_frame_t *src_cfp)
 {
-    rb_control_frame_t *cfp = rb_vm_get_binding_creatable_next_cfp(th, src_cfp);
-    rb_control_frame_t *ruby_level_cfp = rb_vm_get_ruby_level_next_cfp(th, src_cfp);
-    VALUE bindval, envval;
-    rb_binding_t *bind;
-
-    if (cfp == 0 || ruby_level_cfp == 0) {
-	rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
-    }
-
-    while (1) {
-	envval = rb_vm_make_env_object(th, cfp);
-	if (cfp == ruby_level_cfp) {
-	    break;
-	}
-	cfp = rb_vm_get_binding_creatable_next_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
-    }
-
-    bindval = binding_alloc(rb_cBinding);
-    GetBindingPtr(bindval, bind);
-    bind->env = envval;
-    bind->path = ruby_level_cfp->iseq->location.path;
-    bind->first_lineno = rb_vm_get_sourceline(ruby_level_cfp);
-
-    return bindval;
+    return rb_vm_make_binding(th, src_cfp);
 }
 
 VALUE
@@ -2126,9 +2105,10 @@ proc_binding(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/proc.c#L2105
 	}
     }
 
-    bindval = binding_alloc(rb_cBinding);
+    bindval = rb_binding_alloc(rb_cBinding);
     GetBindingPtr(bindval, bind);
     bind->env = proc->envval;
+    bind->blockprocval = proc->blockprocval;
     if (RUBY_VM_NORMAL_ISEQ_P(proc->block.iseq)) {
 	bind->path = proc->block.iseq->location.path;
 	bind->first_lineno = rb_iseq_first_lineno(proc->block.iseq);
Index: ruby_2_0_0/vm.c
===================================================================
--- ruby_2_0_0/vm.c	(revision 48047)
+++ ruby_2_0_0/vm.c	(revision 48048)
@@ -641,6 +641,39 @@ rb_vm_make_proc(rb_thread_t *th, const r https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm.c#L641
     return procval;
 }
 
+/* Binding */
+
+VALUE
+rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp)
+{
+    rb_control_frame_t *cfp = rb_vm_get_binding_creatable_next_cfp(th, src_cfp);
+    rb_control_frame_t *ruby_level_cfp = rb_vm_get_ruby_level_next_cfp(th, src_cfp);
+    VALUE bindval, envval;
+    rb_binding_t *bind;
+    VALUE blockprocval = 0;
+
+    if (cfp == 0 || ruby_level_cfp == 0) {
+	rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
+    }
+
+    while (1) {
+	envval = vm_make_env_object(th, cfp, &blockprocval);
+	if (cfp == ruby_level_cfp) {
+	    break;
+	}
+	cfp = rb_vm_get_binding_creatable_next_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
+    }
+
+    bindval = rb_binding_alloc(rb_cBinding);
+    GetBindingPtr(bindval, bind);
+    bind->env = envval;
+    bind->path = ruby_level_cfp->iseq->location.path;
+    bind->blockprocval = blockprocval;
+    bind->first_lineno = rb_vm_get_sourceline(ruby_level_cfp);
+
+    return bindval;
+}
+
 /* C -> Ruby: block */
 
 static inline VALUE
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 48047)
+++ ruby_2_0_0/version.h	(revision 48048)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
-#define RUBY_RELEASE_DATE "2014-10-17"
-#define RUBY_PATCHLEVEL 590
+#define RUBY_RELEASE_DATE "2014-10-20"
+#define RUBY_PATCHLEVEL 591
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 10
-#define RUBY_RELEASE_DAY 17
+#define RUBY_RELEASE_DAY 20
 
 #include "ruby/version.h"
 
Index: ruby_2_0_0/test/ruby/test_eval.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_eval.rb	(revision 48047)
+++ ruby_2_0_0/test/ruby/test_eval.rb	(revision 48048)
@@ -483,4 +483,19 @@ class TestEval < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_eval.rb#L483
     fname = "\u{3042}".encode("euc-jp")
     assert_equal(fname, eval("__FILE__", nil, fname, 1))
   end
+
+  def test_gced_binding_block
+    assert_normal_exit %q{
+      def m
+        binding
+      end
+      GC.stress = true
+      b = nil
+      tap do
+        b = m {}
+      end
+      0.times.to_a
+      b.eval('yield')
+    }, '[Bug #10368]'
+  end
 end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r48000


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

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