mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_insnhelper.c (argument_error): insert dummy frame to make
a backtrace object intead of modify backtrace string array. [Bug #9295] * test/ruby/test_backtrace.rb: add a test for this patch. fix test to compare a result of Exception#backtrace with a result of Exception#backtrace_locations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
053b5d0f9c
commit
485e6ebed8
3 changed files with 51 additions and 17 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Wed Dec 25 18:29:22 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm_insnhelper.c (argument_error): insert dummy frame to make
|
||||||
|
a backtrace object intead of modify backtrace string array.
|
||||||
|
[Bug #9295]
|
||||||
|
|
||||||
|
* test/ruby/test_backtrace.rb: add a test for this patch.
|
||||||
|
fix test to compare a result of Exception#backtrace with
|
||||||
|
a result of Exception#backtrace_locations.
|
||||||
|
|
||||||
Wed Dec 25 13:00:54 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Dec 25 13:00:54 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: let mingw do something black-magic, and check if
|
* configure.in: let mingw do something black-magic, and check if
|
||||||
|
|
|
@ -19,17 +19,16 @@ class TestBacktrace < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_exception_backtrace_locations
|
def test_exception_backtrace_locations
|
||||||
bt = Fiber.new{
|
backtrace, backtrace_locations = Fiber.new{
|
||||||
begin
|
begin
|
||||||
raise
|
raise
|
||||||
rescue => e
|
rescue => e
|
||||||
e.backtrace_locations
|
[e.backtrace, e.backtrace_locations]
|
||||||
end
|
end
|
||||||
}.resume
|
}.resume
|
||||||
assert_equal(1, bt.size)
|
assert_equal(backtrace, backtrace_locations.map{|e| e.to_s})
|
||||||
assert_match(/.+:\d+:.+/, bt[0].to_s)
|
|
||||||
|
|
||||||
bt = Fiber.new{
|
backtrace, backtrace_locations = Fiber.new{
|
||||||
begin
|
begin
|
||||||
begin
|
begin
|
||||||
helper_test_exception_backtrace_locations
|
helper_test_exception_backtrace_locations
|
||||||
|
@ -37,11 +36,34 @@ class TestBacktrace < Test::Unit::TestCase
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
e.backtrace_locations
|
[e.backtrace, e.backtrace_locations]
|
||||||
end
|
end
|
||||||
}.resume
|
}.resume
|
||||||
assert_equal(2, bt.size)
|
assert_equal(backtrace, backtrace_locations.map{|e| e.to_s})
|
||||||
assert_match(/helper_test_exception_backtrace_locations/, bt[0].to_s)
|
end
|
||||||
|
|
||||||
|
def call_helper_test_exception_backtrace_locations
|
||||||
|
helper_test_exception_backtrace_locations(:bad_argument)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_argument_error_backtrace_locations
|
||||||
|
backtrace, backtrace_locations = Fiber.new{
|
||||||
|
begin
|
||||||
|
helper_test_exception_backtrace_locations(1)
|
||||||
|
rescue ArgumentError => e
|
||||||
|
[e.backtrace, e.backtrace_locations]
|
||||||
|
end
|
||||||
|
}.resume
|
||||||
|
assert_equal(backtrace, backtrace_locations.map{|e| e.to_s})
|
||||||
|
|
||||||
|
backtrace, backtrace_locations = Fiber.new{
|
||||||
|
begin
|
||||||
|
call_helper_test_exception_backtrace_locations
|
||||||
|
rescue ArgumentError => e
|
||||||
|
[e.backtrace, e.backtrace_locations]
|
||||||
|
end
|
||||||
|
}.resume
|
||||||
|
assert_equal(backtrace, backtrace_locations.map{|e| e.to_s})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_caller_lev
|
def test_caller_lev
|
||||||
|
|
|
@ -126,20 +126,22 @@ NORETURN(static void argument_error(const rb_iseq_t *iseq, int miss_argc, int mi
|
||||||
static void
|
static void
|
||||||
argument_error(const rb_iseq_t *iseq, int miss_argc, int min_argc, int max_argc)
|
argument_error(const rb_iseq_t *iseq, int miss_argc, int min_argc, int max_argc)
|
||||||
{
|
{
|
||||||
|
rb_thread_t *th = GET_THREAD();
|
||||||
VALUE exc = rb_arg_error_new(miss_argc, min_argc, max_argc);
|
VALUE exc = rb_arg_error_new(miss_argc, min_argc, max_argc);
|
||||||
VALUE bt = rb_make_backtrace();
|
VALUE at;
|
||||||
VALUE err_line = 0;
|
|
||||||
|
|
||||||
if (iseq) {
|
if (iseq) {
|
||||||
int line_no = FIX2INT(rb_iseq_first_lineno(iseq->self));
|
vm_push_frame(th, iseq, VM_FRAME_MAGIC_METHOD, Qnil /* self */, Qnil /* klass */, Qnil /* specval*/,
|
||||||
|
iseq->iseq_encoded, th->cfp->sp, 0 /* local_size */, 0 /* me */, 0 /* stack_max */);
|
||||||
err_line = rb_sprintf("%s:%d:in `%s'",
|
at = rb_vm_backtrace_object();
|
||||||
RSTRING_PTR(iseq->location.path),
|
vm_pop_frame(th);
|
||||||
line_no, RSTRING_PTR(iseq->location.label));
|
}
|
||||||
rb_funcall(bt, rb_intern("unshift"), 1, err_line);
|
else {
|
||||||
|
at = rb_vm_backtrace_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_funcall(exc, rb_intern("set_backtrace"), 1, bt);
|
rb_iv_set(exc, "bt_locations", at);
|
||||||
|
rb_funcall(exc, rb_intern("set_backtrace"), 1, at);
|
||||||
rb_exc_raise(exc);
|
rb_exc_raise(exc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue