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

ruby-changes:27223

From: ko1 <ko1@a...>
Date: Sat, 16 Feb 2013 15:51:28 +0900 (JST)
Subject: [ruby-changes:27223] ko1:r39275 (trunk): * proc.c (rb_binding_new_with_cfp): create binding object even if

ko1	2013-02-16 15:51:17 +0900 (Sat, 16 Feb 2013)

  New Revision: 39275

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

  Log:
    * proc.c (rb_binding_new_with_cfp): create binding object even if
      the frame is IFUNC. But return a ruby-level binding to keep
      compatibility.
      This patch fix degradation introduced from r39067.
      [Bug #7774] [ruby-dev:46960]
    * test/ruby/test_settracefunc.rb: add a test.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_settracefunc.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39274)
+++ ChangeLog	(revision 39275)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Feb 16 15:45:56 2013  Koichi Sasada  <ko1@a...>
+
+	* proc.c (rb_binding_new_with_cfp): create binding object even if
+	  the frame is IFUNC. But return a ruby-level binding to keep
+	  compatibility.
+	  This patch fix degradation introduced from r39067.
+	  [Bug #7774] [ruby-dev:46960]
+
+	* test/ruby/test_settracefunc.rb: add a test.
+
 Sat Feb 16 13:40:13 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (shvar_to_cpp): do not substitute exec_prefix itself
Index: proc.c
===================================================================
--- proc.c	(revision 39274)
+++ proc.c	(revision 39275)
@@ -315,16 +315,24 @@ rb_binding_new_with_cfp(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/proc.c#L315
 {
     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;
+    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 = rb_vm_make_env_object(th, cfp);
+    bind->env = envval;
     bind->path = ruby_level_cfp->iseq->location.path;
     bind->first_lineno = rb_vm_get_sourceline(ruby_level_cfp);
 
Index: test/ruby/test_settracefunc.rb
===================================================================
--- test/ruby/test_settracefunc.rb	(revision 39274)
+++ test/ruby/test_settracefunc.rb	(revision 39275)
@@ -942,6 +942,16 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L942
     assert_security_error_safe4(func)
   end
 
+  def m1_for_test_trace_point_binding_in_ifunc(arg)
+    arg + nil
+  rescue
+  end
+
+  def m2_for_test_trace_point_binding_in_ifunc(arg)
+    arg.inject(:+)
+  rescue
+  end
+
   def test_trace_point_binding_in_ifunc
     bug7774 = '[ruby-dev:46908]'
     src = %q{
@@ -969,5 +979,32 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L979
       rescue RuntimeError
       end
     }, bug7774
+
+    # TracePoint
+    tp_b = nil
+    TracePoint.new(:raise) do |tp|
+      tp_b = tp.binding
+    end.enable do
+      m1_for_test_trace_point_binding_in_ifunc(0)
+      assert_equal(self, eval('self', tp_b), '[ruby-dev:46960]')
+
+      m2_for_test_trace_point_binding_in_ifunc([0, nil])
+      assert_equal(self, eval('self', tp_b), '[ruby-dev:46960]')
+    end
+
+    # set_trace_func
+    stf_b = nil
+    set_trace_func ->(event, file, line, id, binding, klass) do
+      stf_b = binding if event == 'raise'
+    end
+    begin
+      m1_for_test_trace_point_binding_in_ifunc(0)
+      assert_equal(self, eval('self', stf_b), '[ruby-dev:46960]')
+
+      m2_for_test_trace_point_binding_in_ifunc([0, nil])
+      assert_equal(self, eval('self', stf_b), '[ruby-dev:46960]')
+    ensure
+      set_trace_func(nil)
+    end
   end
 end

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

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