[#35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s) — "James M. Lawrence" <redmine@...>

Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

16 messages 2011/02/01

[#35114] [Ruby 1.9-Bug#4373][Open] http.rb:677: [BUG] Segmentation fault — Christian Fazzini <redmine@...>

Bug #4373: http.rb:677: [BUG] Segmentation fault

59 messages 2011/02/06

[#35171] [Ruby 1.9-Bug#4386][Open] encoding: directive does not affect regex expressions — mathew murphy <redmine@...>

Bug #4386: encoding: directive does not affect regex expressions

9 messages 2011/02/09

[#35237] [Ruby 1.9-Bug#4400][Open] nested at_exit hooks run in strange order — Suraj Kurapati <redmine@...>

Bug #4400: nested at_exit hooks run in strange order

12 messages 2011/02/15

[ruby-core:35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

From: "James M. Lawrence" <redmine@...>
Date: 2011-02-01 02:31:13 UTC
List: ruby-core #35027
Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)
http://redmine.ruby-lang.org/issues/show/4352

Author: James M. Lawrence
Status: Open, Priority: Normal
Category: core, Target version: 1.9.x
ruby -v: ruby 1.9.3dev (2011-02-01 trunk 30751) [i386-darwin9.8.0]

def ex_message
  begin
    yield
  rescue => e
    p e.message
  end
end

ex_message { eval('raise') }
ex_message { eval('raise', binding) }

eval('def f ; end')
p method(:f).source_location
eval('def g ; end', binding)
p method(:g).source_location
----
Without patch:
"(eval):1:in `block in <main>': "
""
["(eval)", 1]
["eval_test.rb", 14]

With patch:
"(eval):1:in `block in <main>': "
"(eval):1:in `block in <main>': "
["(eval)", 1]
["(eval)", 1]

Knowing the line of an error inside eval is useful. Passing a binding
shouldn't discard that information. Present behavior is even wrong:
there's no line 10 in this file.
----
eval %{
  
  # .. code ...
  raise


}, binding
----
Without patch:
/Users/jlawrence/tmp/raiser.rb:10:in `<main>': unhandled exception
	from /Users/jlawrence/tmp/raiser.rb:7:in `eval'
	from /Users/jlawrence/tmp/raiser.rb:7:in `<main>'

With patch:
/Users/jlawrence/tmp/raiser.rb:7:in `eval': (eval):4:in `<main>':  (RuntimeError)
	from /Users/jlawrence/tmp/raiser.rb:7:in `eval'
	from /Users/jlawrence/tmp/raiser.rb:7:in `<main>'


----------------------------------------
http://redmine.ruby-lang.org

Attachments (1)

eval.patch (1.75 KB, text/x-diff)
diff --git a/bootstraptest/test_eval.rb b/bootstraptest/test_eval.rb
index 9ae50a6..c5ab953 100644
--- a/bootstraptest/test_eval.rb
+++ b/bootstraptest/test_eval.rb
@@ -287,7 +287,7 @@ assert_normal_exit %q{
   eval("", method(:proc).call {}.binding)
 }
 
-assert_equal "", %q{
+assert_equal "(eval):1:in `block in <main>': ", %q{
   b = binding
   10.times{
     eval('', b)
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb
index 299165f..faa4a57 100644
--- a/test/ruby/test_eval.rb
+++ b/test/ruby/test_eval.rb
@@ -430,4 +430,28 @@ class TestEval < Test::Unit::TestCase
     result = foo.instance_eval(&foo_pr)
     assert_equal(1, result, 'Bug #3786, Bug #3860, [ruby-core:32501]')
   end
+
+  def exception_message
+    begin
+      yield
+    rescue => e
+      e.message
+    end
+  end
+  
+  def test_exception
+    msg = "(eval):1:in `block in test_exception': "
+    assert_equal msg, exception_message { eval('raise') }
+    assert_equal msg, exception_message { eval('raise', binding) }
+  end
+
+  def test_source_location
+    c = Class.new do
+      eval('def f ; end') ;
+      eval('def g ; end', binding)
+    end
+    loc = ["(eval)", 1]
+    assert_equal loc, c.instance_method(:f).source_location
+    assert_equal loc, c.instance_method(:g).source_location
+  end
 end
diff --git a/vm_eval.c b/vm_eval.c
index 0dcbafa..df3846d 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -977,10 +977,6 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char
 	    if (rb_obj_is_kind_of(scope, rb_cBinding)) {
 		GetBindingPtr(scope, bind);
 		envval = bind->env;
-		if (strcmp(file, "(eval)") == 0 && bind->filename != Qnil) {
-		    file = RSTRING_PTR(bind->filename);
-		    line = bind->line_no;
-		}
 	    }
 	    else {
 		rb_raise(rb_eTypeError,

In This Thread

Prev Next